我的MYSQL PHP是正确的但是当我登录时,页面 check.php 再次在login.page上重定向我。为了验证页面重定向,我在URL中使用*?session*
。可能是因为我的会话未激活。怎么样?甚至所有标签都是纠正的。
还有其他问题吗?请帮忙。
提前谢谢你。!!!
登录页面
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();
if (isset($_SESSION["Mobile"]) && isset($_SESSION["LoggedIn"]))
{
header("Location: index.php");
exit();
}
if (isset($_POST["submit"]))
{
$connection = new mysqli("localhost", "id4915357_regis", "Demo@1653", "id4915357_reg");
if ($data->num_rows > 0)
{
$_SESSION["Mobile"] = $Mobile;
$_SESSION["loggedIn"] = 1;
header ("Location: index.php");
exit();
} else {
echo "<script>alert(' Invalid Credentials')</script>";
}
}
?>
的index.php
<!DOCTYPE html>
<html lang="en-US"> <head>
<title>MyWebsite</title>
<meta charset="utf-8"/>
</head>
<body> <form action="login.php" method="post">
<input type="text" name="Mobile" placeholder="Mobile" value="1234567890"/>
<input type="text" name="Password" placeholder="Passwors"/>
<input type="submit" name="submit" value="Log In"/>
</form>
</body>
</html>
CHECK.PHP
<?php
session_start();
if (!isset($_SESSION["Mobile"]) || !isset($_SESSION["LoggedIn"]))
{
header("Location: login.php?session");
exit();
}
?>
答案 0 :(得分:2)
session_start()
函数必须是文档中的第一件事。在任何HTML标记之前。
并且页面应使用.php
扩展名
答案 1 :(得分:0)
session_start()应位于代码的最顶层。你should not output anything before calling it
否则它会失败。同样适用于 setcookie()和 header();
查看您的代码,我认为如果将您的php块移动到html内容的顶部会更好。