$_SERVER['HTTP_REFERER'] The page isn't redirecting properly PHP
I am usingheader('Location: ' . $_SERVER['HTTP_REFERER']);
on Logout.php page and it is working properly there.But when I have used it on Login page it gives me error "The page isn't redirecting properly PHP" and "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
My code is :
if($resT==3){
$_SESSION['userId'] = $_POST["user"];
header('Location: '.$_SERVER['HTTP_REFERER']);
}
$resT
is the usertype I am getting from database according to the user.
Answer
Solution:
This error generally comes when you have loop cycle on the page, means you are redirecting in a cycle that is will not halt. There is some logical error in your page.
HTTP_REFERER
Will redirect you to the base address e.ghttp://localhost/
Therefore check your redirection on the pages where you throw the user.
Answer
Solution:
HTTP_REFERER
is set by client and thus not guaranteed to be available. So, it cannot be used for the any purpose other than logging.Store initial location in a session or pass it via form parameter.
Answer
Solution:
Hi Its better to set your back page to be into session and redirect user to that page. Like $_SESSION['backfromlogin'] = $currentpage; than use this session variable to redirect back. your issue is, referrer redirecting to the login page itself. you can echo referrer to make sure.