porzant Posted June 25, 2007 Share Posted June 25, 2007 Is there any way to get the referrer document URL other than:$_SERVER['HTTP_REFERER']^ doesn't work for me, when I echo it, it just displays nothing. Link to comment Share on other sites More sharing options...
vijay Posted June 25, 2007 Share Posted June 25, 2007 Hi.. May I know how and in which scenario are you using this " $_SERVER['HTTP_REFERER'] "..? if you have refer page then and then only you have value for it.. otherwise its empty...so check for that...Regards,Vijay Link to comment Share on other sites More sharing options...
vijay Posted June 25, 2007 Share Posted June 25, 2007 Hi.. May I know how and in which scenario are you using this " $_SERVER['HTTP_REFERER'] "..? if you have refer page then and then only you have value for it.. otherwise its empty...so check for that...Regards,Vijay Link to comment Share on other sites More sharing options...
porzant Posted June 25, 2007 Author Share Posted June 25, 2007 I'm trying to make a "form protection" thing, I want it only to add a record to an SQL database if the referring page was the one I made, not one somebody else made with the same action. So on the action page I want to do something like:IF ($_SERVER['HTTP_REFERER']=="myform.php"){// some code Link to comment Share on other sites More sharing options...
Mr_CHISOL Posted June 25, 2007 Share Posted June 25, 2007 One other way to do it is to use sessions... Link to comment Share on other sites More sharing options...
porzant Posted June 25, 2007 Author Share Posted June 25, 2007 How exactly would I do that, to find out if a user came from a certain page? Link to comment Share on other sites More sharing options...
porzant Posted June 25, 2007 Author Share Posted June 25, 2007 I have a form which adds records to a table, I want to make sure that the user came from my form on another page, so it will only add messages which I have formatted. So in normal language, I need:if(referrer_url == "mypage.php"){// some code to run.} Link to comment Share on other sites More sharing options...
justsomeguy Posted June 25, 2007 Share Posted June 25, 2007 It would probably be better to use sessions, to make sure they are logged in on your site. The referrer will be empty if the URL was manually typed or selected from a bookmark, or if the browser is going from https to http. I'm not sure if browsers will set the referrer when submitting a form or not, the referrer is optional for browsers and it's easy enough to fake it. Link to comment Share on other sites More sharing options...
porzant Posted June 26, 2007 Author Share Posted June 26, 2007 How do I use sessions to make that work then please . Link to comment Share on other sites More sharing options...
justsomeguy Posted June 26, 2007 Share Posted June 26, 2007 On the page with the form you need to start a session and set a variable, like this: <?phpsession_start();$_SESSION['from_thesite'] = true;?> On the form processing page, you need to again start the session and then make sure the variable is set: <?phpsession_start();if (isset($_SESSION['from_thesite'])){ //they came from the form page}else{ //they didn't}?> Link to comment Share on other sites More sharing options...
porzant Posted June 27, 2007 Author Share Posted June 27, 2007 That works great thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.