asmith Posted November 19, 2007 Share Posted November 19, 2007 this file : <?php session_start(); session_register('count'); $_session[count]++; $msg="u've been here $_session[count]"; ?> <html> <head> <title>start a session</title> </head> <body> <?php echo $msg; ?> </body> </html> do not work , when i load this page , the only thing i get is " you've been here 1" , by refreshing the page that "1" does not change, just 1 again and again , but this file : <?php session_start(); if (isset($_SESSION['count'])) $_SESSION['count']++; else $_SESSION['count'] = 1; $msg="you've been here {$_SESSION['count']} "; ?> <html> <head> <title>start a session count</title> </head> <body> <?php echo $msg; ?> </body> </html> it works by refreshing that number add each time, BUT when i close my brower , and open again , the session won't end, and gives me the last number i was refreshing ! what is wrong with the first file ? and why the second do not end the session when i close it ? Quote Link to comment Share on other sites More sharing options...
trq Posted November 19, 2007 Share Posted November 19, 2007 In the first file your using the non-existant $_session array. There is nothing wrong with your second file. Quote Link to comment Share on other sites More sharing options...
asmith Posted November 19, 2007 Author Share Posted November 19, 2007 so why when i close by browser it won't reset to 1 again ? just continue the last number before closing? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 19, 2007 Share Posted November 19, 2007 You have to unset the session. I mean to destroy after it is not needed anymore session_destroy(); In order to kill the session altogether, like to log the user out, the session id must also be unset. Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 19, 2007 Share Posted November 19, 2007 In my experience it is a browser bug. Sessions should expire when you close your browser but I am able to log in to a lot of different web services, close my browser and still be logged in when I open my browser again. But I might be mistaken You can set the time a session should live. Quote Link to comment Share on other sites More sharing options...
asmith Posted November 19, 2007 Author Share Posted November 19, 2007 i changed that to $_SESSION , now the first works too , but they are connected to each other ,which mean when i open one and close it on number 7 , then i open second , it is already on 7 , then again when i close this one at 17 , and open other, it starts at 17 ... Quote Link to comment Share on other sites More sharing options...
trq Posted November 19, 2007 Share Posted November 19, 2007 Sessions live for a set time, there is no guarentee they will die when a browser closes. What exactly are you trying to do? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 19, 2007 Share Posted November 19, 2007 I think session will expire after 180 minutes session.cache_expire=180 (default) Quote Link to comment Share on other sites More sharing options...
asmith Posted November 19, 2007 Author Share Posted November 19, 2007 i have about 10 pages which should just be veiwed by a registered member , but i want when the user browser is closed the session ends, but before that i was trying with coockie (which didn't worked either ) , now i'm all confused ! the coockie part was this : if ($check != 0) {$auth="<a href=\"a.php\">a page</a>"; SETCOOKIE("abc","bbb",time()+60,"/","127.0.0.1",0); } else {$auth="bad login";} ?> <html> <head> </head> <body> <?php echo $auth; ?> </body </html> and a.php : <?php if ($_COOKIE[abc] == "bbb") {$msg="hello !";} else {header("location: /my2/login.html"); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...... when i sign in , i saw the "a page" link , but when i click on it , it bring up the login page again , which means the he couldn't find abc== bbb, i've checked my brower coockie but all is allowed ! :s now don't know what wouldn't be similar for a session for doing such a thing, and this book hasn't said anything about that ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.