开发者

Get destiniation URL using PHP?

I'd like to redirect the user depending on the destination url and referrer url. Say I have a homepage url http://www.example.com/ and in that page there are a bunch of links that point to http://www.example.com/page/x/. When the user goes to http://www.example.com/page/ from http://www.example.com/ it should redirect to another page. But when the user goes to http://www.example.com/page/x/ via a link from http://www.example.com/ it should开发者_如何学C not redirect. In order to achieve this, the solution I am thinking is to get the destination url as well to correctly determine if the user comes from http://www.example.com/ but wants to view http://www.example.com/page/x/. Bottom line is I want to prevent access to http://www.example.com/page/ but not to its sub pages.


What you are trying to do here is scary bad.

You can't rely on the referer being returned by the browser (but it is a good indicator). You could use a generic javascript to rewrite every link on the page to append a CGI variable containing the URIencoded URL of the current page (but where javascript is enabled it won't work). Or you could put rewrite the output buffer to inject CGI vars into hrefs in PHP. Neither of these are trivial - and if they break your users will not be able to navigate.

But leaving aside the implementation for now - your solution seems to be rather absurd.

If the problem is to

prevent access to http://www.example.com/page/

but allow requests for

http://www.example.com/page/x/

Then create an index.php in http://www.example.com/page/ with something like....

<?php
header('Location: /', true, 301);
?>

Or disable auto-index on your webserver.


As it seems no one can access the example.com/page/, You can have a Header function in the http://www.example.com/page/ to redirect the page to some other page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜