Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

HTTP_REFERER and DOCUMENT_ROOT

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'
and
$_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.
0
koston
Asked:
koston
  • 2
  • 2
1 Solution
 
WilliamFrantzCommented:
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 */
...
0
 
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 updated.page

and then

updated.php?action=addnews
updated.php?action=updatenews
updated.php?action=editprofile

would this be a more secure method or do you know an alternative WilliamFrantz?
0
 
WilliamFrantzCommented:
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.

http://www.w3schools.com/php/php_cookies.asp

http://us3.php.net/session
0
 
kostonAuthor Commented:
yes mate i am using sessions already, oki ill change it over to the method i suggested and award you the points
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now