monkeybidz Posted January 22, 2012 Share Posted January 22, 2012 Im working on an issue that keeps sending the user to logge_in.php and never to post_new.php even if it is the referer. Here is the code I have wrote so far: if($_SERVER['HTTP_REFERER'] =="post_new.php"){ $referer = "post_new.php"; }elseif($_SERVER['HTTP_REFERER'] =="logged_in.php"){ $referer = "logged_in.php"; } header("Location: ".$referer." "); exit(); } Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/255534-server-referer-issue/ Share on other sites More sharing options...
ManiacDan Posted January 22, 2012 Share Posted January 22, 2012 header reditect and http_referrers are full URLs. Quote Link to comment https://forums.phpfreaks.com/topic/255534-server-referer-issue/#findComment-1310102 Share on other sites More sharing options...
monkeybidz Posted January 22, 2012 Author Share Posted January 22, 2012 Yes, I know. I just shortened them for posting here. It will only go to http://www.mysite.com/logged_in.php regardless of the referer page or site. Am I using the ELSE statement incorrectly? Quote Link to comment https://forums.phpfreaks.com/topic/255534-server-referer-issue/#findComment-1310125 Share on other sites More sharing options...
ManiacDan Posted January 23, 2012 Share Posted January 23, 2012 Why do you have the IF/ELSEIF statement at all? Why not delete the whole thing and use the HTTP_REFERRER directly in the header? Quote Link to comment https://forums.phpfreaks.com/topic/255534-server-referer-issue/#findComment-1310223 Share on other sites More sharing options...
monkeybidz Posted January 23, 2012 Author Share Posted January 23, 2012 If the referer is from a certain page I need it to return there after login, but my problem is that the register page on my site returns a success mesage on the same page and there is a login link on the header. If the user clicks on login, they are returned to the register page. Quote Link to comment https://forums.phpfreaks.com/topic/255534-server-referer-issue/#findComment-1310227 Share on other sites More sharing options...
ManiacDan Posted January 23, 2012 Share Posted January 23, 2012 Then I'm not understanding the problem. Your code says "if they came from post_new, send them to post_new. If they came from logged_in, send them to logged_in." Quote Link to comment https://forums.phpfreaks.com/topic/255534-server-referer-issue/#findComment-1310327 Share on other sites More sharing options...
monkeybidz Posted January 24, 2012 Author Share Posted January 24, 2012 Yeah, that was a typo. It's supposed to be login.php. I kind of narrowed down the problem and realized that the code I posted is working, just not passing the var because it sits inside another "if(". Here is the entire code which is suposed to follow the $referer and start a session if the $email checks out ok. if($_SERVER['HTTP_REFERER'] =="post_new.php"){ $referer = "post_new.php"; }elseif($_SERVER['HTTP_REFERER'] =="login.php"){ $referer = "logged_in.php"; } $email=$_POST['email']; $sql="SELECT * FROM users WHERE email='$email' "; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count == "1" && $referer != ""){ session_start(); $_SESSION['email'] = $email; header("Location: ".$referer." "); //I am not getting $referer here exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/255534-server-referer-issue/#findComment-1310510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.