开发者

Show link based on Referrer URL

I am having a little trouble showing/hiding a link based on the referrer pa开发者_JS百科ge. I am only worried about the page not any extra querys at the end.

BELOW IS THE UPDATED SCRIPT

<? 

$last_page = GetHostByName($_SERVER['HTTP_REFERER']);

  if(strpos($last_page,"fall2011"))
    {
        echo '<li><a href="'. $last_page  .'" class="navigation-link">Fall 2011</a></li>';
    }else{
        //THIS IS HERE FOR TESTING
        echo $last_page;
}


?>

For some reason I am still not getting the referer data.


Why not use $_SERVER['HTTP_REFERER']?

Anyway, you'd want to look into http://php.net/manual/en/function.strpos.php which searches for occurences of a string in another string, rather than testing if two strings match 100%.

EDIT:

Well, when you test the script, do you at least go to the script through a link? You know, you're not a referer otherwise...

If you are going through a link, does the URL where the link is contain fall2011? Also, put an echo 'test'; in the else {} block, see if the condition with strpos() is failing or not.


The link most certainly has its protocol, e.g. http. You'll need to add it in the strong comparison.

Also

  • Access $_SERVER['HTTP_REFERER']. Register globals is deprecated, and for good reason.
  • Don't use error suppressor operator @.
  • Don't make an if with a do nothing body and an else. Instead, flip the condition.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜