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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variable to new page? 2

Status
Not open for further replies.

stealth71

Programmer
Feb 22, 2005
14
0
0
US
Is there any way to pass variables to a new page without putting all of them in a query string?

I have a large form that the user must fill out. Then I want to move the info into a format easier to read ie. without text boxes and have the user verify this info before it is submitted to the database. I currently have to send all of the data through the query string which is rather huge because on of the fields can be a paragraph long. So is there any way to pass this or reshow it without the querystring?
 
you can use forms. put all the data in hidden fields.

e.g.

on page1
Code:
<form action="page2.php" method="post">
    <input type="text" name="test">
    <input type="submit" value="Go!">
</form>
page2
Code:
<form action="page3.php" method="post">
    <input type="hidden" name="test" value="<?php echo $_POST['test']; ?>">
    ....etc
</form>
this help?


Regards,

Martin

Gaming Help And Info:
 
1. POST with hidden fields
2. Cookies
3. Sessions

I would opt for sessions.
Use session_start() at the top of every page. Assign the values into the superglobal $_SESSION array, e.g. upon receiving the values with POST;
Code:
<?
session_start();
$_SESSION['myVar'] = $_POST['myVar'];
# it is available on any pahe where session_start() is called
 
I think I need to use $_SESSION because my form has:

action="<? echo $_SERVER['PHP_SELF']; ?>"

I do this to check the info in the fields before moving on.

How do you retrieve the info from the SESSION variable on the next page?
 
You just need to call the session_start() at the top of the code and then you have access to the variables in $_SESSION:
Code:
<?php
session_start();
# just show all vars in the session
print_r($_SESSION);
# it is an associative array
echo $_SESSION['myVar'];
?>
 
For security purposes I am wondering when these variables will be erased and where they are stored during the session?
 
The values are stored, by default, on the server's filesystem. Only a cookie containing an index is stored on the user's browser.

And you can erase any session variable at any time. The script:

<?php
session_start();
unset ($_SESSION['foo']);
?>

will erase the session variable 'foo';


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
PHP has a session_max_lifetime. Usually the sessions are stored in small files by the web server (unless a database driven system was created). Files are the default.

The information can only be accessed by the person with the right session_id (which is passed in a cookie) and someone able to read the sessions files in the file system.

There is a garbage cleanup mechanism cleaning out expired sessions. The settings can be seen in the phpinfo() and can also be manipulated by runtime ini_set() commands.
 
Thank You. It's great having such geniuses around to help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top