php 链接刷新错误
php links refresh error
你好,我在登录后遇到这个登录脚本的问题,当它必须转到链接时,它只是让我重新登录,我不明白为什么我有一个搜索脚本而不是链接它现在可以工作,但不是很多。
<html>
<head>
<title>User Login Form - PHP MySQL Ligin System | W3Epic.com</title>
</head>
<body>
<h1>User Login Form - PHP MySQL Ligin System | W3Epic.com</h1>
<?php
if (!isset($_POST['submit']) || !isset($_SESSION['username'])){
?>
<!-- The HTML login form -->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" />
</form>
<?php
} else {
require_once("db_const.php");
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username'] = $_POST['username'];
$sql = "SELECT * from members WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
$result = $mysqli->query($sql);
if (!$result->num_rows == 1) {
echo "<p>Invalid username/password combination</p>";
} else {
echo "<table align=center><tr>
<font color=#000000 face=Arial, Helvetica, sans-serif size=+2>
<td align=center><p>Logged in successfully</p></td></tr>";
echo "<tr><td align=center><p>welcome!</p></td></tr>";
echo "<tr><td align=center><p>what wood you like to work whit today ". $username . "!</p></td></tr></table>";
echo "<table align=center><tr><td align=center><a href=adminsearch.php>
<class\= color=#000000; face=Arial Black, Gadget, sans-seri;style=”text-decoration:none; size=+2>Admin</a></td>";
echo "<td align=center>⇔</td>";
echo "<td align=center><a href=constructionsearch.php>
<class\= color=#000000; face=Arial Black, Gadget, sans-seri;style=”text-decoration:none; size=+2>Construction</a></td>";
echo "<td align=center>⇔</td>";
echo "<td align=center><a href=drivingsearch.php>
<class\= color=#000000; face=Arial Black, Gadget, sans-seri;style=”text-decoration:none; size=+2>Driving</a></td>";
echo "<td align=center>⇔</td>";
echo "<td align=center><a href=industrialsearch.php>
<class\= color=#000000; face=Arial Black, Gadget, sans-seri;style=”text-decoration:none; size=+2>Industrial</a></td></font></table>";
}
}
?>
您的脚本现在的方式是,如果未提交表单,它只会显示登录表单。所以当你导航到其他链接时,表单没有提交,所以它会显示表单。您需要使用 cookie 或会话跟踪已登录的用户。在确认 username/password 后将其添加到您的代码中:
$_SESSION['username'] = $_POST['username'];
然后代替这个:
if (!isset($_POST['submit'])){
使用这个:
if (!isset($_POST['submit']) || !isset($_SESSION['username']){
你好,我在登录后遇到这个登录脚本的问题,当它必须转到链接时,它只是让我重新登录,我不明白为什么我有一个搜索脚本而不是链接它现在可以工作,但不是很多。
<html>
<head>
<title>User Login Form - PHP MySQL Ligin System | W3Epic.com</title>
</head>
<body>
<h1>User Login Form - PHP MySQL Ligin System | W3Epic.com</h1>
<?php
if (!isset($_POST['submit']) || !isset($_SESSION['username'])){
?>
<!-- The HTML login form -->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" />
</form>
<?php
} else {
require_once("db_const.php");
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username'] = $_POST['username'];
$sql = "SELECT * from members WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
$result = $mysqli->query($sql);
if (!$result->num_rows == 1) {
echo "<p>Invalid username/password combination</p>";
} else {
echo "<table align=center><tr>
<font color=#000000 face=Arial, Helvetica, sans-serif size=+2>
<td align=center><p>Logged in successfully</p></td></tr>";
echo "<tr><td align=center><p>welcome!</p></td></tr>";
echo "<tr><td align=center><p>what wood you like to work whit today ". $username . "!</p></td></tr></table>";
echo "<table align=center><tr><td align=center><a href=adminsearch.php>
<class\= color=#000000; face=Arial Black, Gadget, sans-seri;style=”text-decoration:none; size=+2>Admin</a></td>";
echo "<td align=center>⇔</td>";
echo "<td align=center><a href=constructionsearch.php>
<class\= color=#000000; face=Arial Black, Gadget, sans-seri;style=”text-decoration:none; size=+2>Construction</a></td>";
echo "<td align=center>⇔</td>";
echo "<td align=center><a href=drivingsearch.php>
<class\= color=#000000; face=Arial Black, Gadget, sans-seri;style=”text-decoration:none; size=+2>Driving</a></td>";
echo "<td align=center>⇔</td>";
echo "<td align=center><a href=industrialsearch.php>
<class\= color=#000000; face=Arial Black, Gadget, sans-seri;style=”text-decoration:none; size=+2>Industrial</a></td></font></table>";
}
}
?>
您的脚本现在的方式是,如果未提交表单,它只会显示登录表单。所以当你导航到其他链接时,表单没有提交,所以它会显示表单。您需要使用 cookie 或会话跟踪已登录的用户。在确认 username/password 后将其添加到您的代码中:
$_SESSION['username'] = $_POST['username'];
然后代替这个:
if (!isset($_POST['submit'])){
使用这个:
if (!isset($_POST['submit']) || !isset($_SESSION['username']){