There is a class for the login form:

class Controller_login extends Controller { function action_index() { session_start(); // Π‘Ρ‚Π°Ρ€Ρ‚ сСсси $error["login_status"]=''; // объявлСниС ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ с ошибкой if (isset($_POST['enter'])) { if (empty($_POST['email']) || empty($_POST['password'])) { $error["login_status"] = "access_fail1"; } else { $email=$_POST['email']; $password=$_POST['password']; $connection = mysql_connect("localhost","mysql","mysql");// ΠΊΠΎΠ½Π΅ΠΊΡ‚ $email = stripslashes($email);// Π·Π°Ρ‰ΠΈΡ‚Π° ΠΎΡ‚ ΠΈΠ½ΡŒΠ΅ΠΊΡ†ΠΈΠΉ $password = stripslashes($password); $email = mysql_real_escape_string($email); $password = mysql_real_escape_string($password); $db = mysql_select_db("myshop", $connection);// Π²Ρ‹Π±ΠΎΡ€ Π‘Π” $query = mysql_query("select * from tblUsers where Password='$password' AND Email='$email'", $connection);// SQL запрос $rows = mysql_num_rows($query); if ($rows == 1) { $_SESSION['login_user']=$email; // инициализация сСссии header("location: /profile"); // Ρ€Π΅Π΄ΠΈΡ€Π΅ΠΊΡ‚ } else { $error["login_status"] = "access_fail2"; header("location: /login"); } mysql_close($connection); // Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ соСдинСниС } } $this->view->generate('login_view.php', 'template_view.php'); } } 

Next to the profile form, I connect the session.php in which I output the email recorded in the session:

 <?php session_start(); $connection = mysql_connect("localhost","mysql","mysql"); $db = mysql_select_db("myshop", $connection); $user_check=$_SESSION['login_user']; $ses_sql=mysql_query("select Email from tblUsers where Email='$user_check'", $connection); $row = mysql_fetch_assoc($ses_sql); $login_session =$row['Email']; if(!isset($login_session)){ mysql_close($connection); } 

So, the task is to complete all these sessions by clicking the exit button, but an error pops up

Warning: session_destroy (): Trying to destroy the session in F: \ Openserver \ OpenServer \ domains \ gidrolux.ru \ application \ controllers \ controller_main.php on line 18

I try to implement the output as follows:

 function action_logout() { session_unset(); session_destroy(); } 

    1 answer 1

    To be able to work with the session, you need to start it.

     function action_logout() { session_start(); session_unset(); session_destroy(); } 

    upd . a couple of references to the documentation

    session_start() creates or recovers a session (based on the session id transmitted via a GET parameter or cookie ).

    To set a session name, call session_name($name) before session_start()

    • Something nonsense))) That's not the problem. And the fact that he does not have a session at the time of destruction. And just to create a new one and instantly destroy it is not a solution to his question. - Vasily Barbashev
    • one
      @ Vasily Barbashev, session_start does not create a new session, it simply creates it and if before that (in the past references to the site) something was written to it, then in this "new" session (which is old) everything will be. - BOPOH
    • 2
      @ Vasily Barbashev, is it possible? do not advise what you do not fully understand - BOPOH
    • one
      @ Denis Session is an array, you can make the fields you need $_SESSION['auth'] , $_SESSION['someElse'] , while auth can be an object / array itself - Vasily Barbashev
    • 3
      @ Denis, this will be one session. session_start does not create a new session, it simply creates it. If you need to leave certain data - delete unnecessary and leave only the necessary. Think of a session as an array of $_SESSION , if roughly, then session_start() after session_destroy() creates a new array (i.e. creating a clean session), and if session_destroy() not called, then session_start() simply uses the old array . Accordingly, if it is necessary to remove something definite - it is definite and can be deleted. Either delete the session and write the data there again - BOPOH