-
PHP check reffering URL
Hi, I dont know if this is at all possible, but I was looking for a PHP script that checks the referring URL and only runs the rest of the script if a user came from a specific site. e.g if someone was browsing the web and went on a certain page on my site it wouldnt do anything, but if they came to the page directly from paypal then it would run the script.
If you are still with me do you know if this is possible, and if it is how would I go about this? Cheers in advance for any help.
-
-
<?php
if (strpos('google',$_SERVER['HTTP_REFERER'])!==FALSE) {
dostuff();
}
else {
die();
}
?>
Something like that.
That would check if google existed within the referring URI. It would, however, allow for any use of the word, such as something.com/google, etc.
You could use 'http://google', but that wouldn't allow for 'http://www.google', etc. Just think about how you want to do it, and then it's fine.
You could also use regular expressions to match a pattern (such as 'http://', then something with only 1 dot, then 'google')
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
-
Thanks so much for the code and the fast reply! Really appreciate it.
-
-
Sure. No problem.
A couple more things to note, though--
Using the referring URI is ok, but you shouldn't entirely rely on it because some browsers strip this (it isn't required by the server), some things, like just typing the URL directly won't have a referrer at all, and there are some ways to fake this.
It generally can work, though, and is useful in some cases. Just be a bit wary.
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
-
Thanks for the info, but it should be ok, I am just using it as part of my shop system to make sure people only go to a page after being to paypal and not just skipping straight to the end page. I dont think people will anyway because they dont know what the end page it called so its more just for my piece of mind!
Cheers again.
-
-
Just thought I would add a little to it...
Ok so you said you wanted to check if the paypal website was the refering URI?
If so don't, this is extremely unsafe and could lead to people getting your products for free.
For example, if I was to purchase a 10p sweet from paypal the use javascripts location.href="youraddress" then this would trick your system into thinking they have used paypal to buy your product.
I'm not sure how you would get around this but I just thought I would let you know it can be an issue.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks