Re: Session management

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Friday, October 22, 2004, 4:10:50 PM, you wrote:
HS> Hi

HS> I am a PHP newbie from a Java/C/Oracle background. I
HS> cannot seem to get session management with PHP
HS> working.

HS> <?php

HS>   #echo 1;

HS>   $old = ini_set('session.use_cookies', 0);

HS>   session_start();
HS>   $username = $_REQUEST["username"];
HS>   session_register($username);

HS>   echo "old=".$old;

HS>   echo $username;

HS>   include_once("db_security.inc");

HS>   echo "PHPSESSID=".$PHPSESSID."\n";


HS>   $Postfrom = $_REQUEST["username"];
HS>   $Postpass = $_REQUEST["password"];


HS>   if (__user_authenticate($Postfrom,$Postpass))
HS>   {
HS>     $display = '>>Welcome '.$Postfrom.' !';

HS>     echo '<a href="ht_next.php">Next</a>';

HS>     echo $display;
HS>   } else {
HS>     echo "Login Failed!";
HS>   }

?>>


HS> In ht_next.php I have:

HS> <?php


HS>   session_start();
  
HS>   echo $username;


?>>


HS> $username seems to be empty at this point. 

HS> echo "PHPSESSID=".$PHPSESSID."\n";

HS> in the first script does not produce any output
HS> either. 


It is best to use
session_start();
.
.//get username
.
$_SESSION['username'] = $username;

then on the next page

session_start();
echo (isset($_SESSION['username']))? $_SESSION['username'] : 'Not in session';

PHP does not fill global variables by default.

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux