$_SERVER['HTTP_REFERER'] The page isn't redirecting properly PHP

665

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.

98

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.

976

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.

761

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.

People are also looking for solutions to the problem: php - form submit inside div with empty action

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.