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
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
Share on other sites

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 ...

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.