There is a page with a login form that sends data from it via AJAX:

function call() { if($(".nick").val() == "" || $(".pass").val() == "" || $(".capcha").val() == "") return false; var msg = $('#loginform').serialize(); $.ajax({ type: 'POST', url: '/templates/logincheck.php', data: msg, success: function(data) { if(data == 'ok') window.location.href = "/ucp.php"; else alert(data); }, error: function(xhr, str){ sweetAlert("Ой", 'Возникла ошибка: ' + xhr.responseCode, "error"); } }); } 

Here it is. She sends them to logincheck.php :

 <?php session_start(); if(isset($_POST['login'])) { if(isset($_POST['password'])) { if(isset($_POST['capcha']) && $_POST['capcha'] == $_SESSION['captcha']) { require_once("connect.php"); if ($stmt = $mysqli->prepare("SELECT `password` FROM `accounts` WHERE `player_name` = ?")) { $stmt->bind_param("s", $nickname); $nickname = $_POST['login']; $stmt->execute(); $stmt->bind_result($password); while ($stmt->fetch()) { $pswd = $password; } $stmt->close(); } else echo 'err5'; $mysqli->close(); if($pswd == $_POST['password']) { $_SESSION['login'] = $nickname; echo 'ok'; } else echo 'err4'; } else echo 'err3'; } else echo 'err2'; } else echo 'err1'; 

The correct data is ucp.php - the redirect goes to ucp.php , but the $_SESSION['login'] variable is empty. What can be wrong?

ucp.php:

 <?php function createRedirect($where) { $s='<html><head>'; $s.='<meta http-equiv="refresh" content="5; url='.$where.'">'; $s.='</head><body>Ошибка. Вы будете перенаправлены <a href="'.$where.'">сюда</a>'; $s.= '</body></html>'; return $s; } if(!isset($_SESSION['login'])) die(createRedirect("login.php")); 

Redirectitis (

PS In the logincheck'e session is saved, 100%. Debag shows nothing (error reporting)

  • Session_start (); forgot to register something at the beginning of the file - zhenyab
  • @zhenyab I understand, but if ucp.php register in ucp.php , then Cannot send session cache limiter - headers already sent - Rasrow
  • @zhenyab however, despite warning the conclusion from the variable is correct) - Rasrow
  • Everything. Put output_buffering in php.ini on On - Rasrow
  • We need to figure out what headers are and when they are sent - zhenyab

1 answer 1

Your browser hike prohibits saving cookies from your site. Go to your browser settings and do as in the screenshot:

enter image description here