My login site run in Xampp on Windows exactly. But now I copy it to Apache server, It run but when i type id, pass and submit. It not login and alway return "The ID or Password do not match, try again"
I installed Apache server, MySQL, PHP5 on Ubuntu 11.10 and copy my database from Xampp to MySQL on Ubuntu.
This is my code:
Login.php
<?php session_start(); ?>
<?php if(isset($_SESSION['name'])) {
header('location: member.php?id='.$_SESSION['name']);
}?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Login page</title>
<link href="resources/style.css" type="text/css" rel="stylesheet">
</head>
<body>
<?php
require "./references/BLLClass.php";
//Khoi tao doi tuong BLL
$bllObj = new BLLClass();
//Kiem tra truong du lieu trong 2 o nhap
if(isset($_POST['submit'])) {
$errors = array();
$required = array('account', 'password');
foreach($required as $fieldname) {
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) {
$errors[] = "The <strong> $fieldname </strong> was left bank.";
}
} // end: foreach
if(empty($errors)) {
$acc = mysql_real_escape_string($_POST['account']);
$pword = mysql_real_escape_string($_POST['password']);
//ket noi lay du lieu xac thuc
$result = $bllObj->AuthMember($acc, $pword);
if(mysql_num_rows($result) == 1){
while($rows = mysql_fetch_assoc($result)){
$_SESSION['name'] = $rows['member_name'];
header('Location: member.php');
}; //end while
} else {
$errors[] = "The ID or Password do not match, try again";
}
}//end if(empty($errors)
} // end isset($_POST['submit'])
?>
<div id="wrapper">
<?php
if(!empty($errors)) {
echo "<ul>";
foreach($errors as $error) {
echo "<li>$error</li>";
}
echo "</ul>";
}
?> <!-- Hien thi thong bao loi khi o nhap lieu rong -->
<?php if(isset($message)) echo $message;?>
<form action="" method="POST">
<p>
<label for="account or id"> Account or ID: </label>
<input type="text" name="account"/>
</p> <!-- o nhap ID hoac nick login-->
<p>
<label for="password"> Password </label>
<input type="password" name="password"/>
</p> <!--o nhap password-->
<p>
<input type="submit" name="submit" value="Login"/>
<a href="register.php">Register</a>
</p> <!-- nut submit va chuyen trang dang ky-->
<!-- <div class='login'>
<a href="#">Login</a>
</div>
-->
</div>
</body>
</html>
BLLClass.php
<?php
//Business Logic Layer
require_once 'DBClass.php';
class BLLClass {
private $dbo;
function BLLClass(){
}
//Check username password
function AuthMember($username, $pword) {
$this->dbo = new DBClass();
$hash_pw = sha1($pword);
$query = "SELECT member_name
FROM member
WHERE member_ID='$username'
OR member_login_name = '$username'
AND member_password = '$hash_pw'
LIMIT 1
";
$result = $this->dbo->SqlEx($query);
return $result;
}
}
?>
And DBClass.php
<?php
//Data Access Layer
class DBClass{
private $mysql_hostname = "localhost";
private $mysql_port = "3306";
private $mysql_user = "root";
private $mysql_password = "mypass";
private $mysql_database = "db.sums01";
public function DBClass(){
}
//khoi tao ket noi
public function GetConn() {
$conn = mysql_connect($this->mysql_hostname.":".$this->mysql_port, $this->mysql_user, $this->mysql_password) or die("Could not connect to DB");
mysql_select_db($this->mysql_database, $conn) or die("Opps some thing went wrong");
return $conn;
}
//gui query len co so du lieu
public function SqlEx($query) {
$conn = $this->GetConn();
$result = mysql_query($query, $conn) or die (mysql_error($conn));
return $result;
}
}
?>
This is my apache error log
[Thu May 24 20:42:27 2012] [error] [client 192.168.40.1] PHP Warning: mysql_real_escape_string(): Access denied for user 'www-data'@'localhost' (using password: NO) in ~/site/Login.php on line 33, referer: http://192.168.40.130/Login.php
[Thu May 24 20:42:27 2012] [error] [client 192.168.40.1] PHP Warning: mysql_real_escape_string(): A link to the server could not be established in ~/site/Login.php on line 33, referer: http://192.168.40.130/Login.php
[Thu May 24 20:42:27 2012] [error] [client 192.168.40.1] PHP Warning: mysql_real_escape_string(): Access denied for user 'www-data'@'localhost' (using password: NO) in ~/site/Login.php on line 34, referer: http://192.168.40.130/Login.php
[Thu May 24 20:42:27 2012] [error] [client 192.168.40.1] PHP Warning: mysql_real_escape_string(): A link to the server could not be established in ~/site/Login.php on line 34, referer: http://192.168.40.130/Login.php
[Thu May 24 20:42:27 2012] [error] [client 192.168.40.1] File does not exist: ~/site/favicon.ico
mysql_real_escape_string uses the current MySQL connection to figure out what to escape:
Escapes special characters in the unescaped_string, taking into account the current character set of the connection so that it is safe to place it in a mysql_query(). If binary data is to be inserted, this function must be used.
If there's no connection available, it will try to create one:
If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If no connection is found or established, an E_WARNING level error is generated.
This is why you're getting that particular warning -- it's trying to connect to localhost as the user PHP is running as (www-data) with no password.
To match the rest of your code, you probably want to create a DBClass->escape()
function that uses the connection in that class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.