I am having trouble using session variables with Class functions and I have trawled the documentation and faq lists and I just can't find a solution.
I am trying to set up a global class for a community site that would allow a member to link from their own site to the community and then dynamically generate their content. This content wold be across several pages so I figured the best way to do this would be to take a user reference querystring and assign a session variable that would then be used to figure out what content to get on subsequent page requests.
Here is what index.php looks like...
------------------------------------------------------------------------------
Code: Select all
<?
Class CGlobal
{
function CGlobal()
{
global $HTTP_GET_VARS;
session_start();
if (isset($HTTP_GET_VARSї'user']))
{
session_register('USER');
$HTTP_SESSION_VARSї'USER'] = $HTTP_GET_VARSї'user'];
}
}
function initPage()
{
global $HTTP_SESSION_VARS;
echo session_id();
echo '<br>session_is_registered(USER) = '. session_is_registered('USER');
echo '<br>count($HTTP_SESSION_VARS) = '. count($HTTP_SESSION_VARS);
if (isset($HTTP_SESSION_VARSї'USER']))
{
echo $HTTP_SESSION_VARSї'USER'];
}
}
}
$global = new CGlobal;
?>
<html>
<head></head>
<body>
<p><b>index.php</b></p>
<p><a href="index.php?user=a1">Add user</a></p>
<?
$global->initPage();
?>
<br><br>
<p><a href="index.php">index</a> | <a href="page1.php">page1</a></p>
</body>
</html>And another page, page1.php
---------------------------------------------------------------------------
Code: Select all
<?
Class CGlobal
{
function CGlobal()
{
global $HTTP_GET_VARS, $HTTP_SESSION_VARS;
session_start();
if (isset($HTTP_GET_VARSї'user']))
{
session_register('USER');
$HTTP_SESSION_VARSї'USER'] = $HTTP_GET_VARSї'user'];
}
}
function initPage()
{
global $HTTP_SESSION_VARS;
echo session_id();
echo '<br>session_is_registered(USER) = '. session_is_registered('USER');
echo '<br>count($HTTP_SESSION_VARS) = '. count($HTTP_SESSION_VARS);
if (isset($HTTP_SESSION_VARSї'USER']))
{
echo $HTTP_SESSION_VARSї'USER'];
}
}
}
$global = new CGlobal;
?>
<html>
<head></head>
<body>
<p><b>page1.php</b></p>
<p><a href="index.php?user=a1">Add user</a></p>
<?
$global->initPage();
?>
<br><br>
<p><a href="index.php">index</a> | <a href="page1.php">page1</a></p>
</body>
</html>If you click the Add user link it will register the $HTTP_SESSION_VARS['USER'] when the CGlobal class initiates, however it is not available in the initPage() function. The strange thing, for me at least, is that the session_is_registered() function returns true but the array count of $HTTP_SESSION_VARS returns 0.
This is being used with the cgi version of PHP on IIS/win2k.
Got any ideas?
Thx in advance.