+ Reply to Thread
Results 1 to 9 of 9

Thread: PHP Include, file help!

  1. #1
    stillDOLL is offline x10Hosting Member stillDOLL is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    11

    Question PHP Include, file help!

    I'm new to PHP but I just mangaged to put the content which I am going to use on all my pages on a "header.php" file and the other content which I put on a "footer.php" file. And the tutorial I was reading says to type in the script like this:

    <?php include('header.php'); ?>
    <div style="position: absolute; left: 246; top: 619; width: 574; height:180">
    <div style="width: 574; height: 224"><p class="Header">Welcome~</div>
    </div>
    <?php include('footer.php'); ?>

    I've done that and I even uploaded the "header" and the "footer" onto my server but when I upload this as one PHP file (main.php) and preview it it's just a blank screen with "Welcome~" on it!! >w<

    Can someone please tell me what I'm doing wrong? and if I'm not doing this wrong does x10 support PHP??


    Thanks!~^^,

    Ann

    -btw, if you don't get what I'm saying please feel free to email me at vampireheart.stilldoll@hotmail.com

  2. #2
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: PHP Include, file help!

    Couple of things to watch out for here...

    Firstly, all my includes have double quotation marks (") but I'm not sure that has any relevance.

    More importantly is the location of the included file. If they are in the same directory as the file you are including them into - there shouldn't be a problem but if they are in a directory above/below/different - you need to specify the path correctly.

    Lastly (and this is probably the reason), your included file can only be the body part of a page. In other words, you need to strip out everything above (and including) <body>

    Very simply put, your included files should only have code like this...

    PHP Code:
    <table>
    <tr>
    <td>Welcome</td>
    </tr>
    </table>
    <?php echo $_SESSION['username']; ?>
    If headers, opening or closing tags are in the include file, it confuses the page you are including them in.

    Your main page would look something like this.

    PHP Code:
    <html>
    <head>
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <?php include("header.php"); ?>
    <div style="position: absolute; left: 246; top: 619; width: 574; height:180">
    <div style="width: 574; height: 224"><p class="Header">Welcome~</div>
    </div>
    <?php include("footer.php"); ?>
    </body>
    </html>
    Yes, X10 does support php!

  3. #3
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: PHP Include, file help!

    Quote Originally Posted by stillDOLL View Post
    <?php include('header.php'); ?>
    <div style="position: absolute; left: 246; top: 619; width: 574; height:180">
    <div style="width: 574; height: 224"><p class="Header">Welcome~</div>
    </div>
    <?php include('footer.php'); ?>

    I've done that and I even uploaded the "header" and the "footer" onto my server but when I upload this as one PHP file (main.php) and preview it it's just a blank screen with "Welcome~" on it!! >w<
    Hmm. I would ask if the header and footer are named exactly that, not header.php.html or anything, and that they are in the same directory as the file that includes them.
    But if that was the case, PHP would give an error.

    Because you get no errors, I can only assume that your header and footer are either blank, or have no output in them. For example, the following example header.php will output nothing and would look exactly like what you're getting above.
    PHP Code:
    <?php
    $a 
    10;
    $b 3;
    $c $a $b;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
    <head>
    <title>Index page</title></head><body>
    One other thing to check, the file that is trying to include is a PHP file, right? But again, it would output the PHP code if it was HTML...
    index.php?


    Have you viewed the source of your file? Because if you look at my example above, it will show nothing on the page. But it will output the headers in the source...
    Last edited by Scoochi2; 10-06-2008 at 07:06 AM.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  4. #4
    sycoblast is offline x10Hosting Member sycoblast is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    4

    Re: PHP Include, file help!

    <?php include('header.php'); ?>
    <div style="position: absolute; left: 246; top: 619; width: 574; height:180">
    <div style="width: 574; height: 224"><p class="Header">Welcome~</div>
    </div>
    <?php include('footer.php'); ?>


    --------

    Instead of "including"

    why not just "echo" your header/footer ... or if your page is scripted in HTML just have it in "class" text so you can avoid using headers and footers... It also slows down the page when you have excessive .php scripts for no reason... Like this.

  5. #5
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: PHP Include, file help!

    Quote Originally Posted by sycoblast View Post

    why not just "echo" your header/footer ...
    Interesting point.. what's the syntax for this and why do we even have an include function?

    If you echo a page, does it process any included php?

    What are the pro's con's?

  6. #6
    exemption is offline x10Hosting Member exemption is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    66

    Re: PHP Include, file help!

    Why use HTML inside of PHP when you can simply use PHP through out?

    such as this

    PHP Code:
    <?php
    include "header.php";
    include 
    "w/e.php";
    include 
    "file.html";
    ?>
    '
    something like that is super simple


    I program PHP..so if you need help lemme know!


  7. #7
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: PHP Include, file help!

    What I do is I create a header and footer template in html, and I have a function that reads them and echos them. This is, in my opinion, the simplest way.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  8. #8
    stillDOLL is offline x10Hosting Member stillDOLL is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    11

    Re: PHP Include, file help!

    Hey!!^^ Thanks everyone who replied!!!^^ I've got the problem fixed now XD
    So thank you very very much!!!!^^

  9. #9
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: PHP Include, file help!

    Then I guess you have to close this thread. post one more time and tick the close thread option. before posting.

+ Reply to Thread

Similar Threads

  1. include php within javascript
    By thezone1 in forum Programming Help
    Replies: 5
    Last Post: 04-24-2008, 12:50 PM
  2. PHP version + max file size limit
    By tipsyman in forum Free Hosting
    Replies: 3
    Last Post: 02-27-2008, 01:04 PM
  3. Replies: 0
    Last Post: 10-10-2007, 07:53 AM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  5. Converting a .RMVB file
    By SEŅOR in forum Off Topic
    Replies: 7
    Last Post: 06-19-2006, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers