Session missing in passing thru pages

A

Anonymous

Guest
Dear all,

In my project, a login page is set as index.php which check the login user and creat appropiate session for various user by :

session_start;
:
check user statements
:
$super = $username;
session_register("super");

then the page jump to next page and so on, the sessionID is passed thru quite smoothly.

But the session lost when I try to made insertion or updating database when it pass to a html form. I have code the necessary codes for using the session but whatever I do, I check the session string is empty !!

How can I fix the problem ?



With regards,

Ransome :cry:
 
At each page you do:
Code:
<?PHP
session_start();
if (!session_is_registered("super")) {
Sorry you not registered :^(
}
 
WiZARD said:
At each page you do:
Code:
<?PHP
session_start();
if (!session_is_registered("super")) {
Sorry you not registered :^(
}

Dear WiZARD,

How can I do after checking whether the session is registered or not :

say not:

Do I code that :

if (!session_is_registered("super"))
{
global $super;
$super = $username;
session_register("super");
}


Will the sessionID generated is the same as the sessionID I registered before ?




With regards,


Ransome
 
How about this?
Code:
session_start();

function GetSession($parameter_name)
{
    global $HTTP_SESSION_VARS;
    return isset($HTTP_SESSION_VARS[$parameter_name]) ? $HTTP_SESSION_VARS[$parameter_name] : "";
}

function SetSession($param_name, $param_value)
{
  global ${$param_name};
  if(session_is_registered($param_name)) 
    session_unregister($param_name);
  ${$param_name} = $param_value;
  session_register($param_name);
}
if (!GetSession("User")) {
SetSession("User", "super");
SetSession("Rights", "none");
}

From worked project.....
 
using the $_SESSION array would be an easier to understand and less complex way to do it.

Translated code.
Code:
session_start(); 

function GetSession($parameter_name) 
{ 

    return isset($_SESSION[$parameter_name]) ? $_SESSION[$parameter_name] : ""; 
} 

function SetSession($param_name, $param_value) 
{ 
 if(!isset($_SESSION[$param_name]))
    $_SESSION[$param_name] = $param_value;
} 
if (!GetSession("User")) { 
SetSession("User", "super"); 
SetSession("Rights", "none"); 
}

notice the SetSession is much more readable. and since the $_SESSION is a global array it will act just like other arrays and you will not have to make a global command which is something I always forget to do. Just one note. in order to use this method you must be using PHP 4.1 or later.
 
I know what this code work under PHP 4.1.x and later...
P.S. Some program may be fat but work faster......
Some instructions of PHP work faster but if you programming this, you need more typing code :wink: :?
 
Back
Top