代码会一直打开login.php,其中包含错误和正确的登录详细信息。我打算每次有人尝试登录时启动一个会话,但只允许经过身份验证的尝试
<?php
function login() {
global $con;
if (isset($_POST['submit'])){
// $member_id = $_POST['member_id'];
// $memberpass = $_POST['memberpass'];
if( isset($_POST['member_id']) && isset($_POST['memberpass'])){
$sql= "SELECT * from login ";
$query=query($sql);
if(isset($_SESSION["user"]))
{
if ($_SESSION['member_id'] = $_POST['member_id'] && $_SESSION['memberpass'] = $_POST['memberpass']);
session_start();
header('Location: index1.php');
}
else {
header('Location: login.php');
}
?>
答案 0 :(得分:0)
<?php
session_start();
//For debuging purpose
error_reporting(E_ALL);
ini_set('display_errors', true);
print_r( $_SESSION );
function login() {
global $con;
if (isset($_POST['submit'])){
// $member_id = $_POST['member_id'];
// $memberpass = $_POST['memberpass'];
if( isset($_POST['member_id']) && isset($_POST['memberpass'])){
$sql= "SELECT * from login ";
$query=query($sql);
if(isset($_SESSION["user"]))
{
// remove semi colon at the end ;if ($_SESSION['member_id'] = $_POST['member_id'] && $_SESSION['memberpass'] = $_POST['memberpass']);
if ($_SESSION['member_id'] == $_POST['member_id'] && $_SESSION['memberpass'] == $_POST['memberpass'])
{
header('Location: index1.php');
}
else {
echo "Invalid User";
//header('Location: login.php');
}
}
else {
header('Location: login.php');
}
?>
希望这有帮助。