I want to set up a page that it is only accessible when it is redirected to from another site but when you type the URL in directly, it does not work, so for example, I have a page like example.com/test.html and I want it to only work when it comes from payfast.co.za but from any other way (like typing the URL in directly, then it does not work and you are redirected to example.com/fail.html . How do I do that? Thanks in advance
Asked
Active
Viewed 67 times
-2
-
1Possible duplicate of [(htaccess) How to prevent a file from DIRECT URL ACCESS?](http://stackoverflow.com/questions/10236717/htaccess-how-to-prevent-a-file-from-direct-url-access) – Mike Oct 20 '16 at 16:49
-
1Use `stripos()`. `["HTTP_REFERER"]` isn't reliable. – Funk Forty Niner Oct 20 '16 at 17:01
2 Answers
2
You Can checek http referer
The HTTP referer is an HTTP header field that identifies the address of the webpage that linked to the resource being requested. By checking the referrer, the new webpage can see where the request originated.

Arjun sharma
- 521
- 4
- 9
0
you already have the solution from @8zero2.ops. you can do it like that.
if($_SERVER["HTTP_REFERER"] === "payfast.co.za"){
{#what you want} else {
echo "Error";}

youssouf
- 381
- 2
- 11
-
Sure. Another solution exists but i works fine if your website uses databases. if so, you can save an activity in a table (like the timestamp) when the redirection is ready to be done, and check for the last stamp in the the new webpage. thus, you will now if the user had an activity in the last minute, if so, show the the webpage, else redirect him back to payfast.co.za. you can use this solution along http referer (and maybe setting cookie before redirection (but it cannot be trusted since the user can create it)) to perform it. – youssouf Oct 20 '16 at 17:13