Results 1 to 15 of 15

Thread: http referer

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Canada
    Posts
    75

    http referer

    I'd like to determine if a user has come from a certain webpage (to make it impossible to enter the page from elsewhere)
    Using PHP 4.0 with no globals...

    Anyone want to point me in the right direction?

    Thanks

  2. #2
    PHP Code:
    echo $HTTP_REFERER
    It's not always guaranteed to work though, especially if the browser doesn't send HTTP/1.1 headers (unlikely though).

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by filburt1
    PHP Code:
    echo $HTTP_REFERER
    It's not always guaranteed to work though, especially if the browser doesn't send HTTP/1.1 headers (unlikely though).
    filburt, that method is deprecated and in PHP 4.2 will automatically be turned off.

    PHP Code:
    echo $_SERVER['HTTP_REFERER']; 
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Also, to touch up on what filburt said:

    HTTP_REFERER
    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Oi

    Yeah I'm used to running PHP 4.1 on my site's server, cheers

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Canada
    Posts
    75
    what would you recommend to determine whether the page was send via a form?
    a hidden field?

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by sinewaves
    what would you recommend to determine whether the page was send via a form?
    a hidden field?
    Um...yes, I suppose. If the form is within a PHP document, you can do:

    PHP Code:
    echo "<input type=\"hidden\" value=\"" $_SERVER['PHP_SELF'] . "\">"
    $_SERVER['PHP_SELF'] contains the URL of the current PHP document.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Canada
    Posts
    75
    actually the php page just gets information from an html file...so i could just include a hidden field and in the php file check if the hidden value is there?

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm not exactly sure what you're talking about...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Canada
    Posts
    75
    Ok let me clarify...
    I have a form on one of my .html files that submits to a php file

    I want to ensure on the php file that it was submit to via the correct .html....should i include a "hidden" field in the form of .html and then with the php determine whether the hidden is there or not?

    Would this be the most logical?

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Yes, that would be best then.

    PHP Code:
    //In the HTML file:
    <input type="hidden" name="source" value="good">

    //In the PHP file:
    if($_REQUEST['source'] != 'good') {
      echo 
    "Input came from illegal source!";
    } else {
      
    //your code here

    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Canada
    Posts
    75
    Ok thanks alot for your input

  13. #13
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Of course, if someone else wanted to use your script (if that's what you're trying to protect against), they'd probably find the hidden field and put it in their form as well.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  14. #14

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Canada
    Posts
    75
    Thats not really my concern, i jsut dont want people to bookmark the page and go straight to it without using the form...

  15. #15
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Oh, gotcha. Then the hidden field should do just fine.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width