|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I am trying to set up a multi page form using sessions (PHP) and it appears that I am missing something in my code.
I have the session_start(); function called and from what I have read that is essentially all I need- or so I gather from the books. I want to send it without cookies (no lecture on security please) by adding it to the URL. I have about 20 variables to pass from each page. Do I need to declare/register these with the session? Do I need to name the session (session_name(); )? Any help please? Rob
__________________
Rob |
|
|||
|
Hi Rob
You need to register each session variable. Below is a simple multi-part form using session varaibles. I hope it is of help. form1.php Code:
<?
session_start();
session_register('s_fname','s_lname','s_house','s_street','s_city');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>Form Part 1</title>
</head>
<body>
Please Enter Your Name</p>
<form name="form1" method="post" action="form2.php">
First Name
<input name="f_fname" type="text" id="f_fname">
</p>
Last Name
<input name="f_lname" type="text" id="f_lname">
</p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
form2.php Code:
<?
session_start();
//with PHP register_globals off you MUST use
$_SESSION['s_fname']=$_POST['f_fname'];
$_SESSION['s_lname']=$_POST['f_lname'];
//with PHP register_globals on you can also use
//$s_fname=$f_fname;
//$s_lname=$f_lname;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>Form Part 2</title>
</head>
<body>
Please Enter Your Address</p>
<form name="form2" method="post" action="form3.php">
House
<input name="f_house" type="text" id="f_house">
</p>
Street
<input name="f_street" type="text" id="f_street">
</p>
City
<input name="f_city" type="text" id="f_city">
</p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</p>
</body>
</html>
Code:
<? session_start(); //with PHP register_globals off you MUST use $_SESSION['s_house']=$_POST['f_house']; $_SESSION['s_street']=$_POST['f_street']; $_SESSION['s_city']=$_POST['f_city']; //with PHP register_globals on you can also use //$s_housee=$f_house; //$s_street=$f_street; //$s_city=$f_city; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Form Part 3</title> </head> <body> Your Name and Address</p> <? echo $_SESSION['s_fname']." "; echo $_SESSION['s_lname']." "; echo $_SESSION['s_house']." "; echo $_SESSION['s_street']." "; echo $_SESSION['s_city']." "; ?> </body> </html> |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |