R
R
Ruslan Tilyaev2019-06-05 16:34:42
Yii
Ruslan Tilyaev, 2019-06-05 16:34:42

How to make a 403 error?

Hello fellow programmers!
Could you help me) The idea is this:
I have registration, authorization on the site. Accordingly, there is also a user's personal account. How to do the following: So that if the user is not logged in or not registered, he could not go to his personal account ("ishop.loc/cabinet.html"), so that an error 403 comes out LIKE THIS
:
5cf7c4eb1175a773072437.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Ruslanov, 2019-06-05
@Heckfy325

for yii-2.
just for yii - I don't know. I will find something - I will add the answer.

use yii\web\HttpException;
//some code...
throw new HttpException(403/*or any code*/, 'Forbidden'/*or any message*/);

but in general you need to do this:
try {
  //any code
} catch (Exception $e) {
    echo 'Выброшено исключение: ',  $e->getMessage(), "\n"; // any action/message
}

H
Habr, 2019-06-05
@GA_Roman

throw new yii\web\HttpException(403, 'Доступ запрещен');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question