Konieczne było przeniesienie się na nowy serwer, który działa tylko pod PHP5, natomiast skrypt pisany był pod PHP4. Praktycznie nie było żadnych zmian prócz skryptu odpowiadającego za logowanie, który początkowo dawał błąd o call to a member function on a non-object, jednak po dodaniu dwóch linijek kodu problemu nie ma (dodanie w funkcji logowania parent::__construct(); i zamiana include na include_once). Pojawił się jednak bardzo nieoczekiwany problem: przy logowaniu z poprawnymi danymi występuje błąd o złych danych. Sprawdziłem o co chodzi i wynika, że skrypt przekazuje pusty login i password dalej, mimo wpisania tam danych (SELECT *, count(id) as ile FROM users WHERE login='' AND haslo='d41d8cd98f00b204e9800998ecf8427e' GROUP by id limit 1)
Poniżej wysyłam kod do login.class.php:
Kod
<?php
class login extends Controller {
function login($login, $password) {
parent::__construct();
$qry= $this->sql->sql_query("SELECT *, count(id) as ile FROM users WHERE login='$login' AND haslo='" . md5($password) . "' GROUP by id limit 1");
$this->sql->sql_fetch_array($qry);
if ($this->sql->rows[ile] == 1) {
if ($this->sql->rows[blokada] == 1) {
$this->bloki();
$this->error("Konto zablokowane!", "Twoje konto zosta≥o zablokowane. Je∂li chcesz masz moŅliwo∂ś skontaktowania siÍ
z administracjĪ: <a href=\"mailto:" . ADMIN_MAIL . "\">" . ADMIN_MAIL . "</a>");
exit;
}
if ($this->sql->rows[stat] == 0) {
$this->bloki();
$this->error("Konto nieaktywne!", "Twoje konto jest jeszcze nieaktywne! Wys≥ali∂my do Ciebie mail z potwierdzeniem rejestracji, zatem sprawdľ swojĪ pocztÍ!");
exit;
}
session_register('user');
$_SESSION[user]= $this->sql->rows;
/*if ($_SESSION[user][login] != $_COOKIE[autologin]) {
$_COOKIE[autologin]= $_SESSION[user][login];
}*/
$this->sql->sql_query("UPDATE users SET ip='" . $_SERVER[REMOTE_ADDR] . "' WHERE id='" . $_SESSION[user][id] . "'");
$this->smarty->assign('user', $this->sql->rows);
$this->smarty->assign('auth', '1');
$pm= pm :: pmCnt($_SESSION[user][id]);
online :: update($_SESSION[user][id]);
$this->bloki();
$this->getClass('profile');
if ($_POST[autologin] == true) {
$hash= substr(md5(md5(rand(0, 1000)) . md5(rand(0, 1000))), 0, 20);
$this->sql->sql_query("INSERT INTO autologin SET hash='$hash', value='$login'");
setcookie("autologin", $hash, time() + 3600 * 24 * 31);
}
profile :: showMyProfile();
header("Location: profile.html");
// $this -> smarty -> display('index.html');
exit;
} else {
$this->bloki();
$this->smarty->assign('inc', 'blad_logowania.html');
$this->smarty->display('index.html');
}
}
function logout() {
session_unregister('user');
session_unregister('admin');
session_unregister('auth');
online :: delete();
online :: listen();
setcookie("autologin", "-1", time() + 3600 * 24 * 31);
$this->bloki();
$this->smarty->assign('auth', '0');
$this->welcomeMessage();
$this->listNews();
header("Location: index.html");
}
function form() {
$this->smarty->assign('inc', 'logowanie.html');
$this->smarty->display('index.html');
}
function autologin() {
if ($_COOKIE[autologin] != "-1") {
//$this -> sql -> sql_cache("user_" . $_COOKIE[autologin]);
$this->sql->sql_query("SELECT value FROM autologin WHERE hash='$_COOKIE[autologin]'");
$this->sql->sql_fetch_row();
$autolog= $this->sql->rows[0];
if ($autolog != '') {
$qry= $this->sql->sql_query("SELECT * FROM users WHERE login='" . $autolog . "' limit 1");
$this->sql->sql_fetch_array($qry);
if ($this->sql->rows[blokada] == 1) {
$this->error("Konto zablokowane!", "Twoje konto zosta≥o zablokowane. Je∂li chcesz masz moŅliwo∂ś skontaktowania siÍ
z administracjĪ: <a href=\"mailto:" . ADMIN_MAIL . "\">" . ADMIN_MAIL . "</a>");
exit;
}
//$this -> sql -> sql_cache();
if ($this->sql->rows[login] != '') {
session_register('user');
$_SESSION[user]= $this->sql->rows;
//header("Location: index.html");
$this->smarty->assign('user', $this->sql->rows);
}
}
}
}
}
?>
class login extends Controller {
function login($login, $password) {
parent::__construct();
$qry= $this->sql->sql_query("SELECT *, count(id) as ile FROM users WHERE login='$login' AND haslo='" . md5($password) . "' GROUP by id limit 1");
$this->sql->sql_fetch_array($qry);
if ($this->sql->rows[ile] == 1) {
if ($this->sql->rows[blokada] == 1) {
$this->bloki();
$this->error("Konto zablokowane!", "Twoje konto zosta≥o zablokowane. Je∂li chcesz masz moŅliwo∂ś skontaktowania siÍ
z administracjĪ: <a href=\"mailto:" . ADMIN_MAIL . "\">" . ADMIN_MAIL . "</a>");
exit;
}
if ($this->sql->rows[stat] == 0) {
$this->bloki();
$this->error("Konto nieaktywne!", "Twoje konto jest jeszcze nieaktywne! Wys≥ali∂my do Ciebie mail z potwierdzeniem rejestracji, zatem sprawdľ swojĪ pocztÍ!");
exit;
}
session_register('user');
$_SESSION[user]= $this->sql->rows;
/*if ($_SESSION[user][login] != $_COOKIE[autologin]) {
$_COOKIE[autologin]= $_SESSION[user][login];
}*/
$this->sql->sql_query("UPDATE users SET ip='" . $_SERVER[REMOTE_ADDR] . "' WHERE id='" . $_SESSION[user][id] . "'");
$this->smarty->assign('user', $this->sql->rows);
$this->smarty->assign('auth', '1');
$pm= pm :: pmCnt($_SESSION[user][id]);
online :: update($_SESSION[user][id]);
$this->bloki();
$this->getClass('profile');
if ($_POST[autologin] == true) {
$hash= substr(md5(md5(rand(0, 1000)) . md5(rand(0, 1000))), 0, 20);
$this->sql->sql_query("INSERT INTO autologin SET hash='$hash', value='$login'");
setcookie("autologin", $hash, time() + 3600 * 24 * 31);
}
profile :: showMyProfile();
header("Location: profile.html");
// $this -> smarty -> display('index.html');
exit;
} else {
$this->bloki();
$this->smarty->assign('inc', 'blad_logowania.html');
$this->smarty->display('index.html');
}
}
function logout() {
session_unregister('user');
session_unregister('admin');
session_unregister('auth');
online :: delete();
online :: listen();
setcookie("autologin", "-1", time() + 3600 * 24 * 31);
$this->bloki();
$this->smarty->assign('auth', '0');
$this->welcomeMessage();
$this->listNews();
header("Location: index.html");
}
function form() {
$this->smarty->assign('inc', 'logowanie.html');
$this->smarty->display('index.html');
}
function autologin() {
if ($_COOKIE[autologin] != "-1") {
//$this -> sql -> sql_cache("user_" . $_COOKIE[autologin]);
$this->sql->sql_query("SELECT value FROM autologin WHERE hash='$_COOKIE[autologin]'");
$this->sql->sql_fetch_row();
$autolog= $this->sql->rows[0];
if ($autolog != '') {
$qry= $this->sql->sql_query("SELECT * FROM users WHERE login='" . $autolog . "' limit 1");
$this->sql->sql_fetch_array($qry);
if ($this->sql->rows[blokada] == 1) {
$this->error("Konto zablokowane!", "Twoje konto zosta≥o zablokowane. Je∂li chcesz masz moŅliwo∂ś skontaktowania siÍ
z administracjĪ: <a href=\"mailto:" . ADMIN_MAIL . "\">" . ADMIN_MAIL . "</a>");
exit;
}
//$this -> sql -> sql_cache();
if ($this->sql->rows[login] != '') {
session_register('user');
$_SESSION[user]= $this->sql->rows;
//header("Location: index.html");
$this->smarty->assign('user', $this->sql->rows);
}
}
}
}
}
?>
index.php (a konkretnie jego część odpowiadająca za logowanie)
Kod
$controller = new Controller();
switch ($_GET['act']){
case 'news':
$controller -> showNews((int)$_GET[id]);
break;
case 'login':
$controller -> login($_POST[login], $_POST[password]);
break;
switch ($_GET['act']){
case 'news':
$controller -> showNews((int)$_GET[id]);
break;
case 'login':
$controller -> login($_POST[login], $_POST[password]);
break;