Jump to content

2 session php files


asmith

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/77915-2-session-php-files/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/77915-2-session-php-files/#findComment-394370
Share on other sites

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 ! :(

 

Link to comment
https://forums.phpfreaks.com/topic/77915-2-session-php-files/#findComment-394377
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.