Herkes bu oturum açma komut ile yanlış bir şey görebilirsiniz:
public function login($username, $pass, $remember) {
// check username and password with db
// else throw exception
$connect = new connect();
$conn = $connect->login_connect();
// check username and password
$result = $conn->query("select * from login where
username='".$username."' and
password=sha1('".$pass."')");
if (!$result) {
throw new depException('Incorrect username and password combination. Please try again.');
} else {
echo $username, $pass;
}
Açıklamak gerekirse:
At the moment the script is allowing anything through. In other words the query is returning true for any username and password that are passed to it. I've put the echo statement just as a check - obviously the script would continue in normal circumstances!
I know that the connect class and login_connect
method are working because I use them in a register script that is working fine. depException is just an extension of the Exception class.
The function login() is part of the same class that contains register() that is working fine.
I know that the two variables ($username and $pass) are getting to the function because the echo statement is outputting them accurately. (The $remember variable is not needed for this part of the script. It is used later for a remember me process).
I'm stumped. Please help!
UPDATE
Bu yanıt için teşekkürler. Ben sorgu dönen ne ile karışık alıyorum. Tam komut iade kaç satır kontrol yapar ve kontrol yapılmalıydı bu nerede. Şimdi herşey benim, beni hatırlar fonksiyonu için DIŞINDA çalışıyor. Belki birisi bu konuda yardımcı olabilir?!?! İşte tam betik:
public function login($username, $pass, $remember) {
// check username and password with db
// else throw exception
$connect = new connect();
$conn = $connect->login_connect();
// check username and password
$result = $conn->query("select * from login where
username='".$username."' and
password=sha1('".$pass."')");
if (!$result) {
throw new depException('Incorrect username and password combination. Please try again.');
}
if ($result->num_rows>0) {
$row = $result->fetch_assoc();
//assign id to session
$_SESSION['user_id'] = $row[user_id];
// assign username as a session variable
$_SESSION['username'] = $username;
// start rememberMe
$cookie_name = 'db_auth';
$cookie_time = (3600 * 24 * 30);*/ // 30 days
// check to see if user checked box
if ($remember) {
setcookie ($cookie_name, 'username='.$username, time()+$cookie_time);
}
// If all goes well redirect user to their homepage.
header('Location: http://localhost/v6/home/index.php');
} else {
throw new depException('Could not log you in.);
}
}
Yardımlarınız için çok teşekkür ederiz.
GÜNCELLEME 2!
Thanks to your help I've got the main part of this script working. However, the remember me bit at the end still doesn't want to work. Could someone give me a hand to sort it out? $username, $pass and $remember are all short variable names that I assigned before passing them to the function to save writing $_POST['username'] etc. everytime. $remember refers to a checkbox.