Ask questions via twitter! Message any question to @answers on twitter. We'll publish the question and send you a reply each time there's a new answer.
Next Question

Answered Question

 
M$2 December 24, 2008 12:12 AM

How can you pass variables from one php script page to another?

Using PHP 4.4.9, how can you pass 10ish variables from one php script page to another php script NOT using the URL/POST method and NOT turning register_globals to ON?
Interesting Question?  (0)   (0)   
RSS
 
 

Best Answer  Chosen by Asker

 
December 24, 2008 08:37 AM
Here's an example of how you use session variables:

script1.php:

<?php
session_start();
$_SESSION['foobar'] = 'test';
?>

script2.php:
<?php
session_start();
echo $_SESSION['foobar'];
?>

Note that this will by default use cookie-based session management.
Source(s):
http://us3.php.net/session_start

Asker's Rating:
• Although other answers contained more information, this answer gave me an example of how to do what I was trying to do.


Helpful Answer?  (0)   (0)    Tip ilaksh for this answer
Permalink | Report
   Reply  
 
 

Other Answers (6)

Sort By
 
December 24, 2008 12:15 AM
Create a file, save the data in the file, open the file in the other script, and extract the data.

Helpful Answer?  (1)   (2)    Tip tannerld for this answer
Permalink | Report
   Reply  
 
 
 
December 24, 2008 12:27 AM
Typical answers would be:

* In the querystring (GET)
* Via a POST in hidden fields
* In a cookie / session variable
* By including the next page in the current page (thus making both pages the same page)
* By saving to a DB or file
* Via JS in a hidden frame, or iframe

I know some of these answers you requested not to include, but I was trying to be comprehensive. :)

Helpful Answer?  (1)   (0)    Tip booshtukka for this answer
Permalink | Report
   Reply  
 
 
 
December 24, 2008 01:04 AM
I'd guess that a cookie would be the best solution.

However, without knowing exactly why you can't use POST (and presumably GET), it's difficult to have a clear view of the problem.

Helpful Answer?  (1)   (0)    Tip robbrown for this answer
Permalink | Report
   Reply  
 
 
 
December 24, 2008 04:47 AM
if u pass the one value one page to another without GET/POST

Step 1: Using session value get the previous page value.
Step 2: Using cookie also get the previous page value.

The ways are using get the previous page values

Helpful Answer?  (1)   (0)    Tip phpcook for this answer
Permalink | Report
   Reply  
 
 
 
December 24, 2008 05:59 AM
Can you give an example of how to use session values?

Report
 
 
 
December 24, 2008 09:18 AM
The best way would be with cookies because sessions sometimes have problems. Cookies, as much as I hate them sometimes, have proven to be the best way to maintain state (which is a fancy way of saying save variables). Cookies can also be set to different durations such as "until browser closes" or "forever" as well as time values like 30 minutes or 180 days. The longer values are often used for login info on sites.

Go with cookies, they are universal and if you ever change technologies, they will still be there in the new platform.

Helpful Answer?  (1)   (0)    Tip randulo for this answer
Permalink | Report
   Reply  
 
 
 
December 25, 2008 02:44 AM
Zend framework has a useful session management component that can help with this.
Source(s):
http://framework.zend.com/manual/en/zend.session.html


Helpful Answer?  (0)   (0)    Tip phrees for this answer
Permalink | Report
   Reply  
 
 

Answer this Question

How tips and payments work

This question has already been resolved. You may add an answer to it but you will not be eligible to win best answer or any associated tips.

Ask a Question


140 characters left
Top of Page
Buy Mahalo Dollars with Credit Card or PayPal

Top Members

This Week All Time
  • bunnyphuph...
    bunnyphuph...
    Brown Belt with a Black Tip
    12747 Points
    M$353.75 Earned
  • bestpay
    bestpay
    Purple Belt with a Brown Tip
    6540 Points
    M$76.00 Earned
  • krysstel
    krysstel
    Purple Belt
    2038 Points
    M$8.00 Earned
   See All
 

Most Popular Tags

 

Categories