Next Question
RSS
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
Permalink | Report
* 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. :)
Permalink | Report
drmatt
Go with cookies, they are universal and if you ever change technologies, they will still be there in the new platform.
Permalink | Report
Source(s):
http://framework.zend.com/manual/en/zend.session.html
Permalink | Report
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)
(0)
(0)
- In Web Development |
- |
- Report |
-
Share
RSS
Best Answer Chosen by Asker
| December 24, 2008 08:37 AM |
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.
Permalink | Report
Other Answers (6)
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. :)
Permalink | Report
drmatt
December 24, 2008 05:59 AM
Can you give an example of how to use session values?
Tip drmatt for this comment
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.
Permalink | Report
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
Permalink | Report
Answer this Question
Related Questions
Ask a Question
Buy Mahalo Dollars with Credit Card or PayPal
Top Members
Most Popular Tags
Categories
- Arts & Design
- Beauty & Style
- Books & Authors
- Business
- Cars & Transportation
- Consumer Electronics
- Coupons and Deals
- Education
- Entertainment
- Environment
- Fitness
- Food & Drink
- From Email
- From iPhone
- From Twitter
- Health
- History
- Hobbies
- Home & Garden
- How Tos
- Humor
- Jobs
- Legal
- Local
- Love & Relationships
- Mahalo Answers Community
- Money
- Music
- News