Sunday, June 18, 2006

Session in PHP

Hmm... whole day of today, I've been playing with the session using PHP. As many of us know that Session handling in ASP.NET using the Microsoft Visual Studio .NET environment was pretty easy as it has a file which you can declare your session variables, and application level variables. In php, it doesn't offer such functions. Thus, all you have to do is create an extra php file and import to every page of your web applications. I was having problem to declaring the Session and retrieve the values from the session variables in the php pages. Hence, I decided to google around and it suggested me to do as below:


auth.php
<?php
session_start(); //start session when your auto_start_session is 0 (off) in your php.ini
session_register($auth); //register global variable 'auth' into session variable
session_register($username); //register username as session variable too.
?>


Well, when I try to access the variable in another page, it does appears to be null. So where have I gone wrong?

0 comments: