<?PHP header("Content-Type: text/html; charset=utf-8"); //error_reporting( E_ERROR ); //require 'db.php'; require 'connection.php'; $data = $_POST; if (isset($data['do_login'])) { $name = $data['name']; //берём имя игрока $password = $data['password']; //берём то что пользователь ввёл при авторизации $query = "SELECT password FROM accounts WHERE name = '".$name."'"; // запрос в бд $user = "SELECT id, name, mail, sex, model, last_ip, password, cash, bank, FROM accounts WHERE name = '".$name."'"; $bd = mysqli_connect("localhost", "admin", "max777", "database"); $cache1 = mysqli_query($bd, $user); // Данные для UCP $result1 = mysqli_fetch_row($cache1); // Данные для UCP $cache = mysqli_query($bd, $query); $users[] = $result1[0]; // ID $users[] = $result1[1]; // Name $users[] = $result1[2]; // Mail $users[] = $result1[3]; // Sex $users[] = $result1[4]; // Model $users[] = $result1[5]; // last_ip $users[] = $result1[6]; // password $users[] = $result1[7]; // cash $users[] = $result1[8]; // bank if (mysqli_num_rows($cache)) { $result = mysqli_fetch_row($cache); $expected_password = $result[0]; // берём пароль из бд $hash = hash('md5', $password); // Хэшируем введёный пароль при помощи md5 if($hash === $expected_password) { // если хеш введённого пароля совпадает с хешом из бд значит пароль введён правильно $_SESSION['logged_user'] = $users; header("Location: panel.php"); }else { // в инном случае введённый пароль не правильный ?><script type="text/javascript">alert("Введён неверный логин или пароль!")</script> <?PHP ; } } else { ?><script type="text/javascript">alert("Введён неверный логин или пароль!")</script> <?PHP ; } } ?> 

<?php print_r($_SESSION['logged_user'][1]); ?> <?php print_r($_SESSION['logged_user'][1]); ?> This is how I bring out the name of the character in the LC, but for some reason it does not appear

  • Developing LC for the GTA server. There is a database in which there are accounts. I receive the data by request and transfer it to the session (the session starts in connection.php). For some reason, the data is not transferred from the database to the Session and from the Session, respectively, in the LC. - Maxim Khalin

1 answer 1

Before writing data to a session or taking it from there, the session must be opened using the session_start () function. You can also try to transfer the session ID with your hands. If the problem persists, you can search for a solution to the problem here: http://php.net/manual/ru/function.session-start.php http://phpfaq.ru/sessions#bugs

Record:

 if($hash === $expected_password) { // если хеш введённого пароля совпадает с хешом из бд значит пароль введён правильно session_start(); $_SESSION['logged_user'] = $users; header("Location: panel.php?".session_name()."=".session_id()); } 

Conclusion:

 <?php session_start(); print_r($_SESSION['logged_user'][1]); ?> 
  • The session starts in the file connection.php and it also connects to the LC. A session in the LC exists, I checked, but for some reason the data is not transmitted - Maxim Khalin
  • In this case, try to pass the session identifier in the header handles, perhaps the problem will be eliminated. I fixed the code in the response - Tsotne Otanadze
  • Mdaaa. Now generally in the LC does not redirect. What added your code that removed it - Maxim Khalin
  • Removed my code and still does not redirect? And you just cleaned everything right? Well, or at least you can specify errors? server responses? Try to exit or die after the header in order for the program to stop exactly. And about the sessions, try to look at phpfaq.ru/sessions#bugs , in due time this article helped me to get rid of many of the bugs related to the sessions. - Tsotne Otanadze 5:56 pm