このログインページを php で書く作業はほぼ完了しました (完了したと思っていました)。ユーザーが詳細を入力してログインボタンを押すと、すべてが正常に機能します。
ただし、ユーザーがログインすると、ブラウザの進むボタンと戻るボタンを使用して 2 つのページ間を移動できます。
これが起こらないようにする方法はありますか?基本的に、ログイン ページにある場合、次のページに進むことはできません。
(1ページ目、ログインページ)
<form method="post" action="selectQuery.php">
<table width="768" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="118" height="34">Name:</td>
<td width="650"><select name="username" id="username">
<option value="fredk">Fred</option>
<option value="arbonk">Arbon</option>
<option value="arsalana">Arsalan</option>
<option value="minhn">Minh</option>
<option value="nathanielg">Nathaniel</option>
</select></td>
</tr>
<tr>
<td height="33">Password:</td>
<td><input name="password" type="password" value="password" maxlength="16" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Login" /></td>
</tr>
</table>
</form>
(2ページ目)
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$referer = $_SERVER['HTTP_REFERER'];
#connection to server
$connection = @mysql_connect ( "***.***.**.*" , "****", "*******") or die ("Could not connect to server");
#connection to database
$rs = @mysql_select_db ( "one", $connection ) or die ("Could not connect to Database");
#the sql query
$sql = "SELECT * FROM `users` WHERE user_name = \"$username\" AND password = \"$password\"";
#executing the query
$results = mysql_query( $sql, $connection ) or die ("Could not connect to Database");
#counts the no of rows that much the query
$row = mysql_num_rows($results);
##$rows = count(row);
#checks to see if password field is left blank
#if so it will return the user back to the login page
#if there is a match then we assume that the login is authenticated
if (empty($password) || $row == 0)
{
header( "Location:$referer" ); exit();
}
else
{
if ($username == 'fredk')
{ $fname = 'Fred'; }
else if ($username == 'arbonk')
{ $fname = 'Arbon'; }
else if ($username == 'arsalana')
{ $fname = 'Arsalan'; }
else if ($username == 'minhn')
{ $fname = 'Minh'; }
else if ($username == 'nathanielg')
{ $fname = 'Nathaniel'; }
$msg = "Hi $fname, your login was successfull. <p></p>";
echo($msg);
}
?>
2 ページ目のコードは、ログインが正しいかどうかを確認する必要があります。すべて問題がなければ、ユーザーに表示される追加のコード (フォームと別のデータベース クエリ) があります。