In a php include /file.php doesn't work...

Discussion in 'Web Design and Development' started by MegaMan1311, Jul 9, 2008.

  1. MegaMan1311 macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #1
    Odd. When I use <php include('/index.php');?> from mypage.php, it doesn't work. It doesn't like the slash. Shouldn't that work?

    EDIT: Here is my error:
    Warning: require() [function.require]: Unable to access /header.php in /var/www/vhosts/url/httpdocs/testing/server_root.php on line 2

    Warning: require(/header.php) [function.require]: failed to open stream: No such file or directory in /var/www/vhosts/url/httpdocs/testing/server_root.php on line 2

    Warning: require() [function.require]: Unable to access /header.php in /var/www/vhosts/url/httpdocs/testing/server_root.php on line 2

    Warning: require(/header.php) [function.require]: failed to open stream: No such file or directory in /var/www/vhosts/url/httpdocs/testing/server_root.php on line 2

    Fatal error: require() [function.require]: Failed opening required '/header.php' (include_path='.:') in /var/www/vhosts/url/httpdocs/testing/server_root.php on line 2


    Thanks,
    MegaMan1311
     
  2. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #2
    edit: nevermind you edited post negated my advice...
     
  3. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #3
    Makes sense... I edited your code to /httpdocs/header.php, but it still didn't work.

    Error:

    Warning: include() [function.include]: Unable to access /httpdocs/header.php in /var/www/vhosts/thecybernetwork.net/httpdocs/server_root.php on line 2

    Warning: include(/httpdocs/header.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/thecybernetwork.net/httpdocs/server_root.php on line 2

    Warning: include() [function.include]: Unable to access /httpdocs/header.php in /var/www/vhosts/thecybernetwork.net/httpdocs/server_root.php on line 2

    Warning: include(/httpdocs/header.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/thecybernetwork.net/httpdocs/server_root.php on line 2

    Warning: include() [function.include]: Failed opening '/httpdocs/header.php' for inclusion (include_path='.:') in /var/www/vhosts/thecybernetwork.net/httpdocs/server_root.php on line 2

    Edit: I read your edit. Thanks for your help.
     
  4. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #4
    without access to your file structure there isnt a lot to do...

    Where does this file sit on your server? the / might even be taking you all the way back to the root of your hard drive depending on how PHP was setup.

    in which case you should use something like
    /var/www/vhosts/thecybernetwork.net/httpdocs/

    it just has to do with locating the file in the file structure tree


    EDIT:
    is there any reason you are adding the slash?
    If you want to get to the directory above where you are include('../page.php'); take you to the directory above where the current file is.
     
  5. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #5
    Thank you! That works. There is still one problem though.
    The following code doesn't work. It is because of the first slash... (again).
    <img id="nav_nav" src="/images/navigation/nav.jpg" alt=""/>

    Also, the reason I am doing this is that this code goes in a template that will be used in both the document root AND subfolders. The template code doesn't change, so I need code that will work in whatever folder it is put in.
     
  6. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #6
  7. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #7
    :p
    I feel really stupid right now. I forgot to upload the images folder... Thanks for all of your help. You're a lifesaver!
     
  8. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #8
    haha, happens to the best of us! ;)
    Try editing a CSS file to fix this little annoyance, then after 240 reloads and line changes you remember that you never uploaded the new file to begin with! haha


    You're very welcome.
     
  9. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #9
    Just to throw it out there, here is how I access the site root:
    PHP:
    include $_SERVER['DOCUMENT_ROOT']."/index.html";
     
  10. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #10
    Ok, I have another issue. I'm am also integrating phpBB's user database into my site. So, here is the code to do that. It also uses includes, so I used the above method to fix it. It works like a charm, but it has one small flaw.

    Code to include phpBB.
    PHP:
    <?php
    define
    ('IN_PHPBB'true);
    $phpbb_root_path '/var/www/vhosts/thecybernetwork.net/httpdocs/forums/';
    $phpEx substr(strrchr(__FILE__'.'), 1);
    include(
    $phpbb_root_path 'common.' $phpEx);
    include(
    $phpbb_root_path 'includes/functions_display.' $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup(); 
    global 
    $user;
    ?>
    Flaw:
    PHP:
    <?php
                                
    if($user->data['is_registered'])
                                {
                                    echo 
    "<br /><div class=\"center\">";
                                    echo 
    get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height']);
                                    echo 
    "<br /><br />Welcome back " $user->data['username'] .  " (<a href=\"" append_sid("{$phpbb_root_path}ucp.$phpEx""mode=logout"true$user->session_id). "\">Log out</a>)";
                                    echo 
    "<br />You have <a href=\"" append_sid("{$phpbb_root_path}ucp.$phpEx"'i=pm&folder=inbox') . "\">" $user->data['user_new_privmsg'] . "</a> new private messages.";
                                    echo 
    "</div><br />";
                                }
                                
                                else and 
    so on and so forth
    When you try to log out using the above code, it makes the log out link is this:
    HTML:
    http://www.thecybernetwork.net/var/www/vhosts/thecybernetwork.net/httpdocs/forums/ucp.php?mode=logout&sid=4f453ccb0048f490d856b87b4e92afc3
    EDIT: Just realized something. The phpBB code is called before the HTML tag. That may be what my problem is.

    Not quite what I need, since thecybernetwork.net is the root. Thanks in advance.

    MegaMan1311
     

Share This Page