Manual => http://www.php.net/manual/en/ref.session.php
The function session_start(); must be executed prior to any headers sent on
any script you wish to call the session variables into. Typically you would
simply put session_start(); as the first line of each page. So..
----------------------------------
<? // page1.php
session_start();
$myvar = 'hello world';
session_register('myvar');
?>
<a href="page2.php">Page 2</a>
-------------------------------------
<? // page2.php
session_start();
// .. with registered globals ON
echo $myvar;
// .. or with reg globals OFF and before v4.1
echo $HTTP_SESSION_VARS['myvar'];
// .. or with reg globals OFF and after v4.1
echo $_SESSION['myvar'];
?>
------------------------------------
Hope this helps.
-Kevin
----- Original Message -----
From: "Jas" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 13, 2002 12:13 PM
Subject: [PHP] session problems...
> Ok I think I am a little confused as to if this is working or not: I have
> commented in the places where I am confused... if someone could please
point
> out why the variables "u_name & p_word" are not being registered that
would
> help me out a ton... thanks in advance,
> Jas
> --- Form to log user in ---
> <form name="auth" method="post" action="auth_done.php">
> <input type="text" name="u_name"><br>
> <input type="password" name="p_word"><br>
> <input type="submit" name="login" value="login">
> </form>
> --- checks db to see if user exists ---
> <?php
> if ((!$u_name) || (!$p_word)) {
> header ("Location: index.php");
> exit;
> }
> $db_name = "bignicke";
> $table_name = "auth_users";
> $connection = @mysql_connect("localhost","user","password") or die("Could
> not connect to Database, please try again later");
> $db = @mysql_select_db($db_name, $connection) or die("Could not select
> Database, please try again later");
> $sql = "SELECT * from $table_name WHERE un = \"$u_name\" AND pw =
> password(\"$p_word\")";
> $result = @mysql_query($sql,$connection) or die("Couldn't execute
query");
> $num = mysql_numrows($result);
> if ($num !=0) {
> $msg = "<p class=\"content\">You have been authorized to make changes to
> the web site.</p>";
> session_start();
> #session_register(u_name); //cant tell if this has been registered with
a
> print statement
> #session_register(p_word); //can't tell if this is either
> $_session['u_name'] = $u_name; //this must be wrong too
> $_session['p_word'] = $p_word; //still wont register session variables
> } else {
> header ('Location: index.php');
> exit;
> }
> ?>
> <body bgcolor="#FFFFFF" text="#000000">
> <?php
> echo $msg;
> print (SESSION_ID()); // the session is working right here
> print ($_SESSION['u_name']); // this will not print the registered
variable
> print ($_SESSION['p_word']); // this is not printing the registered
> variable either
> print ($u_name); // this works
> print ($p_word); // this works
> print (session_is_registered('u_name')); // this won't work
> print (session_is_registered('p_word')); // this isnt working either
> ?>
> <br>
> <a href="edit.php">edit more pages</a>
> </body>
> --- page to see if variables are being passed to edit page ---
> <?php
> session_start();
> $_session['u_name'] = $u_name; //should be registering username
> $_session['p_word'] = $p_word; //should be registering password
> ?>
> <body bgcolor="#FFFFFF" text="#000000">
> success?
> <?php
> print ($_SESSION['u_name']); //does not print the variables
> print ($_SESSION['p_word']); //this doesn't either
> print (session_is_registered('u_name')); //this says variables are set
> print (session_is_registered('p_word')); //this also says variables are
set
> ?>
> </body>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php