开发者

Change Page From PHP Script?

I am a complete PHP newbie, and I'm not even sure if I should be using PHP for what I'm doing, but here goes. Basically all I want to do is 开发者_如何学JAVAbased on where a user comes from, change a link on the page to link to another location. I feel like this is very basic, but I'm not sure exactly how to phrase my search to get the best results. How would I do this?


You probably want something along the lines of

<?php if ($_SERVER['HTTP_REFERER'] === 'http://www.example.com') { ?>
  <a href="http://www.example.com/1">1</a>
<?php } else { ?>
  <a href="http://www.example.com/2">2</a>
<?php } ?>


$_SERVER['HTTP_REFERER'];

This will give you the url of client requesting the page. As said in this post: "Note that it is provided by the client so it may be empty or faked, so don't trust it security-wise."

source of REQUEST


Not sure exactly how you would best google that, but hopefully this will get you started:

To figure out where a user came from, you need $_SERVER['HTTP_REFERER']. Here's a tutorial based on doing a header redirect on that: http://bytes.com/topic/php/answers/7406-how-redirect-based-_server-http_referer

But you'll want to substitute echoing out a link instead of using header().

So quick snippet it would be something like this:

if (!empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'stackoverflow.com')) {
    echo "<a href='http://thatplaceiwanttogoto.com'>Here</a>";
} else {
    echo "<a href='http://thatotherplace.com'>There</a>";
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜