Php 注销后的空页
我的登录表单工作正常,但注销没有。如果我单击注销按钮,它会转到index.php,位置正确,但它不会显示任何(空白)白色屏幕 登录形式:index.phpPhp 注销后的空页,php,html,Php,Html,我的登录表单工作正常,但注销没有。如果我单击注销按钮,它会转到index.php,位置正确,但它不会显示任何(空白)白色屏幕 登录形式:index.php <?php require('CONFIG/config.php'); require('CONFIG/db.php'); if(empty($_SESSION)) // if the session not yet started session_start(); if(isset($_SESSION['email'
<?php
require('CONFIG/config.php');
require('CONFIG/db.php');
if(empty($_SESSION)) // if the session not yet started
session_start();
if(isset($_SESSION['email'])) { // if already login
header("location: ../dashboard.php"); // send to home page
exit;
}
?>
<form class="form-horizontal" role="form" method="POST" action="PHP/action_login.php">
<div class="form-group">
<label class="col-md-4 control-label">Email</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-success col-md-6" name="submit" style="margin-right: 15px; background-color:#069370;">Login </button>
</div>
</div>
</form>
电子邮件
密码
登录
操作登录:PHP/action\u login.PHP
<?php
session_start();
if(isset($_POST['submit'])) {
include('CONFIG/config.php');
include('CONFIG/db.php');
$Email = $_POST['email'];
$Password = $_POST['password'];
$_SESSION['email'] = '$Email';
//erroe handler
//check if the input is empty
if(empty($Email) || empty($Password)) {
header("Location: ../index.php?login=error");
exit();
}else{
$sql = "SELECT * from users where email='$Email' AND password='$Password'";
$sql2 = "SELECT roles.id from users, roles where users.email='$Email'";
$result2 = mysqli_query($conn, $sql2);
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck < 1){
header("Location: ../index.php?login=error");
exit();
}else{
$_SESSION['roleid'] = $result2;
header("Location: ../dashboard.php?login=success");
exit();
}
}
}else{
header("Location: ../index.php?login=error");
exit();
}
-
action logout:action_logout.php(在php文件夹中)
问题是,当我单击注销时,索引表单什么也不显示,为什么?请检查我的代码谢谢在action\u logout.php中,您必须删除
session\u start()
,因为您只需创建一个新会话,然后销毁它
<?php
session_unset();
session_destroy();
header("Location: ../index.php");
exit;
?>
在action\u logout.php中,您必须删除
会话\u start()
,因为您只需创建一个新会话,然后销毁它
<?php
session_unset();
session_destroy();
header("Location: ../index.php");
exit;
?>
警告:您完全可以使用参数化的预处理语句,而不是手动生成查询。它们由或提供。永远不要相信任何类型的输入,尤其是来自客户端的输入。即使您的查询仅由受信任的用户执行,。也不要以明文形式存储密码!仅存储密码散列。使用PHP的和。如果您运行的PHP版本低于5.5(我真的希望您不是),则可以使用该库获得相同的功能。警告:您完全可以使用参数化的预处理语句,而不是手动生成查询。它们由或提供。永远不要相信任何类型的输入,尤其是来自客户端的输入。即使您的查询仅由受信任的用户执行,。也不要以明文形式存储密码!仅存储密码散列。使用PHP的和。如果您运行的PHP版本低于5.5(我真的希望您不是),您可以使用该库获得相同的功能。为什么需要检查会话是否已设置且不为空?为什么不调用
session_start()代码>本身?为什么需要检查会话是否已设置且不为空?为什么不调用session_start()代码>自己?
<?php
session_unset();
session_destroy();
header("Location: ../index.php");
exit;
?>
if(isset($_SESSION) && empty($_SESSION)) {
session_start()
}