Php #home页面没有重定向

时间:2016-06-19 19:08:22

标签: php jquery html

我正在开发一款应用。但是登录系统有问题。我想将用户重定向到(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-->

1 个答案:

答案 0 :(得分:0)

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

将此代码放在页面底部:

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