...

View Full Version : Help creating a login variable



chornbeck
02-17-2006, 08:05 PM
Need a little direction here.. Basically, what I'm trying to do is:

1. Have people log in to my website using a login page with an ID# (which they already know>

2. The ID# needs to be stored as a variable for use on the following page, where it will be included as a hidden field in a form the person will be submitting for inclusion in a MySQL DB

3. This whole thing will be hosted on a kiosk, so I need two things to happen. The variable needs to be reset (cleared, whatever..) on a certain inactivity timeout period, or at the completion of the session (which will be activited by clicking an "exit" button).


I'm pretty well versed in PHP, HTML, etc., it's more a matter of figuring out the best way to store this variable for later use, and then having it reset at a certain point so the next user can start from scratch. Any help in the right direction is greatly appreciated!!!

goughy000
02-18-2006, 11:07 AM
Sessions

http://uk2.php.net/manual/en/function.session-start.php

example code..

index.php


<?php
// Start session before any output!
session_start();

// Define session variables
$_SESSION[colour] = "red";
$_SESSION[object] = "book";

?>

<html>
<body>
<a href="page2.php">GO!</a>
</body>
</html>


page2.php


<?php

// Start, well "resume", the session (before any output)
session_start();

// Session variables not defined on this page but carried over from last page
echo "oh look a $_SESSION[colour] $_SESSION[object]";

?>


And to end the session....


<?php
// Load session
session_start();

// Kill session
session_destroy();
?>


EDIT:
Also adding to that...
http://uk2.php.net/manual/en/function.session-cache-expire.php

Calling this code BEFORE session_start(); you can set how long the session should last (in minutes) before being ended... I think you would either be able to put this on every page to update it to say.. 30mins.. every new page, or just on the first page. But you might have to call it on every page, never used it before



session_cache_expire(30);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum