2016-07-13 1 views
0

私は自分のComputer Scienceプロジェクト用のウェブサイトを作成しています。ログインページに戻った後にメッセージボックスを表示させる

私はPHP/HTMLコーディングも新しくなっています。

基本的には、この考え方です。私はログインページを持っていますが、これはあなたをウェブサイトに連れ込ませてくれるものです。しかし、拒否されたときにユーザー名/パスが正しくないことをウェブサイトに伝えたいと思います。あなたが正常にログインしたときに

<html> 
<link rel="stylesheet" type="text/css" href="Style.css"> 
<body> 
<center> 
<h1 style="font-size:70px;">FitnessHub<h1> 
<p>Enter Username & Password to get started</P> 

<form action="Welcome.php" method="post"> 

<table> 
    <tr> 
     <td><input type="text" name="username" placeholder="Username" style="width:400px;height:30px;"></td> 
    </tr> 
    <tr> 
     <td><input type="password" name="password" placeholder="Password" style="width:400px;height:30px;"></td> 
    </tr> 
</table> 

<input type="submit" value="Login" style="width:100px;height:30px;"> 
<br> 



</form> 
<img src="fitnesshub.png" alt="logo" style="width:400px;height=300px;"> 





</center> 
</body> 
</html> 

そしてここに歓迎のページです:ここで

は、ログインページがある

<html> 
<link rel="stylesheet" type="text/css" href="Style.css"> 
<body> 


<h1> Hello <?php echo $_REQUEST[username] ?> </h1> 

<p style="Font-Size:15px;">FitnessCenter can be used to book customers into multiple services<br> 
Use the buttons to start using the database 
</p> 

<?php 
$db = new mysqli("127.0.0.1", "root", "root", "fitnessbooking"); 
$query= $db->query("select Username from users where Username = '$_POST[username]' and Pass = '$_POST[password]'"); 

if ($query->num_rows ==1){ 
echo ""; 
} 
else { 
header("Location: http://localhost/pages/login.php"); 

    exit; 
} 
?> 





</body> 
</html> 

私が言ったように、私はウェブサイトのもので、何の専門家でないので、してみてください私が理解できる方法で事を説明する!

ありがとうございました

+0

[ユーザーを別のWebページにリダイレクトした後にメッセージを表示する](http://stackoverflow.com/questions/12249906/displaying-a-message-after-redirecting-the-user-to-another-web-page ) – FirstOne

+0

の代わりに、すぐにウェルカムページに投稿するフォーム、投稿する別のPHPページを作成し、資格情報をチェックし、悪い場合はそれを拒否するか、それとも良い場合はwelcome.phpに送信してください – Derek

答えて

-2

このサンプルを使用してください。

<html> 
<link rel="stylesheet" type="text/css" href="Style.css"> 
<body> 
<center> 


<?php if((!empty($_GET['login'])&& ($_GET['login'] == 'false')): ?> 
<p>username or password incorrect</P> 
<?php endif;?> 


<h1 style="font-size:70px;">FitnessHub<h1> 
<p>Enter Username & Password to get started</P> 

<form action="Welcome.php" method="post"> 

<table> 
    <tr> 
     <td><input type="text" name="username" placeholder="Username" style="width:400px;height:30px;"></td> 
    </tr> 
    <tr> 
     <td><input type="password" name="password" placeholder="Password" style="width:400px;height:30px;"></td> 
    </tr> 
</table> 

<input type="submit" value="Login" style="width:100px;height:30px;"> 
<br> 



</form> 
<img src="fitnesshub.png" alt="logo" style="width:400px;height=300px;"> 





</center> 
</body> 
</html> 

あなたのウェルカムページです。リダイレクトで

<html> 
<link rel="stylesheet" type="text/css" href="Style.css"> 
<body> 


<h1> Hello <?php echo $_REQUEST[username] ?> </h1> 

<p style="Font-Size:15px;">FitnessCenter can be used to book customers into multiple services<br> 
Use the buttons to start using the database 
</p> 

<?php 
$db = new mysqli("127.0.0.1", "root", "root", "fitnessbooking"); 
$query= $db->query("select Username from users where Username = '$_POST[username]' and Pass = '$_POST[password]'"); 

if ($query->num_rows ==1){ 
echo ""; 
} 
else { 
    header("Location: http://localhost/pages/login.php?login=false"); 

    exit; 
} 
?> 


</body> 
</html> 
+0

ありがとうIこれを試してみましょう! –

0

追加しますか?

<?php 
    if (isset($_GET['fail']) && $_GET['fail'] == 1) 
    { 

     echo "Try again:)"; 
    } 
?> 
0

は、このようなログインページにすべてのことを行う追加のパラメータに、ログインページで

header("Location: http://localhost/pages/login.php?fail=1"); 

を渡す= 1失敗します。

<?php 
session_start(); 

if(isset($_SESSION['auth'])){ 
    header('Location: logged_in.php'); 
    die(); 
} 

if ($_SERVER['REQUEST_METHOD'] === 'POST') { 
    $db = new mysqli("127.0.0.1", "root", "root", "fitnessbooking"); 
    if ($db->connect_error) { 
     die("Connection failed: " . $conn->connect_error); 
    } 
    $stmt = $db->prepare('select Username from users where Username = ? and Pass = ?'); 
    $stmt->bind_param('ss', $_POST['username'], $_POST['password']); 
    $stmt->execute(); 

    if($stmt->num_rows > 0){ 
     $_SESSION['auth'] = true; 
     header('Location: logged_in.php'); 
     die(); 
    } 
    else{ 
     $error_message = "Username Or password are invalid"; 
    } 
} 

?> 


<html> 
    <link rel="stylesheet" type="text/css" href="Style.css"> 
<body> 
    <center> 
     <h1 style="font-size:70px;">FitnessHub<h1> 
     <p>Enter Username & Password to get started</P> 


     <?php 
      //Display the error message 
      if (isset($error_message)){ 
       echo "<p><strong>$error_message</strong></p>" 
      } 
     ?> 
     <form action="Welcome.php" method="post"> 

      <table> 
      <tr> 
       <td><input type="text" name="username" placeholder="Username" style="width:400px;height:30px;"></td> 
      </tr> 
      <tr> 
       <td><input type="password" name="password" placeholder="Password" style="width:400px;height:30px;"></td> 
      </tr> 
      </table> 

      <input type="submit" value="Login" style="width:100px;height:30px;"> 
      <br> 



     </form> 
     <img src="fitnesshub.png" alt="logo" style="width:400px;height=300px;"> 





    </center> 
</body> 
</html> 

他のページには、そのように残し:

<?php 
session_start(); 

if(!isset($_SESSION['auth'])){ 
    die('Access denied'); 
} 

<html> 
<link rel="stylesheet" type="text/css" href="Style.css"> 
<body> 


<h1> Hello User </h1> 

<p style="Font-Size:15px;">FitnessCenter can be used to book customers into multiple services<br> 
Use the buttons to start using the database 
</p> 

</body> 
</html> 

したい場合は、それが使用可能な持っているセッションにユーザー名を格納します。

関連する問題