Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP登录(会话问题)_Php_Mysql_Session_Cookies_Session Variables - Fatal编程技术网

PHP登录(会话问题)

PHP登录(会话问题),php,mysql,session,cookies,session-variables,Php,Mysql,Session,Cookies,Session Variables,我的MYSQL PHP是正确的,但当我登录时,pagecheck.PHP再次在login.page上重定向我。为了验证页面重定向,我在URL中使用了*?session*。可能是因为我的会话未激活。怎么用?甚至所有的标签都是正确的 还有其他问题吗?请帮忙 提前谢谢 登录页面 <?php error_reporting(E_ALL); ini_set("display_errors", 1); session_start(); if (isset($_SESSION

我的MYSQL PHP是正确的,但当我登录时,pagecheck.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>";  
 } 
 }  

?> 
会话_start()应该位于代码的最顶端。在调用它之前,
不应输出任何内容
,否则它将失败。setcookie()和header()也是如此

查看您的代码,我认为最好将php块移动到html内容的顶部。

文档中的第一件事必须是
session\u start()
函数。在任何HTML标记之前。
并且页面应该使用
.php
扩展名保存

您在代码段中添加了
会话()
注释为
记住我未选中
,可能是您没有选中记住复选框。请检查控件的位置,是否在
if
else
部分。注释不用于扩展讨论;这段对话已经结束。
<!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>
<?php 

session_start();    
if (!isset($_SESSION["Mobile"]) || !isset($_SESSION["LoggedIn"]))
   {            
 header("Location: login.php?session");
    exit(); 
   }
?>