AlexxFoexx
@AlexxFoexx
Начинающий фронтэнд разработчик

Почему не срабатывает сессия?

Добрый вечер! помогите почему не отрабатывает условие?
auth.php
<?php
	$password = '827ccb0eea8a706c4c34a16891f84e7b';  //пароль 12345
	header('Content-Type: text/html; charset=utf-8');

	if ( !empty( $_REQUEST['password'] ) and md5($_REQUEST['password']) == $password ) {
		session_start();

	
		$_SESSION['auth'] = true; 
	} else {
	
		if ( !empty($_REQUEST['password']) and md5($_REQUEST['password']) != $password ) {
			echo 'Неправильный пароль!<br>'; //выведем сообщение об ошибке
		}

	
?>
		<form action='index.php' method='POST'>
			<input name='password' type='password'>
			<input type='submit' value='Отправить'>
		</form>
<?php
 	}
?>


index.php

<?php
	session_start(); 
	header('Content-Type: text/html; charset=utf-8');

	
	if (!empty($_SESSION['auth']) and $_SESSION['auth']) {

		echo '<a href="cabinet.php"> Личный кабинет </a>';

	}else {
		echo 'Доступ запрещен!';
	}
?>
  • Вопрос задан
  • 145 просмотров
Решения вопроса 1
@Karmaa
auth.php
<?php
  $password = '827ccb0eea8a706c4c34a16891f84e7b';  //пароль 12345
  header('Content-Type: text/html; charset=utf-8');

  if ( !empty( $_REQUEST['password'] ) and md5($_REQUEST['password']) == $password ) {
    session_start();

  
    $_SESSION['auth'] = true; 
  } else {
  
    if ( !empty($_REQUEST['password']) and md5($_REQUEST['password']) != $password ) {
      echo 'Неправильный пароль!<br>'; //выведем сообщение об ошибке
    }

  
?>
    <form action='auth.php' method='POST'> //ИЗМЕНЕНИЕ
      <input name='password' type='password'>
      <input type='submit' value='Отправить'>
    </form>
<?php
 	}
?>
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы