php #home页面不重新定向



我正在使用应用程序。但是登录系统有问题。如果正确登录,我想将用户重定向到(http://localhost/media/index.php#home)。但是目前似乎不起作用。当我键入登录信息时,它只是重新加载,什么也不会发生。请帮助!

<?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>';
    }
?>

最新更新