Results 1 to 10 of 10

Thread: PHP problem. Header.php?!

  1. #1
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP problem. Header.php?!

    I just started a website. I have the hosting and domain all up and going. I use php codes. I have my index.php and my header.php

    Now I am ready to code my content and navigation pages. For example..castcrew.php

    My question is how do I have my header shown and included in my castcrew.php..so my layout and side bar is included.

    I put this code on the page, but it doesn't work..

    <?php include("header.php"); ?>

    It doesn't work. I tried google and everything else. I can't figure this out.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    That code is correct, however you must make sure that "header.php" is in the same directory as the file that has this code, also make sure that header.php has code in it, or it will look like nothing's happened.

    If you want more help, post a link to your site and I'll see what's going wrong or paste the code from the files.

  3. #3
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    As mentioned, header.php must be in the same directory as the file.

    However, if the file is included by another php file, the include path may be different.

    Let's say your folder structure is such

    a.php
    /extra/b.php
    /extra/c.php

    For example, a.php includes /extras/b.php and in b.php you just have a include("c.php");

    When you invoke a.php, c.php cannot be found because c.php is expected to be in the same directory as a.php

    If you are absolutely sure the files are in the same directory, try this

    PHP Code:
    include_once(dirname(__FILE__)."/header.php"); 
    If you have doubts about where a file resides in, you can also echo out dirname(__FILE__) to see which directory it is in.

  4. #4
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

  5. #5
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    You have an index.php inside castcrew right?

    it should be include_once("../header.php");
    ../ means to go back down one directory.

    From the error message, PHP is expecting index.php and header.php to be inside the castcrew directory. It is one directory down, hence ../header.php

  6. #6
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I just took your advice. The code it working, but now, when I click on cast/crew, my cutenews comes up in the content section. I only want my content on my cast/crew page to come up. I don't want cutenews showing, unless someone is on my home.

    you can see what i mean here..

    cutenews shows, which i want.
    http://www.wildsideproductions.net/indexx.php

    cutenews shows here too..which i dont want.
    http://www.wildsideproductions.net/castcrew/

  7. #7
    Join Date
    Mar 2009
    Location
    Florida
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    On the castcrew page you need to remove the code that inserts the cutenews.

    Cheers,

  8. #8
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What is the code I need to remove? This is all the coding that is in my castcrew page...

    <html>
    <body>
    <link rel="stylesheet" type="text/css" href="/!/style.css">
    <?php include("/home/wildside/public_html/header.php"); ?>

    practiceeejfhsdj

  9. #9
    Join Date
    Mar 2009
    Location
    Florida
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    Oh, so you put all your code in the header? Well you will have to break it up if you want to remove certain parts from other pages or else header will be the same for every single page and you won't be able to change it.

  10. #10
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    How can I break it up?

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
  •