Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 30th, 2003, 11:29 AM
Registered User
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Empier4552
Default Help! My Sessions arent working

hey basically im trying to get a session started with several variables being registered, first it queries a database and gets values from it. Now i have tested this out and the values are all brought out and echoed out when i tell it to, but then when i make a session, i echo out the session ID fine...Then however I try to echo out the session variables and none come, ive made sesion variables from others in the database.

/Starting the Session
    //If no session id register the following.
    if (!PHPSESSID) {

//if session Id but no values register the following
    } else if ((!$ipin) || (!$iauth) || (!$ipassword) || (!$ilvl)){


//Authorization is GRANTED
$auth = "true";
if (!$ilvl) {
$ilvl = $lvl;
if (!$ipassword) {
        $ipassword = $epassword;
if (!$ipin) {
    $ipin = $epin;
    if (!$iauth) {
    $iauth = $auth;

$auth, $epassword, $lvl, and $epin are all taken from the database and have actual values, but when i tel $iauth to = $auth for instance, i add an echo later on to show me $iauth and nothign comes up, whats wrong?
Old July 1st, 2003, 04:13 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo

remember that if you want to refer to session variables you have to use $HTTP_SESSION_VARS or $_SESSION array. if you want to assign a value to session variable do this:

$HTTP_SESSION_VARS["myvar"] = "myvalue";

echo $_SESSION["myvar"]; // prints out 'myvalue';

and another thing is that if you want to check whether session variables are registered use session_is_registered('variablename') or try isset() function:

if(isset($HTTP_SESSION_VARS["index"])) blablablabl ....

hope that helped ....

the genuine genius
Old July 9th, 2003, 03:24 PM
richard.york's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

You don't *have* to use $_SESSION or $HTTP_SESSION_VARS but its a good idea if you do. What Moharo is getting at is PHP used to have a register globals functionality that made all variables from all sources available in global context without referring to its respective method. As of one of the version 4 point upgrades this functionality was deprecated and consequently was turned off by default in the php.ini file. So many of the text books that came out at the time that used global variables in their scripts became outdated. This was decided for security reasons by the PHP group. Now in order to use a variable that is not defined exclusively within the running of a script, like post or session data must be accessed by special variable arrays. You can turn the register_globals back on in php.ini by modifying the line to register_globals=On.

What's good about $_SESSION, $_POST, $_COOKIE, $_GET, $_REQUEST, $_SERVER etc. Is these are super-global variables. Which means that they can be accessed within any variable scope. Inside of functions, classes, etc. The super-globals with an underscore in front are the only available in this scope, the old names like $HTTP_SESSION_VARS are only available in regular variable scope. Meaning you would have to pass these to a function in order for them to be available within a function.

I hope that elaborates on why you were getting the behavior you were getting. I also noticed some syntax errors in your script. Your left off a dollar sign in a the $PHPSESSID variable.

Theres more information on variable scope at php.net.

: )

Smiling Souls

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sessions come and go Surre ASP.NET 1.0 and 1.1 Professional 2 April 10th, 2006 05:55 AM
passing through sessions not working dmlocke PHP Databases 2 April 26th, 2005 08:21 AM
sessions p2ptolu Classic ASP Components 3 March 17th, 2005 06:31 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
Mixing classic ASP sessions with ASP.NET sessions scorpion_king General .NET 2 August 4th, 2004 08:20 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.