PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Now I have had the cookie questions solved I have discovered a problem getting the values from a "session", the problem I have here is getting the value from "the cookie" after a session has been set, the book tells me:
Code
$display="Employee Name : $name";
but now "I guess with the register_globals changes" this does not work so I tried the following:
<?php
$display="<PRE>
Employee Name : $_SESSION[name]<br></br>
Department : $_SESSION[dept]<br></br>
Pay Grade : $_SESSION[pay_grade]<br></br>
Location : $_SESSION[location]<br></br>
Home Address : $_GET[address]<br></br>
Telephone : $_GET[telephone]<br></br>
Employee ID : $_SESSION[employee_no]<br></br></pre>";
?>
but "$_SESSION[variable]" does not seem to return a value, I understand from the documentation at php.net that this seems to be the way to get the value from a session variable!
There are three files to this example, the variables above that I have used $_SESSION on are variables set with the first page of the form then the ones I have used GET on are the variabled set with the 2nd form/page "Which return there values OK", the code above is taken from the 3rd form which returns the values set for the session with forms 1 and 2. I have also tried "$_COOKIE" just in case but there is no value returned there either. I hope this is clear enough to be understood!
OK, it appears you are a little confused on how sessions work.
The general format of using sessions is to:
Step 1: Create the data input forms which use either GET/POST
Step 2: Process the GET/POST data
Step 3: Stored the process and selected data into a session
Step 4: Retrieve session data on later pages
So what does this mean for you, I'm going to walk through the pages quickly. Let me know if this doesn't provide enough information to get started:
Page 1: ss1.php, you can remove all the session stuff
Page 2: add lines like $_SESSION["name"]=$_GET["name"]; to register the passed variables. You'' want to keep the session_start() a the first line. If you want to do any error checking on the form inputs, do that before you save teh GET values to SESSION. What this will do for you is basically avoid the need to use hidden form fields to pass ss1.php's data to ss3.php via ss2.php. You can also remove the session_register("address","telephone") line from ss2.php.
Page 3: so telephone and address are still in teh GET array, the other values are in SESSION. You can move teh GET variables to SESSION if needed as shown in page 2, or just use the appropriate array when you need the data.
OK, I will try and get my head around this and then come back.
by the way, this is not my way of creating this process, this is an example from a book on dynamic web sites with php and MySQL that I am using to learn how to use php and MySQL, so it is an exercise on showing the reader how the session thing works.
I think I understand this a little better now, the changes you told me to make gave me the results with ss3.php that where expected. I have pasted the revised code below, I take it I can add variables to the "session" from another page using $_SESSION ? this I will try. There is one thing I noticed and that is when the "Submit" is pressed on ss2.php it takes as much as 60m seconds for ss3.php to load and that is from localhost, is this not a long time for what appears to be a simple process?
Hmm I don't see anything that would cause that type of slow-down. Maybe your computer is a little slow to do the mail-ing and the server isn't pushing the html through to the client until the script ends.
I do wonder why you are storing the sessionid as an employee number. The sessionid generated by php will not be a consistent/good numbering scheme for use within the employee database. You should also make sure to always single or double quote the names of the variables in the GET/SESSION arrays. I noticed that you did most of the time, but missed it a few times. (If you develop with notice level error reporting on, PHP will alert you to these.)
I commented out the mailing and now ss3.php loads instantly.
I stored the session as the employee_id only because it does this in the book, it is only an exercise to learn php.
OK, I was a little confused with the quoting thing, I did a couple of scripts that seemed to have problems when I quoted the variables so I removed them when I was having these problems although at the end of the day they where probably nothing to do with the problem. I wasn't sure if they where to be used as single, double, when getting values with GET and maybe not with COOKIE but I think I am starting to understand quoting a little better now, the book I am using does not use them but from a couple of comments I have had from other users I now understand it is best to use them.