Here's my class. I start the session in the
constructor and in later methods attempt to register
session variables. You can see I've tried a couple
different methods but none of them maintain the
session variable values. Any suggestions?
Mike
<?php
class login {
//This variable tells the browser where to redirect to
the loginpage
var
$loginPage='http://www.somedomain.com/somepage.php';
var
$exitPage='http://www.somedomain.com/somepage.html';
var $loggedIn;
var $access;
var $accesslevel;
function login($loggedIn, $access, $accesslevel) {
session_start();
if ($loggedIn=='1') {
$this->checkLogin();
}
if ($access=='1') {
$this->checkAccess();
}
if ($access=='0' && $loggedIn=='0') {
$this->authenticateLogin();
}
}
function checkLogin() {
if (session_is_registered('user')!='True') {
session_register('unauthorizedaccess');
$unauthorizedaccess="http://" .
$_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
header("location: $this->loginPage");
exit();
}
}
function checkAccess() {
if (session_is_registered('permission')=='True') {
if
($HTTP_SESSION_VARS['permission']<$this->accesslevel)
{
session_destroy();
header("location: $this->exitPage");
exit();
}
}
else {
session_register('unauthorizedaccess');
$unauthorizedaccess="http://" .
$_SERVER["SERVER_NAME"] . $_SERVER["SCRIPT_NAME"];
header("location: $this->loginPage");
exit();
}
}
function authenticateLogin() {
if ((!$HTTP_POST_VARS['un']) ||
(!$HTTP_POST_VARS['pw'])) {
session_register('loginError');
header("Location: $this->loginPage");
exit();
}
else {
include("includes/db_connect.inc");
//call db_connect function from db_connect.inc
db_connect() or trigger_error("MySQL error #" .
mysql_errno() . ":" . mysql_error());
$query="select * from users where username=\"" .
addslashes($HTTP_POST_VARS['un']) ."\" and
password=\"" . addslashes($HTTP_POST_VARS['pw']) .
"\"";
$result=mysql_query($query) or trigger_error("MySQL
error #" . mysql_errno() . ":" . mysql_error());
$foundCount = mysql_num_rows($result);
if ($foundCount==1) {
session_register('user');
session_register('permission');
session_register('company');
session_unregister('loginError');
for ($i=0; $i < $foundCount; $i++) {
$row=mysql_fetch_array($result);
$_SESSION['user']=$row['userID'];
$_SESSION['permission']=$row['permissionLevel'];
$_SESSION['company']=$row['companyID'];
}
if
(session_is_registered('unauthorizedaccess')=='True')
{
$location=$HTTP_SESSION_VARS['unauthorizedaccess'];
session_unregister('unauthorizedaccess');
header("Location: $location");
exit();
}
}
else {
session_register('loginError');
header("Location: $this->loginPage");
exit();
}
}
}
//closes class
}
?>
--- "CPT John W. Holmes" <[EMAIL PROTECTED]>
wrote:
> From: "micro brew" <[EMAIL PROTECTED]>
> > I've been experimenting with sessions. I can make
> > them work just fine in a normal PHP page. But
> when I
> > create a class and try to define a session
> variable
> > within a method in the class it won't work. I've
> > tried setting the session variable directly
> > ($_SESSION['name']='somevalue') but that didn't
> work.
> > The normal way of setting it -
> > session_start();
> > session_register('name');
> > $name='somevalue';
> >
> > - didn't work either (within the class).
>
> "didn't work" isn't very helpful to us. How useful
> would it be for me to
> just answer you with "it worked" for me.
>
> Show us some code examples (short ones) as to how
> this doesn't work, please.
>
> ---John Holmes...
>
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php