iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
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

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-27-2004, 12:45 AM
WebProWorld Pro
 
Join Date: Jul 2003
Location: Canada
Posts: 272
ackerley1 RepRank 0
Default Creating Session and passing variables?

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
Reply With Quote
  #2 (permalink)  
Old 08-29-2004, 06:46 AM
WebProWorld Member
 
Join Date: Jul 2003
Location: England
Posts: 33
brettgodfrey RepRank 0
Default Creating Session and passing variables?

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>
form3.php
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>
__________________
Brett

www.godfreyhart.com
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:32 PM.



Search Engine Optimization by vBSEO 3.3.0