我在我的網站上註冊會話時遇到了問題登錄腳本:我嘗試了以下腳本,但它一直重定向到主登錄頁面,我懷疑腳本沒有註冊session.please幫助我。 這裏是腳本:會話註冊不起作用
checklogin.php
<?php
$con=mysqli_connect("localhost","root","p11","daot");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql=mysqli_query($con,"SELECT * FROM registration WHERE
Username='$myusername' and Password='$mypassword'");
// Mysql_num_row is counting table row
$count=mysqli_num_rows($sql);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_start();
$_SESSION["myusername"];
$_SESSION["mypassword"];
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
login_success.php
<?php
session_start();
if (!isset($_SESSION['myusername']))
{
header('Location:login.php');
}
?>
<html>
<body>
Login Successful
</body>
</html>
一如既往:'session_start();'必須在頁面頂部。 –
我把它放在頂部,但沒有任何改變。 – user3279301
@@ john Conde希望....不是強制性的放置頂部/第一,,,會話必須開始之前去操縱 – user1844933