/    Sign up×
Community /Pin to ProfileBookmark

maintaining state

could someone show me some code that they use to keep track of a person — I’m playing around with sessions, however once the browser is clossed the person looses the sessionID. I want to be able to keep that ID even after the browser closes. I guess I could just set a cookie manually, but I was hoping that there would be something I can do with start_session() to make it more sticky.

How do you achieve this?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsOct 06.2004 — you can control the "lifetime" of a session with session_cache_expire([int new_cache_expire]), you must call session_cache_expire() before every call to session_start()
Copy linkTweet thisAlerts:
@silent11authorOct 06.2004 — That is what I thought. Why then does this page give me a different sessionID after I

1) open a browser, close it, then

2) open it up again?

[code=php]
<?php
session_cache_expire(60*24*31);
$cache_expire = session_cache_expire();


session_start();
header("Cache-control: private");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP Sessions</title>
</head>
<body>

<?php echo session_id(); ?>

</body>
</html>

[/code]
Copy linkTweet thisAlerts:
@ShrineDesignsOct 06.2004 — because you are not telling it to load a session, example:[code=php]if(isset($_REQUEST['PHPSESSID']))
{
session_start($_REQUEST['PHPSESSID']);
}
else
{
session_start();
}[/code]
Copy linkTweet thisAlerts:
@silent11authorOct 07.2004 — Thanks!
×

Success!

Help @silent11 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...