我一周前刚刚学习php。但现在我有一个问题。我的php登录和会话脚本,只在头版工作。当我使用透明饼干进行测试,并在我的网站上输入特定页面的浏览器时(例如:www.mysite.com/page34.html)登录表格不显示。
为什么尚未登录的用户可以访问我网站的特定页面?
ceklogin.php
<?php
include "koneksi.php";
/* Variable declarationl */
$username = $_POST['username'];
$password = $_POST['password'];
/* check data with my sql db in server */
$user = mysql_query("SELECT * FROM login WHERE username='$username' AND password='$password'");
$match = mysql_num_rows($user);
if ($match==1){
echo "<script>window.location = 'http://www.mysite.com/page1.html'</script>";
}
else {
echo "<h1>Username and Password not match</h1>";
}
?>
的index.php
<?php
if(isset($_COOKIE['AboutVisit']))
echo "<script>window.location = 'http://www.mypage.com/page1.html'</script>"
?>
<?php
$hour = 10800 + time();
//this adds 1 hour to the current time
setcookie(AboutVisit, date("F jS - g:i a"), $hour);
?>
<html>
<head>
<title>Login Area</title>
</head>
<body>
<center>
<form action="ceklogin.php" method="post">
<table>
<tr><td colspan="2" align="center"><h1>Form Login </h1></td></tr>
<tr><td>Username</td><td> : <input type="text" name="username"></td></tr>
<tr><td>Password</td><td> : <input type="password" name="password"></td></tr>
<tr><td colspan="2" align="right">
<input type="submit" value="Login"> <input type="reset" value="Batal"></td></tr>
</table>
</form>
</center>
</body>
</html>
koneksi.php
<?php
mysql_connect("mysql server","my username","password") or die("Koneksi failed");
mysql_select_db("u674105401_01") or die("Database not exist");
//i am hiding my sql server, username, and password in this post
?>
为什么尚未登录的用户可以加入我网站的特定页面?
哪一个错了?
答案 0 :(得分:0)
1 - 删除?><?php
2 - setcookie('AboutVisit', xxx);
答案 1 :(得分:0)
您可以使用php header函数
,而不是使用window.location示例:header('Location: http://www.mypage.com/page1.html');