![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
|
Sessions
Ok I have created this session script. I think i am missing something but im not really sure what it is and im wondering if someone can tell me i am or not.
[php] <?php ######################################## ######################################## ## session.php ## ## ## ## ######################################## ######################################## ######################################## ##Required Files ######################################## require("config.php"); require("constants.php"); ######################################## ##Start Sessions ######################################## class Session{ //Values Of $_SESSION //example: $_SESSION['username']; public $sess_user = "username"; public $sess_email = "email_address"; public $sess_ip = "ip"; //Value Of $_COOKIE //example: $_COOKIE['username']; public $cook_user = "username"; public $cook_pass = "password"; //Value Of $_POST //example: $_POST = $_COOKIE public $post_user = "username"; public $post_pass = "password"; //Misc Vars public $profile = "profile"; //Verify that the user got a session function verifySession(){ $this->sess_user = sess_user; $this->sess_email = sess_email; $this->sess_ip = sess_ip; if(!isset($_SESSION[$this->sess_user]) || !isset($_SESSION[$this->sess_email]) || !isset($_SESSION[$this->sess_ip]) || $_SESSION[$this->sess_ip] != $_SERVER['REMOTE_ADDR']){ return false; }else{ return true; } } //Verify that cookie exist function verifyCookie(){ $this->cook_user = cook_user; $this->cook_pass = cook_pass; if(isset($_COOKIE[$this->cook_user]) && isset($_COOKIE[$this->cook_pass])){ return true; }else{ return false; } } //Create Session function createSession(){ $this->username = $_SESSION[$this->sess_user]; $this->email = $_SESSION[$this->sess_email]; $this->ip_addy = $_SESSION[$this->sess_ip]; session_start(); } //Make Cookie mmm cookies ![]() function writeCookie() { setcookie($this->cookie_username,$this->username); setcookie($this->cookie_password,$this->password); } //Verify That The User Has Enter In Login Info Correctly function verifyLogin(){ $this->post_user = post_user; $this->post_pass = post_pass; if(!isset($_POST[$this->post_user]) || !isset($_POST[$this->post_pass]) && $_POST[$this->post_user] != '' && $_POST[$this->post_pass] != ''){ return true; }else{ return false; } } //Create Login function createLogin(){ $this->post_username = $_POST[$this->post_username]; $this->post_password = md5($_POST[$this->post_password]); } //If User Successfully Logged In Redirect To Profile function login(){ $this->profile = profile; $vfy_session = $this->verifySession(); if($vfy_session){ $this->redirect($this->profile); } $vfy_cookie = $this->verifyCookie(); if($vfy_cookie){ if($db->MySQL){ $this->createSession(); $this->redirect($this->profile); } } $vfy_form = $this->verifyLogin(); if(!$vfy_form){ if($db->MySQL){ return $this->error; }else{ $this->createSession(); } if($_POST[$this->post_cookie]){ $this->writeCookie(); } $this->redirect($this->profile); } } //If User Hits Logout Then We Redirect //That User Back To The Login Page Again ![]() //And We Destroy The Session function logout(){ $_SESSION = array(); session_destroy(); header("Location: " . $this->loginPage); } function loggedIn(){ //Check To See If User Is Logged In $vfy_session = $this->verifySession(); $vfy_cookie = $this->verifyCookie(); if($vfy_cookie){ if($db->MySQL){ $this->createSession(); }else{ $this->redirect($this->profile); } } } }; $session = new Session; ?> [/php] |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|