Oto kod:
session.php<?php
define ('SESSION_TIME', 24
*3600
); class session{
function session () {
}
function is_session () {
if(strlen($_COOKIE['session_id']) == 32
) { setcookie ('session_id', $this ->session_id, time()+ SESSION_TIME
); return true;
}
else
return false;
}
function auth_user () {
if (!empty($_POST['login']) && !empty($_POST['password'])) { $username = $_POST['login'];
$password = md5($_POST['password']); mysql::query (\"SELECT user_id FROM lms_users WHERE username = '$username' AND password = '$password'\"); if (mysql::num_rows() == 1
) { $row = mysql::fetch_array (); $this -> user_id = $row['id'];
return true;
}
else
return false;
}
else
return false;
}
function new_session () {
if(getenv('HTTP_X_FORWARDED_FOR') != '') $this -> ip
= (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ?
$_SERVER['HTTP_X_FORWARDED_FOR'] : (!empty($_ENV['HTTP_X_FORWARDED_FOR'])) ?
$_ENV['HTTP_X_FORWARDED_FOR'] : $HTTP_X_FORWARDED_FOR; else
$this -> ip
= (!empty($_SERVER['REMOTE_ADDR'])) ?
$_SERVER['REMOTE_ADDR'] : (!empty($_ENV['REMOTE_ADDR'])) ?
$_ENV['REMOTE_ADDR'] : $REMOTE_ADDR; if ($this -> auth_user ()) {
$this -> type = \"human\";
setcookie (\"session_id\", $this -> session_id, time () + SESSION_TIME); mysql::query (\"INSERT INTO \".$db_prefix.\"sessions (session_id, session_user, session_ip) VALUES ('$this -> session_id', '$this -> user_id', 'this ->ip')\"); }
else {
$this -> browser
= (!empty($_SERVER['HTTP_USER_AGENT'])) ?
$_SERVER['HTTP_USER_AGENT'] : $_ENV['HTTP_USER_AGENT']; if(preg_match('/(lycos|googlebot|slurp@inktomi|ask jeeves|whatuseek|ia_archiver)/i', $this -> browser
)) $this -> type = \"bot\";
else {
$this -> type = \"guest\";
setcookie (\"session_id\", $this -> session_id, time () + SESSION_TIME); mysql::query (\"INSERT INTO \".$db_prefix.\"sessions (session_id, session_user, session_ip) VALUES ('$this -> session_id', '0', 'this ->ip')\"); }
}
}
function load_session () {
if ($this -> type == \"human\") {
mysql::query(\"SELECT * FROM \".$db_prefix.\"sessions WHERE session_id = '$_COOKIE[session_id]'\"); $sessiondata = mysql::fetch_array(); $this -> session_user = $sessiondata['session_user'];
$this -> session_ip = $sessiondata['session_ip'];
if ($this -> session_ip !== $this -> ip)
$this -> type = \"guest\";
else
$this -> type = \"human\";
}
}
}
?>
mysql.php<?php
var $handle;
var $sql_query;
function mysql ($host, $login, $password) { }
function select_db ($name) {
}
function query ($sql, $handle = $this -> handle) {
}
function num_rows () {
}
function real_escape_string ($str) {
}
function fetch_array () {
}
function free_result () {
}
function close () {
}
}
?>
przyklad.php<?php
include ('./config.cfg');
include ('./databases/mysql.php');
include ('./common/session.php');
$db = new mysql (\"localhost\", \"root\", \"krasnal\"); $db -> select_db (\"lms\");
$session = new Session;
if (!empty($_GET['login']) && !empty($_GET['password'])) $session -> new_session ();
else {
if ($session -> is_session())
$session -> load_session();
else
$session -> new_session ();
}
?>
Oto i cały kod. A poniżej błędy.
BłędyKod
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\usr\krasnal\www\php-lms\databases\mysql.php on line 14
Warning: Wrong parameter count for mysql_num_rows() in c:\usr\krasnal\www\php-lms\databases\mysql.php on line 17
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\usr\krasnal\www\php-lms\databases\mysql.php on line 14