P
P
pudz2014-06-07 14:36:03
User identification
pudz, 2014-06-07 14:36:03

How to redirect an unauthorized user to the login page?

There is the following method:

protected function auth() {
  if(isset($_COOKIE['gotostreet'])) {
    // Тут код проверки куки
  }
        // если куки нет перенаправляет на страницу авторизации
  else header("Location: /login");
}

The problem is that when a user enters the authorization page For example: www.site.ru/login and does not have a cookie, it redirects to the same page and a loop is obtained. How to properly process this check.
It would be desirable that only the authorization page was available for an unauthorized user, any other pages, not finding the proper cookies, would redirect him to the authorization page.
I am implementing this scheme in mvc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepan, 2014-06-07
@pudz

if(isset($_COOKIE['gotostreet']) and $_SERVER["REQUEST_URI"]!='/login') {
    // Тут код проверки куки
  }
        // если куки нет перенаправляет на страницу авторизации
  else header("Location: /login");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question