Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jan 28th, 2006, 3: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
Old Jan 30th, 2006, 9:45 PM   #2
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 219
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
your request is incredibly vague. How about testing your own script and when you cant figure out a specific part then maybe post for help on it
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi
freelance scripts - http://ryanguthrie.com/index.html
Mocker is offline   Reply With Quote
Old Feb 1st, 2006, 1:55 AM   #3
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
Like I am wondering if that is a suffient(sp?) session file or do you think i need to add more or what in overall/
KyrinComaBlack is offline   Reply With Quote
Old Feb 1st, 2006, 6:58 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
This isn't meant to be rude, but informative. Not many people are going to look at your code in detail merely to grade it for completeness or style. Most people will chip in to help find a problem, provided that you give a clear description and clean code. That localizes the problem and reduces the time investment, as well as offering some challenge.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

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 3:25 AM.

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