SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using $_SERVER['HTTP_REFERER']???

    I've been trying to figure out how to know weither or not a link on my page is clicked or if the page is accessed from somewhere else, like writing it in the address field or clicking a link in a search engine or something like that.

    I've been searching the forum, read about sessions at php.net, and so on. Then I read about problems with $_SERVER['HTTP_REFERER']. I think the problem is actually my sollution. There is nothing registered if the address comes from a bookmark, is typed directly, or used from behind a firewall, and the only time it DOES show up is when a link is clicked.

    So... if I compare the value from $_SERVER['HTTP_REFERER'] with my domain name, then I could have something NOT happen when that is true, couldn't I?

    Something like this:
    PHP Code:
    if ($_SERVER['HTTP_REFERER'] != ("mydomain") {
       
    //do header redirect and use session variable
    } else {
       
    //do nothing

    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  2. #2
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Better to use a regexp-matcher so you can catch different instances of your domain-- "Reptilian-feline.net" or www.reptilian-feline.net or "REPTILIAN-FELINE.NET" etc

    PHP Code:
    if ( !preg_match("/reptile-feline.net/i",$_SERVER[HTTP_REFERER]) ) {
     
    // do this etc
     
    exit;

    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to make Overgrow's regex more "correct," i'd use this:

    PHP Code:
    if (!preg_match('#^http://(www\.)?reptile-feline\.net#i'$_SERVER['HTTP_REFERER']))
    {
        
    // do this etc
        
    exit;

    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou so much for your help I'm testing to see if it works as I expected.

    It works! If the referer isn't my own domain, it starts a session and redirects to the frameset with the name of the first page as the variable. If the referer IS my domain then the session is killed.
    PHP Code:
    <?php
    unset($session);
    if (!
    preg_match('#^http://(www\.)?mydomain\.ext#i'$_SERVER['HTTP_REFERER']))
    {
        
    $_SESSION["page"] = $_SERVER['SERVER_URL'].substr($_SERVER['PHP_SELF'],1);
        
    header("Location:  http://mydomain.ext/frameset.php" );
        exit;    
    } else {
        
    session_start();
        
    session_destroy();
    }
    ?>
    Thanks for helping me!
    Last edited by reptilianfeline; Apr 1, 2003 at 03:37.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...


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
  •