我遇到登录会话问题。它工作得非常好,但唯一的问题是它在我登录时第一次不起作用,而是一直保持加载直到我第二次登录。以下是登录会话的代码。请帮帮我。
的login.php
<?php
session_start();
$error='';
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
$username=$_POST['username'];
$password=$_POST['password'];
$connection = mysql_connect("localhost", "root", "12345");
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$db = mysql_select_db("company", $connection);
$query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username;
echo "Login Successfully";
header('Refresh: 3; ../packages/package.php');;
} else {
$error = "Username or Password is invalid";
}
mysql_close($connection);
}
}
?>
session.php文件
<?php
$connection = mysql_connect("localhost", "root", "12345");
// Selecting Database
$db = mysql_select_db("company", $connection);
session_start();
// Storing Session
$user_check=$_SESSION['login_user'];
$ses_sql=mysql_query("select username from login where username='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['username'];
if(!isset($login_session)){
mysql_close($connection);
header('Location: index.php');
}
?>
login_page.php
<?php
include('login.php');
if(isset($_SESSION['login_user'])){
header("location: ../index.php");
}
?>