View Full Version : Protecting content with PHP
snipes
03-14-2002, 02:12 PM
I need several of my pages protected from users. However, I must allow the content to be seen if the user just came from PayPal.com (say, after a payment) or from lighthousewd.com. So, I need the pages hidden from everyone except users coming from paypal.com and lighthousewd.com
I tried using some htaccess techniques with no success. I heard there is a simple PHP solution. Anyone know?
Thanks!
Jim Dam
03-16-2002, 09:02 PM
You can use the $_SERVER['HTTP_REFERER'] variable to test if the user comes from one of those pages, and then send the correct output based on that.
snipes
03-16-2002, 11:36 PM
That's my problem. HOW do I do it? I don't know any htaccess commands really at all.
Thanks!
Jim Dam
03-17-2002, 09:58 AM
<?PHP
$rd = $_SERVER['HTTP_REFERER'];
if ($rd = "url1" || $rd = "url2") {
// include the protected content
include("protectedContent.php");
}
else {
// return a 404 error
header("HTTP/1.0 404 Not Found");
}
?>
Then just have your protected content in protectedContent.php.
snipes
03-17-2002, 03:15 PM
Hey, thanks so much for the php code! That is EXACTLY what I was looking for.
One more question: Do I just put this code in the .htaccess file of the directory/file I need to protect? Or do I create some sort of index.php file that will be read???
Thanks so much for your help!
sylow
03-17-2002, 05:28 PM
use == instead of = in if statement
if ($rd == "url1" || $rd == "url2")
Jim Dam
03-17-2002, 09:37 PM
Ah yes, thanks snipes :)
That would be the PHP page that you need hidden (with the actual file included there).
You would need to repeat that for each page. Alternatively you could use .htaccess and mod_rewrite (using %{HTTP_REFERER}). However, I'm not the one to ask for that code, for mod_rewrite never seems to cooperate with me.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.