php 4.3.3 & Classes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NoReason
Forum Commoner
Posts: 51
Joined: Tue Sep 10, 2002 6:19 pm

php 4.3.3 & Classes

Post 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);
}
NoReason
Forum Commoner
Posts: 51
Joined: Tue Sep 10, 2002 6:19 pm

Post 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.
NoReason
Forum Commoner
Posts: 51
Joined: Tue Sep 10, 2002 6:19 pm

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
NoReason
Forum Commoner
Posts: 51
Joined: Tue Sep 10, 2002 6:19 pm

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and what does the class UserData look like?
NoReason
Forum Commoner
Posts: 51
Joined: Tue Sep 10, 2002 6:19 pm

Post 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();
	}
}
?>
NoReason
Forum Commoner
Posts: 51
Joined: Tue Sep 10, 2002 6:19 pm

Post 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*/
NoReason
Forum Commoner
Posts: 51
Joined: Tue Sep 10, 2002 6:19 pm

Post 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.
Post Reply