gpt4 book ai didi

PHP session 销毁

转载 作者:搜寻专家 更新时间:2023-10-30 20:06:06 27 4
gpt4 key购买 nike

如何销毁 php 中的 session ?

事情是当用户点击注销按钮时, session 将结束,他将被重定向到 index.php 这是我的代码

客户.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>

这是来自用户想要再次登录的 index.php

<?PHP 
/* this must go before any html */
session_start();

if (isset($_SESSION['user'])) {
header("location: Customer.php");
}
?>
<div class="sign">
<h2>Welcome</h2>
<form action = "Customer.php" method = "POST">
Customer Name:<input type = "text" name="customerName">
<input type = "submit" name = "submit">
</form>

最佳答案

session_start();
session_destroy();

关于PHP session 销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7244581/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com