Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1651 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Passing variables to multiple pages

Thread title: Passing variables to multiple pages
Closed Thread    
    Thread tools Search this thread Display Modes  
07-10-2007, 07:12 PM
#1
majorglory is offline majorglory
Status: Senior Member
Join date: Jun 2006
Location:
Expertise:
Software:
 
Posts: 848
iTrader: 10 / 100%
 

majorglory is on a distinguished road

  Old  Passing variables to multiple pages

Hey guys,
I'm having a bit of a problem with sending variables across two+ pages.

My first page (the form) is where the user inputs their information.

Page two is where $variable=$_POST['variable'] and echo "You have said $variable";

Page three is where I'm having trouble.
I want page three to also have the echo "You have said $variable"; along with another form.

Page four then gathers all the $variables then INSERTs INTO database VALUES.

Doesn't make sense? I made a picture that may make more sense. I hope the text isn't too small

Attached Images
File Type: gif php problem.GIF (10.1 KB, 14 views)

07-10-2007, 07:37 PM
#2
derek lapp is offline derek lapp
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
 
Posts: 2,246
iTrader: 0 / 0%
 

derek lapp is on a distinguished road

  Old

you need to use sessions.

put session_start() at the start of every page, and define $_SESSION['variable'] as $_POST['variable'], instead of just $variable.

here's a dummy example i just set up to get ie6 treating session variables properly:

index.php
PHP Code:
<?
session_start
();
$_SESSION['product1'] = 'sonic screwdriver';
$_SESSION['product2'] = 'HAL 2000';
echo 
'<a href="page2.php">The products have been registered</a>';
?>
<form method="post" action="page2.php">
    <input type="submit" name="submit" id="submit" value="Log In" class="button" />
</form>
page2.php
PHP Code:
<?
session_start
();
?>
Your chosen products are:
<ul>
    <li><?= $_SESSION['product1']; ?></li>
    <li><?= $_SESSION['product2']; ?></li>
</ul>
you'd just define the $_SESSION variables on page 2 instead of 1.

as for the ie6 thing, turn session.use_trans_sid on in your php.ini. ie 6 will start a new session every page load otherwise, because microsoft builds bad products.

07-10-2007, 08:07 PM
#3
Dark_Prince11 is offline Dark_Prince11
Status: Member
Join date: Apr 2007
Location: Deer Park, NY
Expertise:
Software:
 
Posts: 123
iTrader: 0 / 0%
 

Dark_Prince11 is on a distinguished road

Send a message via AIM to Dark_Prince11 Send a message via MSN to Dark_Prince11

  Old

Yeah your best bet is sessions but be sure to unset the session after you are done using it. If you are putting sensitive data into the session, it can be manipulated by "others".

07-10-2007, 08:16 PM
#4
majorglory is offline majorglory
Status: Senior Member
Join date: Jun 2006
Location:
Expertise:
Software:
 
Posts: 848
iTrader: 10 / 100%
 

majorglory is on a distinguished road

  Old

Derek:
I did it and I got a series of errors

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\contacts\app.php:13) in C:\wamp\www\contacts\app.php on line 15

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\contacts\app.php:13) in C:\wamp\www\contacts\app.php on line 15
Dark: How do I do that?

I'm a COMPLETE noob when it comes to PHP. If the answer is really obvious then I'm sorry.

07-10-2007, 09:09 PM
#5
Faceless is offline Faceless
Status: Junior Member
Join date: Mar 2007
Location:
Expertise:
Software:
 
Posts: 66
iTrader: 2 / 100%
 

Faceless is on a distinguished road

Send a message via MSN to Faceless

  Old

Originally Posted by majorglory View Post
Derek:
I did it and I got a series of errors




Dark: How do I do that?

I'm a COMPLETE noob when it comes to PHP. If the answer is really obvious then I'm sorry.
For the first problem, I would try wrapping the session stuff with the output buffering functions ob_start() and ob_end_flush().

Example:

Code:
ob_start();
session_start();
ob_end_flush();
For the second problem, session_destroy() or session_unset() should do the trick. You could also change the values of each $_SESSION index to "" (ie. $_SESSION['hello'] = ""). That would work too.

07-10-2007, 10:46 PM
#6
derek lapp is offline derek lapp
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
 
Posts: 2,246
iTrader: 0 / 0%
 

derek lapp is on a distinguished road

  Old

Originally Posted by majorglory View Post
Derek:
I did it and I got a series of errors
you've got to start the session before you output anything to the browser. it's best to do it right after you set the <?php tag.


Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\contacts\app.php:13) in C:\wamp\www\contacts\app.php on line 15
you get this error because something's already been sent to the browser. you've either echoed/printed something, or you included an external file that writes to the browser, like an html include.

you can use the $_SESSION variables anytime through the script, but you have to declare it right at the beginning.

07-10-2007, 11:51 PM
#7
CreativeLogic is offline CreativeLogic
CreativeLogic's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 1,078
iTrader: 6 / 100%
 

CreativeLogic is on a distinguished road

Send a message via MSN to CreativeLogic

  Old

You could simply use hidden form fields for the values you already have.

07-11-2007, 01:01 AM
#8
majorglory is offline majorglory
Status: Senior Member
Join date: Jun 2006
Location:
Expertise:
Software:
 
Posts: 848
iTrader: 10 / 100%
 

majorglory is on a distinguished road

  Old

^ Thats what I was thinking, but I figured it was an uncommon way to go. Would that method still be acceptable as a valid way of doing it?

Thanks all for the replies. Since I only work on this at the office, I'll come back tomorrow morning with the results.

07-11-2007, 03:36 PM
#9
majorglory is offline majorglory
Status: Senior Member
Join date: Jun 2006
Location:
Expertise:
Software:
 
Posts: 848
iTrader: 10 / 100%
 

majorglory is on a distinguished road

  Old

Before I tried anything, I tried Creative's idea first. It worked out fine so I never got around to touching the sessions idea.

Thanks all for your help! I feel I'll be back real soon though with another problem.

07-13-2007, 10:27 PM
#10
CreativeLogic is offline CreativeLogic
CreativeLogic's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 1,078
iTrader: 6 / 100%
 

CreativeLogic is on a distinguished road

Send a message via MSN to CreativeLogic

  Old

Just to get back to your question. Yes, there's nothing wrong with doing it that way. The hidden form fields would only contain contents that the user actually submitted themselves therefore there's nothing wrong with doing it that way. I would however not store passwords in the hidden form fields though.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed