...

View Full Version : Session and Register Global off in PHP 4.3.0



hkucsis
03-13-2003, 10:43 AM
Hi,

I am developing web with PHP 4.3.0 under win2k environment. I set register_globals = off.

Now I have two simple pages.

====Session.php=======
<?
$_SESSION["user_name"] = "michael" ;

if (isset($_SESSION["user_name"]))
{
echo "User name:" . $_SESSION["user_name"] ;
}
else
{
echo "User name not set." ;
}
?>

====Session2.php=======
<?
if (isset($_SESSION["user_name"]))
{
echo "User name:" . $_SESSION["user_name"] ;
}
else
{
echo "User name not set." ;
}
?>

I visit session.php, then session2.php.

I got "User name:michael" in session.php but "User name not set." in session2.php.

I expect the $_SESSION["user_name"] should be available in both pages...

What's the problem?

Thanks in advance.

Spookster
03-13-2003, 10:58 AM
That's not quite how sessions work in PHP. Here is a tutorial that explains the use of sessions:

http://hotwired.lycos.com/webmonkey/00/05/index2a_page6.html?tw=programming

Spookster
03-13-2003, 11:06 AM
Here's another one:

http://www.zend.com/zend/tut/session.php

Íkii
03-13-2003, 12:29 PM
those are very OLD tutorials spooks, too old for reg_globals = off

session_register is now defunct

hkucsus - you session calls are fine - exactly the same as I use in PHP4.2.3 with one exception

start every (I mean every) script with

session_start();

If that doesn't do the trick, check your session support in php.ini or php info

Spookster
03-13-2003, 05:35 PM
You got something against things that are old? :p Yeah ok time to update my list of bookmarks. lol Here is a more current one:

http://www.free2code.net/tutorials/other/20/sessions.php

hkucsis
03-14-2003, 09:47 AM
Thanks you guys.

Problem solved -- I missed 'session_start()'.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum