SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Include $page.html not recognized

    I ran across this tutorial and downloaded the files to work with. I run the WAMP server on my computer and normal include statements work ok. However when I run these new files I get these errors
    Code:
    Warning: include(.html) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\new moray\template.php on line 21
    
    Warning: include() [function.include]: Failed opening '.html' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\new moray\template.php on line 21
    where line 21 is
    Code:
    <?php include ("$page.html"); ?>
    The php echo also seems not to work as this
    Code:
    <?php echo "<style type=\"text/css\" media=\"all\">@import \"$style.css\";> </style>"; ?>
    doesn't get the stylesheet.
    All the files are in my root directory.

    I have searched for a couple of day for an answer and all I came up with was to insert this
    Code:
    echo 'Page : '.$page.' - Style : '.$style;
    but I don't know where to insert it.
    Php.ini, httpd.conf ???

    I am a css, html man and trying to learn some php so I would like my server to work with the code other than normal include statements
    Code:
    <?php include ("menu.php"); ?>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,152
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    The echo() will only show you what the values are for the $page and $style variables so I wouldn't strick it anywhere except in a PHP file during troubleshooting to make sure they're what I think they should be.

    The include syntax looks a bit shaky to me. BTW, include is a language construct not a function so you don't need the parentheses.

    Try something like

    PHP Code:
    include $page . '.html';
    <?php echo "<style type=\"text/css\" media=\"all\">@import \"" $style ".css\";> </style>"?>
    /* or */
    <?php echo '<style type="text/css" media="all">@import "' $style '.css";> </style>'?>

  3. #3
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sticks464 View Post
    where line 21 is
    Code:
    <?php include ("$page.html"); ?>
    The variable $page is empty which is why you get

    Code:
    Warning: include(.html)
    If you want to include page.html use

    PHP Code:
    <?php include ("page.html"); ?>
    Same issue with $style.css

    PHP Code:
    <?php echo "<style type=\"text/css\" media=\"all\">@import \"$style.css\";> </style>"?>
    Denny Schlesinger
    web services

  4. #4
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe a better explanation would help. I don't think it is the code that's incorrect.
    This is the index.php
    Code:
    <?php
    if ($stylecookie == "") { 
    $style="default";
    }
    else {
    $style=$stylecookie;
    }
    Header ("Location: http://localhost/new moray/template.php?page=home&style=$style");
    ?>
    This is template.php and the highlighted code works
    Code:
    <?php
    setcookie ("stylecookie", $style, time()+40000000); 
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    	<title>Untitled</title>
    <?php echo "<style type=\"text/css\" media=\"all\">@import \"$style.css\";> </style>"; ?>
    <?php echo "<link rel=\"alternate style sheet\" type=\"text/css\" href=\"print.css\" title=\"Printable\" />"; ?>
    <?php echo "<link rel=\"alternate style sheet\" type=\"text/css\" href=\"default.css\" title=\"Default\" />"; ?>
    </head>
    <body>
    <div class="body">
    <?php include ("$page.html"); ?>
    </div>
    <div class="menu">
    <?php include ("menu.php"); ?>
    </div>
    </body>
    </html>
    This is what I get in my browser with the highlighted code being the menu.php
    Code:
    Warning: include(.html) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\new moray\template.php on line 16
    
    Warning: include() [function.include]: Failed opening '.html' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\new moray\template.php on line 16
    Home
    Picasso
    Babeuf
    
    . . . . . . . .
    
    Printable version
    Default version
    I think somewhere in my Apache httpd.conf or php.ini or another file there is something I need to add for the files with the $ sign in front of them to run.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,152
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    If the syntax is OK, my guess is that it relies on globals being on (IMHO not a good thing to be on).

    Try
    PHP Code:
    <?php
    setcookie 
    ("stylecookie"$styletime()+40000000);
    $page = (isset($_GET['page'])) ? $_GET['page'] : 'index'// a default page
    $style = (isset($_GET['style'])) ? $_GET['style'] : 'default';
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <title>Untitled</title>
    <?php echo "<style type=\"text/css\" media=\"all\">@import \"$style.css\";> </style>"?>
    <?php 
    echo "<link rel=\"alternate style sheet\" type=\"text/css\" href=\"print.css\" title=\"Printable\" />"?>
    <?php 
    echo "<link rel=\"alternate style sheet\" type=\"text/css\" href=\"default.css\" title=\"Default\" />"?>
    </head>
    <body>
    <div class="body">
    <?php include ("$page.html"); ?>
    </div>
    <div class="menu">
    <?php include ("menu.php"); ?>
    </div>
    </body>
    </html>

  6. #6
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    sticks:

    You want to use the forum's php tags to show up your code better

    PHP Code:
    <?php
    if ($stylecookie == "") { 
    $style="default";
    }
    else {
    $style=$stylecookie;
    }
    Header ("Location: http://localhost/new moray/template.php?page=home&style=$style");
    ?>

    Quote Originally Posted by sticks464 View Post
    Maybe a better explanation would help. I don't think it is the code that's incorrect.
    I didn't say the code was incorrect. I said the variable $page was empty.

    You did set it in the code shown above but if "Header" called in a new page, that would be a new set of variables. You have to set $page and $style again for the new page.
    Denny Schlesinger
    web services

  7. #7
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Mittineague
    If the syntax is OK, my guess is that it relies on globals being on (IMHO not a good thing to be on).
    Solved. I turned on register_globals and it all works. Until I learn how to do it with globals off this will work.

    Thanks for all the help.

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sticks464 View Post
    Solved. I turned on register_globals and it all works. Until I learn how to do it with globals off this will work.

    Thanks for all the help.
    $_GET['variable_name_here']
    or
    $_POST or $_COOKIE or $_SESSION...

    But do not use register_globals.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,152
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Just using a $_GET var after checking for isset without further validation is bad enough. eg. if someone types in an HTTP request for
    ....&page=admin/control_panel
    or something similar for a page you don't want them to see. I showed the example as a way for you to check if globals was off or not. This is similar to how you should do it (but with more validation checks), not by turning globals on. Imagine someone makes a request like
    .....&loggedin=true&user=admin
    Having globals on allows access to all your variables from the address bar.

    You may be fine on your localhost server, but this is very bad practice, and IMHO there's no reason to learn PHP using it.

  10. #10
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    be aware that doing this
    PHP Code:
    include $unvalidated_user_defined_variable '.html'
    Is extremely insecure. It's a very common and very severe mistake made by novice coders. This is one of the first vulnerabilities hackers and automated bots probe for. The potential consequences are:
    They can read nearly any file on the server(the passwords!)
    They can execute whichever code they want, basically controlling the server.
    They can send your server into an endless loop, probably crashing it.

    Certain php config settings can mitigate some of that to an extent, but not completely.

    Use a specific list of allowed files.
    PHP Code:
    $allowed = array(
        
    'page1' => 'page1.html'
      
    'page2' => 'bar/page2.php'
      
    'contact' => 'contact.php'
    );

    if (isset(
    $_GET['page'], $allowed[$_GET['page']])) {
        include 
    $allowed[$_GET['page']];
    } else {
        include 
    'default.html';



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •