at login page, i create a new session variable named active $_SESSION['active']=1; PHP: at the following page, i try to call out the sesion variable but failed. <? session_start(); echo $_SESSION['active']; ?> PHP: it is weird. coz last few days the website is running well but now face this kind of problem.... cannot do login event totally... it cannot echo the "1"...the result come out is just empty.... please help me....thanks........
I don't really see what's the problem.. It shouldn't be anything, should it? Sessions isn't actually for echoing.. If you want to print a "1" use variables instead? This is how you could do it with sessions:
Not quiet sure what you mean here Xariov... You can use session variables for anything you like and are especially useful for echoing their values, such as the logged in user's real name for example.
Xariov - OK, I see what you were trying to say now chxxangie - Check that you have session_start() at the top of the page you set $_SESSION["active"] to 1 - it probably is but you didn't show it on your code snippets Has you service provider upgraded the server with a newer version of PHP or changed the default values?
ya, i'd already put session_start() at the top of the page. but the problem is still there. i'm using phpdev423. before today... all is running well. but now, the session active variable cannot pass to other pages.
Are all other session variables working? Have you tested to see if you can set another session variable and see if that passes to the next page?
login.php page <?php session_start(); $_SESSION['active']=1; ?> <script type="text/javascript"> window.location="choose.php" </script> <? PHP: choose.php page <? session_start(); echo "current session is: ".$_SESSION['active']; if(!$_SESSION){ ?> <SCRIPT LANGUAGE="Javascript"> window.location = "login.php"; </SCRIPT> <?php exit; } ?> PHP: any problem of above code? or is there anyway can replace the session so that i can pass the variable among pages?
The script looks fine, it worked for me. Is it all session variables that don't work, do you set others and can you test them by echoing them to the screen?
ya...all variable don't work... i'd tried to create new session and echo to screen but session value is empty... i don't know what had happened? infected of virus??? but is it the virus is so clever to infect only the session??? or because of the localhost program? may be...coz i'd tried to upload the files to server, session is works.
no...i never do that. i use phpdev currently...and when i tried to use Wamp server, more problem arised... really make me headache...