What causes a redirect loop?

Here are my pages:

Redirect page: if the user has an open session, redirect to the corresponding resource; otherwise redirect to the login page

Login page: if the login details are valid, redirect to $ _SERVER ['HTTP_REFERER'] still display the login page

When you visit the redirect page, it sees that you do not have a valid session and is redirected to the login page. After that, you can log in without problems, but after authentication, I get "This web page has a redirect cycle." Pages in Chrome.

This is not a true loop, as there are several exit paths (IE provides valid login information and goes to the target resource, provides invalid login and error data, etc.). But I see the confusion in the browser (moving from a to b to another).

Any ideas how I can solve this problem?

Greetings

+3
source share
5 answers

$_ SERVER ['HTTP_REFERER'] , , . , , , , , .

, $_SERVER ['HTTP_REFERER'], , , , , $_SESSION, $_COOKIE. , , .

+5

$_SERVER['HTTP_REFERER'] URL- , , , .

" " URL- PHP . , , (, , HTTP ..).

+2

:

, (, ), ( ). , , , ( ), . , , . . ...

? ( ) , .

, , HTTP_REFERER , .

+1

You should always check that the $ _SERVER ['HTTP_REFERER'] variable contains valid data, as it should not be trusted, because user agents provide this value.

From php.net manual

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. 
+1
source

You can let your login page redirect in one go (without redirecting to the redirect page).

0
source

Source: https://habr.com/ru/post/1776539/


All Articles