Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use timeouts in sessions?

Status
Not open for further replies.

bradsteele

Programmer
Oct 19, 2004
24
CA
HI,

I am a newbie to PHP and I am trying to initate a session that will timeout after an extended period of time. Does anyone have any url's or help they can send me to help with this? Also, does clicks within a Authorware Web Player window constitute activity within the browser itself?

Thanks,

Brad
 
I don't under stand php sessions either. I tried this from php.net but it seemed to do nothing.

Code:
/* set the cache limiter to 'private' */

session_cache_limiter('private');
$cache_limiter = session_cache_limiter();

/* set the cache expire to 1 minutes */
session_cache_expire(1);
$cache_expire = session_cache_expire();

/* start the session */

session_start();

It's only easy when you know how.
 
The thing about PHP sessions is that it is very easy to over-analyze them.

At the core:
1. Your script invokes session_start().
2. Your script sets or uses elements of the $_SESSION superglobal array.
3. Any other scripts that invoke session_start() will have the same session variables you have previously set.

There are details about tailoring how long session variables will last -- this is explained in FAQ434-4908.


But to get a handle on sessions is to use them. As an example, take the following set of scripts:

s1.php:
Code:
<?php
session_start();
print '<html><body><pre>Session array at start:
';
print_r ($_SESSION);

$_SESSION['foo'] = 'a';
$_SESSION['bar'] = 'b';

print 'Session array at end:
';
print_r ($_SESSION);

print '</pre><a href="s2.php">click here for next script</a></body></html>';
?>

s2.php:
Code:
<?php
session_start();
print '<html><body><pre>Session array at start:
';
print_r ($_SESSION);

$_SESSION['foo'] = '';
unset($_SESSION['bar']);
$_SESSION['baz'] = 'orange';

print 'Session array at end:
';
print_r ($_SESSION);

print '</pre><a href="s3.php">click here for next script</a></body></html>';
?>

s3.php:
Code:
<?php
session_start();
print '<html><body><pre>Session array at start:
';
print_r ($_SESSION);

$_SESSION['foo'] = '';
unset($_SESSION['bar']);
$_SESSION['baz'] = 'orange';

print 'Session array at end:
';
print_r ($_SESSION);

print '</pre><a href="s3.php">click here for next script</a></body></html>';
?>

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top