Page 1 of 1
php 4.3.3 & Classes
Posted: Tue Aug 26, 2003 12:06 pm
by NoReason
I have just upgraded to using php 4.3.3, now the installation whent fine, no issues there.. setup my ini file again with everything i had before..
But now during authentication, it sets the session fine, creates a new user class fine, populates the class variables ... But it will NOT run the setuserdata() function I have as the final part of teh auth proccess .. I continues to indicate;
PHP Fatal error: Call to undefined function: setuserdata() in \path\to\include
oh as a note I am running this class function from within the authentication function.
auth(user,pass)
{
$_SESSION['UserData']->SetUserData(stuff,morestuff,foo);
}
Posted: Tue Aug 26, 2003 12:43 pm
by NoReason
Followup on this..
I have just created a test page in hopes that for whatever reason teh class function didnt like being run from a another funtion..
Well it gave me the same error after I created a test page with only class function trying to run...
Im stumped.
Posted: Tue Aug 26, 2003 12:59 pm
by NoReason
ok .. now.. if I call the function like so;
$_SESSION['UserData']->SetUserData('blah','1234','6789');
it doesnt work (although it did before 4.3.3)
but if i do it thusly;
$UserData->SetUserData('blah','1234','6789');
echo serialize($_SESSION['UserData']);
var_dump($UserData);
it works.
Posted: Tue Aug 26, 2003 1:00 pm
by volka
does this (not so useful) example work?
Code: Select all
<?php
class UserData
{
var $timeLogin;
function setLoginTime($unixtime)
{
$this->timeLogin = $unixtime;
}
function getLoginTime()
{
return $this->timeLogin;
}
function getFormatLoginTime($formatDate)
{
return date($formatDate, $this->timeLogin);
}
}
session_start();
?>
<html>
<body>
<span style="border: 1px solid grey; display: block">
<?php
if (!isset($_SESSION['UserData']))
{
$_SESSION['UserData'] = new UserData;
$_SESSION['UserData']->setLoginTime(time());
echo 'new login';
}
else
echo 'logged in: ', $_SESSION['UserData']->getFormatLoginTime('F j, Y, g:i a');
?>
</span>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>">reload page</a>
</body>
</html>
Posted: Tue Aug 26, 2003 1:10 pm
by NoReason
Code: Select all
<?php
function Authorize($Username, $Password)
{
$IsTrue = true;
if( isset($Username) && isset($Password) )
{
$QueryString = "
SELECT AccountItemUsername,AccountItemPassword,ItemID
FROM AccountItemDescriptors_PersonItemDemographics
WHERE AccountItemUsername = '$Username' AND AccountItemPassword = '$Password'
";
$SqlQuery = new SqlQuery;
$Results = $SqlQuery->ExecuteQuery($QueryString);
unset($SqlQuery);
}
else
$Results = false;
if( !$Results )
{
$IsTrue = false;
unset($_SESSION['UserData']);
}
else
{
$_SESSION['UserData'] ->Categories = GetAllCategories($Results['ItemID'][0]);
if( array_search(SERVICE_HYDRA,$_SESSION['UserData'] ->Categories) )
{
$_SESSION['UserData']->SetUserData($Results['AccountItemUsername'][0], $Results['ItemID'][0], session_id());
$_SESSION['UserData']->CurrentPage = "welcome.php";
}
else
{
unset($_POST);
echo '<SCRIPT LANGUAGE="JavaScript">alert("You do not have access to this service (HYRDA)");</SCRIPT>';
}
}
return $IsTrue;
}function Authorize($Username, $Password)
{
$IsTrue = true;
if( isset($Username) && isset($Password) )
{
$QueryString = "
SELECT AccountItemUsername,AccountItemPassword,ItemID
FROM AccountItemDescriptors_PersonItemDemographics
WHERE AccountItemUsername = '$Username' AND AccountItemPassword = '$Password'
";
$SqlQuery = new SqlQuery;
$Results = $SqlQuery->ExecuteQuery($QueryString);
unset($SqlQuery);
}
else
$Results = false;
if( !$Results )
{
$IsTrue = false;
unset($_SESSION['UserData']);
}
else
{
$_SESSION['UserData'] ->Categories = GetAllCategories($Results['ItemID'][0]);
if( array_search(SERVICE_HYDRA,$_SESSION['UserData'] ->Categories) )
{
$_SESSION['UserData']->SetUserData($Results['AccountItemUsername'][0], $Results['ItemID'][0], session_id());
$_SESSION['UserData']->CurrentPage = "welcome.php";
}
else
{
unset($_POST);
echo '<SCRIPT LANGUAGE="JavaScript">alert("You do not have access to this service (HYRDA)");</SCRIPT>';
}
}
return $IsTrue;
}
if( !isset($UserData) )
$UserData = new UserData;
session_start();
session_register("UserData");
if( empty($_SESSION['UserData']->SessionID) )
{
if( !Authorize($_POST['Username'], $_POST['Password']) )
$_SESSION['UserData']->CurrentPage = "login.php";
}
?>
It failes in teh auth function.
Posted: Tue Aug 26, 2003 2:11 pm
by volka
and what does the class UserData look like?
Posted: Tue Aug 26, 2003 2:16 pm
by NoReason
Code: Select all
<?php
class UserData
{
var $Username;
var $UserID;
var $SessionID;
var $LoginTime;
var $BrowsingClient;
var $Transactions;
var $CurrentPage;
var $Errors_Alerts;
var $Categories;
var $Security;
function UserData()
{
$this->Username = '';
$this->UserID = 0;
$this->SessionID = '';
$this->LoginTime = '';
$this->BrowsingClient = '';
$this->Transactions = array();
$this->CurrentPage = '';
$this->Errors_Alerts = '';
$this->Categories = array();
$this->Security = array();
}
function SetUserData($Username, $UserID, $SessionID)
{
$this->Username = $Username;
$this->UserID = $UserID;
$this->SessionID = $SessionID;
$this->LoginTime = date('m/d/y H:i:s');
}
function DestroyUserData()
{
$this->UserData();
}
}
?>
Posted: Tue Aug 26, 2003 2:52 pm
by NoReason
Code: Select all
<?php
if( !isset($UserData) )
$UserData = new UserData;
session_start();
session_register("UserData");
?>
ok .. From what I can tell the class is being instantiated(sp?), but when registered it is turning into an array.
var_dump($_SESSION);
results in;
array(1) { ["UserData"]=> NULL }
expected is
object(userdata)(10)/*snip*/
Posted: Tue Aug 26, 2003 3:08 pm
by NoReason
session_start();
session_register("UserData");
if( !isset($_SESSION['UserData']->SessionID) )
$_SESSION['UserData'] = new UserData;
Odd ... that fixed it..
But I swear the way I had it before worked just fine.