2016-06-19 15 views
-1

私はアプリを開発中です。ログインシステムに問題があります。ユーザーが正しくログインしている場合は、ユーザーを(http://localhost/Media/Index.php#Home)にリダイレクトします。しかし、それは現在のように動作していないようです。私がログイン情報を入力すると、ただリロードされ、何も起こりません。助けてください!Php#ホームページはリダイレクトされません

<?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--> 
+0

ログインがちょうどあなたを取るために起こっているので、あなたのログインフォームのアクションプロパティは、ないに '#Home'、index.php''に設定されている:あなたのページの一番下にこのコードを入れて

送信ボタンをクリックするとページに戻ります。 –

+0

Media/Index.phpではなくヘッダ( "Location:Index.php#Home")のみが表示されます。#Home –

+0

@SgtAJですが、http://localhost/Media/Index.php#Homeと入力するとブラウザ私の#Homeページが表示されます。これは、ユーザーがログインしている場合にのみユーザーを招待したい場所です。どうすれば修正できますか? –

答えて

0

上記の私のコメントで述べたように、リダイレクトが実行されているので、私は、ページ上のHTMLがロードされる前にしたとき、これidが存在しない場合、あなたはここにリダイレクトを使用することができるとは思いませんそれにリダイレクトしようとしています。ただし、これを行うにはjavascriptと.scrollTopを使用できます。

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

私はhtmlページの一番下にコードを追加しました。ログインするとidホームが取得されます。代わりに、http://localhost/Media/Index.phpと同じ空白のページがあります。それを改善できますか? –

+0

何ですか?あなたはidホームを取得すると言っていますが、そのページは空白ですか?それは意味をなさない。ログインページとログイン後にユーザーをリダイレクトしているページの両方がindex.phpページであることは間違いありません。それらが異なるページであれば、ユーザーがログインした後に送信されるページの下部にあるコードを必要とします。 –

+0

私の悪いことはIDホームを取得しません。私がログイン情報を渡して、私はlocalhost/Media/Index.phpにまだ残っていますが、空白のページでこの時間。 –

関連する問題