nah... Her har du det. Har tilføjet nogle flere kommentarer (på engalsk) der gør det lettere at fatte.. Håber du forstår engels :]~
----- BEGIN login.php -----
// XyborX login-system (
www.xyborx.dk). Feel free to distribute, as long as you keep this comment in the code
// array login ([string nick,[string password,[string mysql_coloumns,[string users_database,[string users_table]]]]])
// If success, returns an array with user-information from the coloumns in the database
// (example: $user=login(); echo $user['nick'])
// If the user could not be logged in, returns false
// If no nick or password is specified, we will try to find it in the $_REQUEST or $_COOKIE variables
function login($login_nick='',$login_password='',$columns='*',$users_database='website',$users_table='users'){
logout();
if(!$login_nick) $login_nick= $_REQUEST['login_nick']; if(!$login_nick)$login_nick= $_COOKIE['login_nick'];
if(!$login_password)$login_password=$_REQUEST['login_password'];if(!$login_password) $login_password=$_COOKIE['login_password'];
// If both nick and password were entered, proceed. Else return false
if($login_nick && $login_password)
{
// If $db_link isn't open, then open it. Used by most of my scripts.
// Remember to close it again later with mysql_close($db_link)
if(!$db_link) $db_link=mysql_connect($mysql_host,$mysql_name,$mysql_password);
// Check if the nick and password is found in the database
$login_query=mysql_query("SELECT $columns FROM $users_database.$users_table WHERE nick='$login_nick' AND password='$login_password'",$db_link) or die ("mySQL query failed:<BR>".mysql_error());
// If excactly 1 user was found, proceed. Else, something is wrong and we return false
if(mysql_num_rows($login_query)==1)
{ // Login was successfull
// Set the cookies with login_nick and login_password
setcookie('login_nick',$login_nick,time()+(3600*24*7));
setcookie('login_password',$login_password,time()+(3600*24*7));
$i=mysql_fetch_row($login_query);
// Collect information bout the users, such as $user['nick']
$user=Array();
$no_of_coloumns=mysql_num_fields($login_query);
for ($count=0;$count<$no_of_coloumns;$count++)
{
$this_fieldname=mysql_field_name($login_query, $count);
$user[$this_fieldname]=$i[$count];
$user[$count]=$i[$count];
unset($this_fieldname);
}
// Update the last_active coloumn to time(). Comment it out, if you don't want it
mysql_query("UPDATE $users_database.$users_table SET last_active=".time()." WHERE id=$user[id]",$db_link) or die ("Update of last_active failed:<BR>".mysql_error());
// If the user has just logged in, send this header to avoid the ugly "Send information again" box in IE
if($_POST['login_nick'] && $_POST['login_password']){ header("Location:
http://www.xyborx.dk$REQUEST_URI");}
// Return the gathered information about the user, such as $user['nick']
return $user;
}
else
{
return false;
}
}
else
{
return false;
}
}
// void logout()
// Logs the user out by deleting the cookie with username and password
function logout()
{
setcookie('login_nick','',1);
setcookie('login_password','',1);
}
------ END login.php ------