Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP会话销毁_Php_Mysql_Database_Session_Destroy - Fatal编程技术网

PHP会话销毁

PHP会话销毁,php,mysql,database,session,destroy,Php,Mysql,Database,Session,Destroy,如何在php中销毁会话 问题是,当用户单击注销按钮时,会话将结束,他将被重定向到index.php Customer.php <?php session_start(); #include("Connection.php"); if (isset($_POST['submit'])) { $name = $_POST['customerName']; $_SESSION['user'] = $name; } if (isset($_SESSION['user'])) { ec

如何在php中销毁会话

问题是,当用户单击注销按钮时,会话将结束,他将被重定向到index.php

Customer.php

<?php 

session_start(); 
#include("Connection.php");
if (isset($_POST['submit'])) { 
$name = $_POST['customerName']; 
$_SESSION['user'] = $name; 
} 
if (isset($_SESSION['user'])) { echo "Hello {$_SESSION['user']}, welcome back"; }
else{echo "walang tao";}

$sql="INSERT INTO ORDERS(Name) VALUES('$name')";
mysql_query($sql);

session_destroy();
?>
<button><a href="Customer.php"></a></button>

您还可以使用
unset()
函数来释放会话环境

if (isset($_SESSION['user']))
{
  unset($_SESSION['user']);
  header('location:index.php');
}

将此文件包含在标题中,并在文件中设置所需的设置。 它应该很有效

<?php
    session_cache_expire(20);
    if (!isset($_SESSION)) {    
        session_start();
    }
    // set timeout period in seconds
    $inactive = 1200; // timeout for the session
    // check to see if $_SESSION['timeout'] is set
    if(isset($_SESSION['timeout']) ) {
        $session_life = time() - $_SESSION['timeout'];
        if($session_life > $inactive) {
            $_SESSION = array();
            if(isset($_COOKIE[session_name()])) {
                setcookie(session_name(), '', time()-42000, '/');
            } 
            session_destroy(); 
            header("Location: index.php"); // or whatever you prefer to do. 
        }
    }
    $_SESSION['timeout'] = time();
?>

如果您不使用auth组件,那么它非常简单

public function logout(){
    $this->Session->destroy();
    // no cake we really want you to delete it because you suck
    $this->Session->destroy();
}
会话_destroy()


session_unset()//函数释放当前注册的所有会话变量

将index.php替换为Customer.php当您看到Bobby Tables时,请代我向他问好。您的Customer.php文件中已经有一个
session\u destroy
调用了吗?“注销按钮”链接到哪里?因为我希望用户重定向到index.php页面
<?php
    session_cache_expire(20);
    if (!isset($_SESSION)) {    
        session_start();
    }
    // set timeout period in seconds
    $inactive = 1200; // timeout for the session
    // check to see if $_SESSION['timeout'] is set
    if(isset($_SESSION['timeout']) ) {
        $session_life = time() - $_SESSION['timeout'];
        if($session_life > $inactive) {
            $_SESSION = array();
            if(isset($_COOKIE[session_name()])) {
                setcookie(session_name(), '', time()-42000, '/');
            } 
            session_destroy(); 
            header("Location: index.php"); // or whatever you prefer to do. 
        }
    }
    $_SESSION['timeout'] = time();
?>
public function logout(){
    $this->Session->destroy();
    // no cake we really want you to delete it because you suck
    $this->Session->destroy();
}
//If you want complete destroy session then you can write.