----- Original Message -----
From: "John Cage"
I have a simple form used on an at work intranet that really doesn't require
security but I do require 'something' just to help ensure a person using or
making changes, is who they say they are. For example, usually it's just
first, middle and last initials (a couple of people have used presumably
their birth year and so on). These form fields are set up as follows:
<input type="text" name="uzername"> and <input type="password"
name="passwordd"> respectively.
My question. How can I set a session or cookie at the onset of a session
where, in any form where 'uzername' and 'passwordd' is used, those
respective fields will populate with the cookie values only for as long as
the browser is open?
For example, starting in formquery.php (initial input), I use uzername and
passwordd (intentional mis-spell) taking you to formquery2.php (query
result). From there, a user can go to formupdate.php (make db updates) and
then click to formquery.php following that. Not looking for anything to
check for valid uzername & password at this point, just hold values for
convenience.
Thanks very much for any help...
john
-----------------------------
Hello John,
Fortunately this is very simple in PHP.
There is only two traps to watch out for. One is a PHP configuraion
environment vairiable "Register Globals" and it can cause security problems
so it is best dissabled or you should prevent it from causing problems.
The other is that you must NOT send anything from the server, even a space
or carage return before you start the session. This is because the operation
to set a cookie is sent in the headers from the server and the server can
only send the headers once.
for example -
/// file starts on next line
<?php
session_start();
....
will not work because of the blank line before <?php and the server will
send the headers along with the blank line before is starts the session and
as a result the server cannot set the cookie.
PHP also realises when cookies are dissabled and it will append serssion
information to urls in a page for example
<a href=http://mydomain.com/mypage.php?SID=83287383u32h238>
instead of
<a href=http://mydomain.com/mypage.php>
ok - the register globals problem -
If you have a script that says -
<?php
....
if($loggedin == TRUE) {...
then some can write HTML
<form action=...
<input "loggedin" value = "1">
and if Register globals is enabled then they can get loggedin status
To prevent this always clear important varialbes in php
<?php
$loggedin="0";
If($_POST['password'] == $password)
{$loggedin = "1";
.....
Ok back to your question - There are two ways of doing this, one is with
Javascript and I wont go into that, the other is session variables.
<?php
session_start();
if(isset($_POST['uzername']))
{
$uzername = $_POST['uzername'];
session_register($uzername);
}
if(isset($_POST['passwordd']))
{
$passwordd = $_POST['passwordd'];
session_register($passwordd);
}
?>
<html>
....
<form action=....
<input type="text" name="uzername" value="<?php echo($uzername); ?>">
<input type="password" name="passwordd" value="<?php echo($passwordd); ?>">
Hope that helps, Rob.