Code:
<?php /* Funktion zum Einloggen */ function login($id, $password) { global $db; if(empty($id) OR empty($password)) { return FALSE; } setcookie("cook_userid", $id, time() + 30 * 24 * 60 * 60); setcookie("cook_password", $password, time() + 30 * 24 * 60 * 60); $sql = "SELECT * FROM wpc_user WHERE id = '$id' AND password = '$password'"; if(!$db->query($sql)) { return FALSE; } $sql = "SELECT * FROM wpc_session WHERE user = '$id'"; if($db->query($sql)) { return TRUE; } $session = md5($id.$password."logged_in"); $sql = "INSERT INTO wpc_session (user, session) VALUES ('$id', '$session')"; $db->query($sql); return TRUE; } /* Funktion zum Prüfen, ob User eingelogged ist */ function logged_in($session) { global $db, $cook_userid, $cook_password; if(empty($id)) { return FALSE; } $sql = "SELECT * FROM wpc_user WHERE id = '$cook_userid' AND password = '$cook_password'"; if($db->query($sql)) { $session = md5($cook_userid.$cook_password."logged_in"); $sql = "SELECT * FROM wpc_session WHERE user = '$cook_userid'"; if($db->query($sql)) { return TRUE; } $sql = "INSERT INTO wpc_session (user, session) VALUES ('$id', '$session')"; $db->query($sql); return TRUE; } $sql = "SELECT * FROM wpc_session WHERE session = '$session'"; if($db->query($sql)) { return TRUE; } return FALSE; } /* Funktion zum ausloggen */ function logout($session) { global $db; setcookie("cook_userid", 0, time() + 30 * 24 * 60 * 60); setcookie("cook_password", 0, time() + 30 * 24 * 60 * 60); $sql = "DELETE FROM wpc_session WHERE session = '$session'"; $db->query($sql); } ?>
Doerr
Kommentar