require not working!

Discussion in 'PHP' started by Dirty-Rockstar, Oct 27, 2007.

  1. #1
    Main directory, i have staff.php. on this page i have

    
    $step=$_GET[step];
    if(isset($step)) {
    include('staffpage/banuser.php');
    }
    
    PHP:
    in staffpage/banuser.php the very first line i have is

    
    require ('../staff.php');
    PHP:
    but i get error:

    In all logical sense this should work. I read up on it. I also commented out require and my code works fine. im missing something simple? O_O
     
    Dirty-Rockstar, Oct 27, 2007 IP
  2. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    erm, i dont think you need the two dots.. ?

    just have
    require('staff.php')
    PHP:
    should be fine
     
    Lordy, Oct 27, 2007 IP
  3. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    wow what a messed up loop that gave me. i think i can figure it out from here. but why is this? I always thought if you are calling a file one directory up then use the ../page.php

    2 directorys ../../page.php etc. I got something to happen. but it exploded in a loop. hrmm....i think i can fix it. but can you explain why leaving out the 2 dots seemed to work?
     
    Dirty-Rockstar, Oct 27, 2007 IP
  4. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Not quite sure, but as far as I remember, include behaves as if the included code was written directly into the first script. So the working directory is never changed, and all paths are relative to the first script...
     
    theOtherOne, Oct 27, 2007 IP
  5. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #5
    require and include work in the same directory.

    if you put a ./ you would need to put that before the quotes, but then it would be searching for a directory named staff.php
     
    Lordy, Oct 27, 2007 IP
  6. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hey, whatever works. Only thing i never tried. changing require to require_once fixed the loop. issue resolved! thanks again
     
    Dirty-Rockstar, Oct 27, 2007 IP
  7. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The include works relative to the path you are calling the script from...

    It is good practice to include files by their full path... Its a little more efficient this way and you wont get caught pulling your hair out (which has happened to me many times :p )
     
    tonybogs, Oct 27, 2007 IP