我輸入用戶名=「管理員」 PW ='admin'on我的login.php說的價值觀上中mysqladmin登錄註銷腳本問題用PHP在mysqli的
真實,它停在check_login.php後,我不能看到什麼。
謝謝你的回答。
這裏是代碼
check_login.php
<?php
define(DOC_ROOT,dirname(__FILE__)); // To properly get the config.php file
$username = $_POST['username']; //Set UserName
$password = $_POST['password']; //Set Password
$msg ='';
if(isset($username, $password)) {
ob_start();
include(DOC_ROOT.'/config.php'); //Initiate the MySQL connection
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($username);
$mypassword = stripslashes($password);
$myusername = mysqli_real_escape_string($dbC, $myusername);
$mypassword = mysqli_real_escape_string($dbC, $mypassword);
$sql="SELECT * FROM login_admin WHERE user_name='$myusername' and user_pass=SHA('$mypassword')";
$result=mysqli_query($dbC, $sql);
// Mysql_num_row is counting table row
$count=mysqli_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 "admin.php"
session_register("admin");
session_register("password");
$_SESSION['name']= $myusername;
header("location:admin.php");
}
else {
$msg = "Wrong Username or Password. Please retry";
header("location:login.php?msg=$msg");
}
ob_end_flush();
}
else {
header("location:login.php?msg=Please enter some username and password");
}
?>
和
admin.php的
<?php
session_start(); //Start the session
define(ADMIN,$_SESSION['name']); //Get the user name from the previously registered super global variable
if(!session_is_registered("admin")){ //If session not registered
header("location:login.php"); // Redirect to login.php page
}
else //Continue to current page
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Welcome To Admin Page Demonstration</title>
</head>
<body>
<h1>Welcome To Admin Page <?php echo ADMIN /*Echo the username */ ?></h1>
<p><a href="logout.php">Logout</a></p> <!-- A link for the logout page -->
<p>Put Admin Contents</p>
</body>
</html>
我tryed東西找到我寫的錯誤回聲 「asdasd」在我的check_login.php上,我看到「asdasd」,直到21.線開始於sessi on_register(...)。我認爲這是我的問題,但我不知道如何使用它。
查看PHP中啓用錯誤報告。它會讓你的生活變得更加容易,並給你詳細的錯誤信息:http://php.net/manual/en/function.error-reporting.php另外,檢查你的PHP日誌文件在服務器上。它會告訴你到底是什麼問題。哦,'session_register'已被棄用 - 使用'$ _SESSION'代替 – Basic
包括你的config.php也讓我們看到它 –
'session_register()'從5.3開始已被棄用我相信。 –