How to check what file is requesting another?

Discussion in 'PHP' started by wdstuff54, Dec 30, 2007.

  1. #1
    Hi -

    I'm trying to check what domain/file is requesting another one.

    For example if I have file webstuff.com/a.php and it is pulling in file b.php is there a way for file b.php to check and make sure that it is domain webstuff.com and file a.php that are requesting it?

    I would like to use PHP and or javascript for this.

    Thanks.
     
    wdstuff54, Dec 30, 2007 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can check the name of the including file, or check if a variable declared in the including file has a value...
     
    selling vcc, Dec 30, 2007 IP
  3. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #3
    Use the global $_SERVER['HTTP_REFERER']
     
    HuggyStudios, Dec 30, 2007 IP
  4. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i would go with this too, parse it up until you get the thing you want to differentiate with other domain. you could also do a quick combination with requesting IP for more security.
     
    kendo1979, Dec 30, 2007 IP
  5. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #5
    HTTP_REFERER doesn't work for include files.

    Of the few times I've needed to do this and haven't wanted to rely on the including file to set a variable, I used the debug_backtrace function ( http://php.net/manual/en/function.debug-backtrace.php ) and just moved my way back up the trace until I found the include function call.
     
    TwistMyArm, Dec 31, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    If a.php is including b.php:

    In b.php, $_SERVER['PHP_SELF'] will be a.php, and __FILE__ will be b.php. That might help.
     
    nico_swd, Dec 31, 2007 IP