hi, i have set up a membership system for a website.
eveything that updates i.e. add news, update news, edit user profile etc are all verified on a single php page called updated.php
it works by the following:

$last = getenv("HTTP_REFERER");  //get last page

and then using an if statement to check the last page with the page url i.e. if the last page was addnews

if ( $last == "http://localhost/addnews.php") {
then update the database

it all works fine. although i wanted to use the $_SERVER["DOCUMENT_ROOT"] function opposed to the lanky url that i would have to change when its uploaded. currently if i set it on my hard drive (localhost)

if ($last == $_SERVER["DOCUMENT_ROOT"]."/addnews.php");

they will never equate to the same thing becoz

getenv("HTTP_REFERER") returns 'http://localhost/addnews.php'
$_SERVER["DOCUMENT_ROOT"] returns 'c:\ webroot' and therefore

will never equal the same thing.

will this work when uploaded on to a webserver or am i going around it the wrong way, or should i just leave the lanky link and change it to what ever it should be when it is uploaded?

thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FYI, what you are doing will work, but it doesn't provide real security.  Anybody can spoof HTTP_REFERER and some browsers turn it off completely.

However, this might be what you are looking for:

$newsPage = 'addnews.php';
$lastPage = $_SERVER['HTTP_REFERRER'];
if (basename($lastPage) === $newsPage)  /* The user is good */
kostonAuthor Commented:
hey the solution worked, after the spelling corrections hehe.
im totally new to php and so i basically just implemented everything how i would get it working.

so if i was to alter this method, the only other ways i could see it working is, by using  $_GET['action'] on the

and then


would this be a more secure method or do you know an alternative WilliamFrantz?
You have to authenticate at the top of each and every protected page.  What you have suggested is a good approach.  You could also make a standard authentication routine and require() it on every page.

You really want to use cookies and/or session variables so users aren't forced to login over and over.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kostonAuthor Commented:
yes mate i am using sessions already, oki ill change it over to the method i suggested and award you the points
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.