----- Original Message ----- 
From: "j0hncage"
Hi Rob,

Thanks very much for the informative reply.  Really appreciate it.

Added the code below as you suggested to the first form:

<snip>

where form action already existed but did try again using <?php
echo($uzername); ?> as my 'value'.  I even tried placing a link from
page 2 back to 1 directly in hopes those values would autofill for the
two text fields but no such luck.  Is there something else I should do
to return the values?  i.e. place a $passwordd = $_POST['passwordd'];
in that particular code on page 1.  Also am assuming that once the
session/cookie is started on page 1 lines 1 and 2 (<?php on line 1 and
session_start(); on line 2 of the page), nothing else needs to be done
for other pages as, the cookie set in page one holds contents for the
variables until the browser window is closed.  Hope that's not a
faulty assumption.  ;-)

Again, thanks very much.

John
----------------------------
Hello John,
                 Client sessions, server sessions, query strings and cookies 
are all different things even though it is a combination that is used for 
session management.

The short answer to your question is that session_start() is needed at the 
start of every page that you want to access the session registered 
variables.

The process I described is simply storing the Session ID in the cookie and 
the password and username on the server. This is the better way to do this 
as the password is being stored away from prying eyes on the client machine.

The actual cookie variables can be set and read in PHP but this is more 
complex and will fail of course if cookies are disabled.

Here is a rough description of the process that I suggested

The client makes a page request for a page and sends any existing cookie in 
the header of the request and any form data in the body of the request.

The server sees session_start() so it gets the sent cookie (if it exists) 
and looks for an established session. If an established session exists then 
it loads the session environment which includes the session register 
variables from a file that it previously stored.

If no session exists or has expired, then new session environment is 
created. The server then updates the cooking with the new session ID but 
only in the session environment ON THE SERVER, it does not send the cookie 
until it is ready to send the headers.

If there are further header instruction in the script before any actual 
content like header() cookie() then these also are stored in the session 
environment.

On the very first ASCII character (even if it is a space or carriage return) 
that the server has that is NOT header information, the sever will send ALL 
the header information stored in the environment AND the first character.

When the client gets this first part of the page it looks at the header 
first and makes any changes or creates a cookie before is starts with the 
content.

The above will of course only work when cookies are enabled.

If cookies are disabled then session_start() will look for a Session ID in 
the request URL like
mydomain.com/thispage.php?SID=874387r03940
If no session exists or has expired then it creates a new one and appends 
the Session ID into all links on the page that it will send ie -
<a href="mydomain.com/theothepage.php?SID=874387r03940

In either case it is the session ID that is stored in the cookie or URL's on 
the client side and not any server side variables.

The server side variables are store in a separate file on the server. One 
file for each session and the files name is the session ID.

The next part is "What is a session?"

A session starts when the server makes a session ID this session will 
usually time out when it has not been used for half an hour or so, in this 
way there is no permanent storage of information so a datadase is required 
to link authorised individuals to current sessions.

Alternatively, a cookie can hold data long after a session has expired so if 
you need to keep information longer, then cookies can be used even if normal 
sessions using session_start() is used as well but remember some people 
disable cookies so once you specifically use cookies, you must also build a 
fallback system for those who have them disabled.

The code I sent before is a bit rough in that it is not checking to see that 
a user has entered a password.

If you have the HTML -
<form ...
<input type="password" name="passwordd" value="">
 and the following php in the next page

<?php
if(isset($_POST['passwordd'])) ...

the isset will always be TRUE even if the user did not enter anything
It would be better to code -
if(isset($_POST['passwordd'])  && ($_POST['passwordd'] != '' ))

Hope this helps, Rob M.

Reply via email to