session_start(); if (isset($HTTP_GET_VARS['action']) && $HTTP_GET_VARS['action'] == "Login") { Login(); } elseif (isset($HTTP_GET_VARS['loggedin']) && $HTTP_GET_VARS['loggedin'] == "true") { ShowStart(); } //############################################################################# //##################### Login() STARTAR HÄR //############################################################################# function Login() { global $HTTP_POST_VARS; if($HTTP_POST_VARS['login'] == NULL) { print("You must supply a loginname!"); } elseif ($HTTP_POST_VARS['pass'] == NULL) { print("You must supply a password!"); } else { if(!($fp = fopen("shadow", "r"))) { print("Error could not open file"); } else { $found = 0; while(fscanf($fp, "%s %s", $l, $p) != NULL && $found == 0) { if($l == $HTTP_POST_VARS['login']) { $login_name = $l; // For use later $password = $p; $found = 1; } } } fclose($fp); if($found == 0) { print "No user by that name!"; } else { if(md5($password) == $HTTP_POST_VARS['pass']) { session_start(); $blnValidUser = true; $name = $l; session_register("blnValidUser"); session_register("name"); header("location: index.php?loggedin=true"); } else { print("Password incorrect!"); } } } //} //############################################################################# //##################### Login() SLUTAR HÄR //############################################################################# } //############################################################################# //##################### ShowStart() STARTAR HÄR //############################################################################# /* function ShowStart() { global $blnValidUser; global $name; Print "Nu är du inloggad ".$name."!"; } */ function ShowStart() { global $HTTP_SESSION_VARS; session_start(); $name = $HTTP_SESSION_VARS['name']; Print "Nu är du inloggad ".$name."!"; } //############################################################################# //##################### ShowStart() SLUTAR HÄR //############################################################################# ?>