$result = $stmt->fetch(PDO::FETCH_ASSOC); if ($result) { $_SESSION['uid'] = $result['uid']; $_SESSION['uname'] = $result['username']; } } } public function isAuthenticated() { return isset($_SESSION['uid']); } public function logout() { unset($_SESSION['uid']); session_destroy(); setcookie("userid", "", time() - 60 * 60 * 24 * 30); setcookie("pass", "", time() - 60 * 60 * 24 * 30); } public function uname() { if ($this->isAuthenticated()) { return $_SESSION['uname']; } else { return "NO LOGIN."; } } } $auth = new userauth(); $auth->dbinit(); //Initial //$u->createTables();
$pass = sqlite_escape_string($_COOKIE['pass']); $q = sqlite_query($this->db, "SELECT * FROM users WHERE uid = '{$id}' AND password = '******' LIMIT 1", $e); if (sqlite_num_rows($q) > 0) { $r = sqlite_fetch_array($q); $_SESSION['uid'] = $r['uid']; $_SESSION['uname'] = $r['username']; } } } public function isloggedin() { return isset($_SESSION['uid']); } public function logout() { unset($_SESSION['uid']); session_destroy(); setcookie("userid", "", time() - 60 * 60 * 24 * 30); setcookie("pass", "", time() - 60 * 60 * 24 * 30); } public function uname() { if ($this->isloggedin()) { return $_SESSION['uname']; } else { return "NO LOGIN."; } } } $u = new userauth(); $u->dbinit();
function get_token($length) { $token = ""; $string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $string .= "abcdefghijklmnopqrstuvwxyz"; $string .= "0123456789"; $max = strlen($string) - 1; for ($i = 0; $i < $length; $i++) { $token .= $string[$this->randomize(0, $max)]; } return $token; } } /* Main application flow starts from here */ session_start(); $user = new userauth(); if ($user->logged_in()) { // Do nothing! } else { if (empty($_POST['userid'])) { ?> <link href="assets/style.css" rel="stylesheet" type="text/css"> <div align=center> <h1>VZBehat User Login</h1> <div style="padding:10px; border:1px solid #777; background-color: #ddd; width:300px;"> <body style="font-size:16px; font-family:Arial"> <form id=login-form method=post action="<?php echo $_SERVER['PHP_SELF']; ?> ">