Possible Duplicate:
PHP redirect based on IP AND referrer
is it possible to redirect a user if they access the site from another location, what i want to do is when the user access the site from google, he will be redirected to the main site, but if he accessed the website from the link that came from the “main site” , a pop up window will appear that contains the restricted site, but since the user came from the “main site” he will be granted access.
any php or javascript will do, as long as it will check if the user came from the main site.
or if possible check from what “IP” the user came from to grant access?
Redirecting the user can be accomplished using the header() method and setting a “Location: ” header for the new target. The conditional can be expressed by evaluating the Referer Header send by the client, this should be available in one of the PHP system variables, see http://php.net/manual/en/reserved.variables.server.php
Something along the lines of:
should do the trick.
To redirect the google bot and that actions’ implications see Does Google bot crawl entire site if there is a redirect and http://forums.digitalpoint.com/showthread.php?t=1210
For figuring out what’s inside the variables and how to use regular expressions in PHP, use this example code
in your script or something like phpfiddle.org