I will give you a few debugging pointers in your code below. One of the most important things to learn is debugging. There are a number of places throughout your script that could cause a failure. I am not going to show you all of them. What you need to do is place debug code in your script so you can track down the bad guys. I have placed a few examples of where I would start.
Debug code can be as simple as echoing SQL queries to make sure they look right before you pass them to the database or echoing variables to see what the values are. I know it adds to you code but during troubleshooting, these few line of code are priceless.
This is my session:
<?php
class login_lib
{
var $server = "localhost";
var $db_user = "root";
var $db_pass = "";
var $database = "login";
var $logout_url = "/login.htm";
var $error = array
(
"Username bevat ongeldige karakters.",
"Password bevat ongeldige karakters."
);
function login($username, $password)
{
if (!eregi("[[:alnum:]_-]+$", $username))
{
return $this->error[0];
}
if (!eregi("[[:alnum:]_-]+$", $password))
{
return $this->error[1];
}
mysql_connect($this->server, $this->db_user, $this->db_pass);
mysql_select_db($this->database);
$query = mysql_query("select id from login where username='$username' and password='$password'");
$result = mysql_num_rows($query);
/*********************************
Added debug code here ******
*********************************/
echo "ROW COUNT=$result";
echo "<br>";
if ($result < 1)
{
return false;
}
else
{
list ($id) = mysql_fetch_row($query);
$time = time();
/*********************************
Added debug code here ******
*********************************/
echo "ID=$id";
echo "<br>";
echo "USERNAME=$username";
echo "<br>";
echo "PASSWORD=$password";
echo "<br>";
echo "TIME=$time";
echo "<br>";
// id and time are not in the session!
// Why?
// How do I get them in?
session_start();
session_register("id", "username", "password", "time");
$id = "";
$time = "";
$username = "";
$password = "";
/*********************************
Move mysql_close here ******
*********************************/
mysql_close();
return 2;
}
}
}
$login_lib = new login_lib;
?>
Hope this helps some.