Jump to content

$_SERVER['PHP_SELF']


Mavent

Recommended Posts

I have a bit of code that's supposed to verify the referring page.  If it's processlogin.php, then it allows access.  Otherwise, it fails.  This works:

 

<?php
$ref = $_SERVER['PHP_SELF']; 
if ($ref != '/processlogin.php')
header('Location: sorry1.php');
?>

 

However, when I try and show more data on the page, it fails on Reload.  At first I thought it was because the page is seeing itself as an invalid Referrer.  So, I added the page itself as a valid referrer, as seen below.

 

<?php
$ref = $_SERVER['PHP_SELF']; 
if (($ref != '/processlogin.php') || ($ref != '/atv_list.php'))
header('Location: sorry1.php');
?>

 

The problem is that now NOTHING works the way I think it should.  Whereas if ($ref != '/processlogin.php') worked just fine when it was by itself, now it throws the Fail state.  However, the page can now be reloaded, which doesn't make much sense to me. Next I attempted the following:

 

<?php
$ref = $_SERVER['PHP_SELF']; 
if ($ref != '/processlogin.php' || $ref != '/atv_list.php')
header('Location: sorry1.php');
?>

 

Which didn't work either.  So I thought that MAYBE it's reprocessing through processlogin.php, and the Variables in the URL were causing the problem.  So, I tried this:

<?php

$ref = $_SERVER['PHP_SELF'];

if (strstr($ref,'/processlogin.php'))

{header('Location: sorry1.php');

}

?>

 

And again it doesn't work.

 

Anyone know where I went so horribly, horribly wrong?

 

 

 

 

Link to comment
Share on other sites

Oops , i forgot there is no use of the tab key in this forum  :P

 

HTTP_REFERER will get the refering page http://www.php.net/manual/en/reserved.variables.server.php

$ref = $_SERVER['HTTP_REFERER']; 

//place all the acceptables in here
$acceptedArray = array('/processlogin.php')

if(in_array($ref,$acceptedArray)
{
//do your thing
}
else{
//echo the ref to check whats going on in the bug squatting
echo $ref;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.