SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot zeeshan's Avatar
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi -

    I basically have a php script that does some stuff. But depending on the referring address I want to output two different things.

    This is what I have...Can someone tell me what I'm doing wrong?

    $host = getenv ("HTTP_REFERER");

    if ($host != "http://www.myserver.com")
    {
    return $quotes[$random_index]);
    }
    else {
    print($quotes[$random_index]);
    }

    Is this code incorrect? When I run this, the php never prints to a request coming from my page.

    Help..someone!

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    1) Use strcmp() for string comparisons:
    http://www.php.net/manual/en/function.strcmp.php

    2) If you are running on Apache then you can just use this:
    $host = $HTTP_REFERER;

    OK, so you could code this
    Code:
    if ( strcmp($HTTP_REFERER, "www.myserver.com") != 0 ) {
       // blah
    } else {
       // blah blah
    }
    Last edited by freakysid; Mar 23, 2001 at 20:46.

  3. #3
    SitePoint Zealot zeeshan's Avatar
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi -

    Thanks for the reply...

    Still getting a problem though.

    My code looks like:

    print ($HTTP_REFERER); // For Error checking

    if ( strcmp($HTTP_REFERER, "www.myserver.com") != 0 ) {
    return($quotes[$random_index]);
    } else {
    print($quotes[$random_index]);
    }

    However the first print line to see the referer doesn't print anything.

    Hence when I execute this code from my server it always forks into the "if" bit instead of the "else"

    What gives?

    Thanks in advance!

  4. #4
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try getenv("HTTP_REFERER");
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, if Son Nyugen's suggestion doesn't work ... then - are you running PHP as a apache module or as cgi? I wonder if HTTP_REFERER is available under cgi? I read somewhere that not *all* browsers send the HTTP_REFERER in the header - but these would be the more obscure browsers.

    Silly question, but are you calling the page with the scipt you have quoted by clicking on a a href link in refering page?

  6. #6
    SitePoint Zealot zeeshan's Avatar
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello and thanks for the replies...

    Actually Son's suggestion didn't work - I tried that already.

    As far as I know the server is running Apache. Also I'm using IE 5 so that should dismiss the browser problem.

    I am calling the php script (with the referer check inside of it) as an embedded php tag from my php/html page. So when the page loads, it sees the <? require("file.php") ?> statement and loads the file here.

    Do you think this is the problem?


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
  •