Why use session_id
Posted: Sun Oct 16, 2005 9:33 am
Jcart | Please use
Jcart | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I have a doubt.
I don't understand why using session_id is necesary.
I can't get to understand why I need them.
I've already created a session manager class and it works quite well without
using session_id. Can anyone tell me why would I need to pass session_id
through URL or cookies?
Here I attach my session_manager class so someone can tell me if i'm doing
something wrong. As I said, it works quite well for me and don't understand
if I should use the session_id somewhere. I know they're there for some reason, but can't see its utility.
Thanks in advanceCode: Select all
class session_manager{
var $s_timeout = 5;
function session_manager()
{
$this->s_timeout = $s_timeout * 60;
session_start();
}
function login($user, $pass)
{
$my_dao = new dao;
$sql = "Select usuarios.*,delegaciones.ciudad "
."From usuarios "
."Inner Join delegaciones ON usuarios.delegacion = delegaciones.id "
."Where usuarios.usuario = '$user' AND usuarios.`password` = '$pass'";
$my_dao->query($sql);
if($my_dao->nextrecord())
{
$user_id = $my_dao->getfield("id");
$this->set_user($id);
return true;
}else{
$this->logout();
return false;
}
}
function set_user($id)
{
$_SESSION['s_user_id'] = $id;
$_SESSION['s_start_time'] = time();
}
function logout()
{
session_unset();
session_destroy();
}
function timeout()
{
$s_time = time() - $_SESSION['s_start_time'];
if($s_time > $this->s_timeout)
{
$this->logout();
return true;
}else{
$_SESSION['s_start_time'] = time();
return false;
}
}
function is_logged()
{
if(isset($_SESSION['s_user_id']))
{ return true; }
else
{
$this->logout();
return false;
}
}
}Jcart | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]