php链接刷新错误

时间:2015-07-20 20:40:25

标签: php html hyperlink

你好,我登录时遇到了这个登录脚本的问题,当它必须转到链接时它只是让我回来再次登录,我不明白为什么当我有一个搜索脚本,而不是它现在工作的链接,而不是。



<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>&hArr;</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>&hArr;</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>&hArr;</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>";
		
		
}
}
?>		
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您的脚本现在的方式,如果表单未提交,它只会显示登录表单。因此,当您导航到其他链接时,表单未提交,因此它将显示表单。您需要跟踪已登录的用户,使用cookie或会话。在确认用户名/密码后将其添加到您的代码中:

$_SESSION['username'] = $_POST['username'];

而不是这个:

if (!isset($_POST['submit'])){

使用此:

if (!isset($_POST['submit']) || !isset($_SESSION['username']){