最近我試圖創建爲我的項目的登錄網頁。 所以有index.html這個人必須登錄的登錄頁面。這將查詢發送到 checklogin.php是這樣的:PHP無法回憶起會議
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("wordshare.zxq.net", "754319_guest", "guest")or die("cannot connect");
mysql_select_db("wordshare_zxq_users")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_start();
session_register("myusername");
session_register("mypassword");
header("location:main.php");
}
else {
header("location:index.html");
}
ob_end_flush();
?>
然後在主網頁檢查的會話,如果您還沒有登錄它重定向你的index.html,代碼是如下:
<?php
// Connects to your Database
mysql_connect("wordshare.zxq.net", "754319_guest", "guest")or die("cannot connect");
mysql_select_db("wordshare_zxq_users")or die("cannot select DB");
//checks cookies to make sure they are logged in
session_start();
session_start();
if(!session_is_registered(myusername)){
header("location:index.html");
}
?>
的問題是,我不重定向回主頁,如果我直接去main.html中。 我試着用echo來找出會話是否被記錄,並且它返回undefined。 讓我感到困惑的是,即使當我嘗試打印出某個單詞之類的東西時,它也會使我「未定義」。 任何人都可以幫助我嗎?
會話在第二個代碼片段if(isset($ _ SESSION [「myusername」]))中檢查用戶名是否設置.. – Gntem 2012-07-21 09:49:38