Php#主页不重定向

Php#主页不重定向,php,jquery,html,Php,Jquery,Html,我正在开发一个应用程序。但是登录系统有问题。如果用户正确登录,我想将他们重定向到()。但到目前为止,它似乎不起作用。当我输入登录信息时,它只是重新加载,什么也没发生。请帮忙 <?php include ("inc/scripts/mysql_connect.inc.php"); ?> <?php session_start(); //Start session //Check if user is logged in or not if (isset($_SESSION['us

我正在开发一个应用程序。但是登录系统有问题。如果用户正确登录,我想将他们重定向到()。但到目前为止,它似乎不起作用。当我输入登录信息时,它只是重新加载,什么也没发生。请帮忙

<?php include ("inc/scripts/mysql_connect.inc.php"); ?>
<?php
session_start(); //Start session
//Check if user is logged in or not
if (isset($_SESSION['user_login'])) {
$user = $_SESSION["user_login"];
 }
else {
$user = ""; //Do nothing
//echo"Sorry but your are not logged in!!!!!!!!!!!!!!"; 
}
?>
<?php
//Login Script
//user Login code
//Check user info when user inputs login information
if (isset($_POST['user_login']) && isset($_POST['password_login']) )
{
//filters input info
$user_login = preg_replace('#[^A-Za-z0-9)]#i','', $_POST['user_login']);//filters everything but numbers and letters
$password_login = preg_replace('#[^A-Za-z0-9)]#i','', $_POST['password_login']);//filters everything but numbers and letters
$password_login_md5 = md5($password_login); // encrypt password input because password in database is already encrypted in md5
//use Binary for case sensitive option
$sql = mysqli_query($con, "SELECT * FROM users WHERE BINARY username= BINARY'$user_login' AND password='$password_login_md5' AND closed='no' LIMIT 1"); //query
//check for existence if user exists
$userCount = mysqli_num_rows($sql); //Count the number of rows returned
//if username exists start session
if($userCount==1)
{
while($row = mysqli_fetch_array($sql)) //fecthing the row to display information
{
$id = $row["id"]; // store user id into variable called $id
}
$_SESSION["id"] = $id;  
$_SESSION['user_login'] = $user_login;
$_SESSION["password_login"] = $password_login;
header("Location: Index.php#Home");//WE WANT USER TO ACCESS THE #HOME PAGE IF THEY ONLY LOGGED IN SUCCESSFULLY
//exit("<meta http-equiv=\"refresh\" content=\"0\">");              
}
else{
    //echo"That information is incorrect, Please try again!";
}
exit(); 
}
?>


<!DOCTYPE html>
<html>
<head>
<title>App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="themes/myThemeEdited.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="main.js"></script>
</head>
<body>

<!-- The welcome page where users must provide login info in order to be logged in -->
<div data-role="page" id="Welcome">
<div data-role="header" data-theme="c">
<h1>Welcome</h1>                    
</div>
<div role="main" class="ui-content">
<form  action = "Index.php" method = "POST"><!--provide username and password then submit -->
<input name="user_login" size= "25" placeholder="Username" type="text"/><!-- Enter username / placeholder  username-->
<input data-clear-btn="false" name="password_login" size= "25" placeholder="Password" autocomplete="off" type="password"/><!-- Enter password /password placeholder-->
<input name="login" value="Login" type="submit" data-theme="c"/><!-- submit button style it later -->
</form>
<div>
<a href="#Home" data-role="button">Sign Up</a><!--Redirect user to sign up page if user not member yet-->
</div>  
</div>
<div data-role="footer" data-position="fixed" data-theme="c"><!-- Footer display/ displays once-->
<h4>(C) 2016</h4><!-- copyright symbols include later-->
</div>
</div><!-- End of the login page-->             


<!-- HOME PAGE AND USER PROFILE PAGE where users can enter and submit texts-->
<div data-role="page" id="Home">
<div data-role="header" data-theme="c"><!-- Jquery settings ref included in the header file-->
<h1>Text</h1>
</div>
<div role="main" class="ui-content">
Enter your text<br>
<!-- Allow users to type and send texts-->
<input name="text-basic" id="text-basic" value="" type="text"/><!-- Enter and send text -->
<a href="" data-role= "button" data-theme="c" onClick="submittext(Q)">Send</a><!-- submit button with onclcick function -->
</div>
</div><!-- End of the Home page-->
</body>
</html><!-- End code-->


正如我在上面的评论中提到的,我认为您不能在这里使用重定向,因为重定向是在加载页面上的HTML之前执行的,因此当您尝试重定向到它时,id不存在。但是,您可以使用javascript和
.scrollTop
来执行此操作

将此代码放在页面底部:

<?php
    if (isset($_SESSION['user_login']))
    {
        echo '<script>
                 var x = document.getElementById('Home').scrollTop;
                 document.body.scrollTop = x;
              </script>';
    }
?>


您的登录表单的action属性设置为
index.php
,而不是
#Home
,因此当您单击submit按钮时,您的登录将带您返回页面。我只看到
标题(“Location:index.php#Home”)
,而不是Media/index.php#Home@SgtAJ但当我在浏览器中输入时,我确实看到了我的主页。这就是我想让用户只有在登录时才能访问的地方。我该如何解决这个问题?首先,你不应该在会话中存储用户的密码。这是非常糟糕的做法。我建议您启用,如果我猜的话,这会给出一些“Headers ready sent”(标题已发送)警告。@Quasimodo's我在尝试使用标题(“Location:Media/Index.php#Home”)时说加载页面时出错。我在html页面底部添加了一段代码,登录时确实会将id返回主页。我有一张空白页,上面写着同样的内容。你能改进吗?什么?你说它可以把身份证带回家,但是页面是空白的?那没有道理。我很清楚,您的登录页面和登录后重定向用户的页面都是index.php页面?如果它们是不同的页面,您需要我在页面底部给您的代码,用户登录后会发送到这些代码。不,我的错,它不会将id带回家。当我输入登录信息并点击提交时,我仍然在localhost/Media/Index.php上,但这次是空白页面。那么#主页是在Index.php页面上,还是在其他页面上?如果是另一个页面,它是什么页面?#主页位于index.php页面上。我可以很容易地用标签找到它。但这种情况不同,我想使用javascript或php代码,这样用户就无法访问#Home,除非他们登录。