Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jan 28th, 2006, 4:21 AM   #1
KyrinComaBlack
Programmer
 
KyrinComaBlack's Avatar
 
Join Date: Dec 2005
Location: Toronto, Ontario, Canada
Posts: 48
Rep Power: 0 KyrinComaBlack is on a distinguished road
Send a message via MSN to KyrinComaBlack
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]
KyrinComaBlack is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC