Php 登录注销会话
我这里有我的登录和注销代码你们能检查一下我的会话是否正确吗 登录代码:Php 登录注销会话,php,session,Php,Session,我这里有我的登录和注销代码你们能检查一下我的会话是否正确吗 登录代码: <?php session_start(); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header('Content-Type: text/
<?php
session_start();
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: text/html');
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("store_data", $connection);
if(isset($_POST['login'])){
$admin=$_POST['user'];
$pass=$_POST['pass'];
$select_user = mysql_query("SELECT admin_name FROM admin");
$select_pass = mysql_query("SELECT admin_pass FROM admin");
$result_1 = mysql_fetch_assoc($select_user);
$result_2 = mysql_fetch_assoc($select_pass);
if($admin !=$result_1['admin_name'] || $pass!=$result_2['admin_pass']){
echo "<script >alert('Invalid password or username')</script>";
header("refresh:0; url=administrator.php" );
}
<?php
session_destroy();
header("Location: administrator.php");
?>
在会话\u销毁之前
您需要会话\u启动
<?php
session_start();
session_destroy();
header("Location: administrator.php");
?>
错误
session\u start()
注销时丢失
您没有在查询中选中$admin
和$pass
值
您的参数在设置会话中错误
而且您没有设置任何会话来销毁它
不要使用MySQL函数,因为它现在已经贬值了
退出时
<?php
session_start(); //add this
session_destroy();
header("Location: administrator.php");
?>
登录时
<?php
session_start();
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: text/html');
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("store_data", $connection);
if(isset($_POST['login']))
{
$admin=$_POST['user'];
$pass=$_POST['pass'];
$query = mysql_query("SELECT * FROM admin where admin_name='$admin' AND admin_pass = '$pass' ");
$result = mysql_fetch_assoc($query);
$count = count($result);
if(!empty($count))
{
$_SESSION["admin_name"] = $admin;
header("refresh:0; url=administrator.php" );
}
else
{
echo "Invalid User";
}
}
您需要启动会话会话_start()代码>在会话_destroy()之前
在注销代码中:
您在登录时没有创建会话。在注销的情况下很好,为什么不试着运行你的代码,看看它是否有效?如果没有,则进行调试。