Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
| Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 22nd, 2008, 06:58 PM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP5 session variable lost

Hi,

I am having a problem passing session variable to the next page.

I am using PHP5.2, MySQL, and Apache 2.2 on Windows XP.

I read many forums and tried different/suggested solutions without success! I would appreciate your help with this.

In page1 I am using the simple code outline below:

<?PHP
session_start();
$color="green";
$_SESSION['color'] = $color;
?>

On page2 I used:

<?php
session_start();
echo "Color = ". $_POST['color']
echo "<br>Color =" . $_SESSION['color'];
?>

However, nothing gets displayed in page2!

Several posts suggest the problem could be in the PHP.ini file.
Here's related parts of my php.ini file:

;session.save_path = "50;/W:\Apache2.2\PHP\sessions\"
session.save_path = "W:\Apache2.2\PHP\sessions\"
session.use_only_cookies = 1
;session.save_path = "/tmp"
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = "W:\Apache2.2\PHP\sessions\"

I am not a PHP expert, and I would really appreciate your help with this.

Many thanks
Totti
 
Old August 5th, 2008, 07:35 AM
Registered User
 
Join Date: Nov 2007
Location: , , India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to v08i
Default

I would like to know , how are you navigating from page 1 to page 2.
Can you just paste the whole source here


--
Vijay Joshi
http://www.vijayjoshi.org

 
Old December 21st, 2008, 01:57 AM
Authorized User
 
Join Date: Nov 2006
Location: mukalla, , Yemen.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<?PHP
session_start();
$color="green";
$_SESSION['color'] = $color;
?>

On page2 I used:

<?php
session_start();
if(isset($_SESSION['color']))
echo "<br>Color =" . $_SESSION['color'];
?>

just it's working like that
 
Old April 3rd, 2009, 11:16 PM
Authorized User
 
Join Date: Dec 2006
Location: Burla, Orissa, India.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to paagle
Default

Best bet is to use variables to store SESSION within a page and re-send it to sessions at the end of a page
Eg:-
page1
$sessionc=$_SESSION['color'];
//Lines of code
/*..........
..........
..........
..............*/
//Last line of your code
$_SESSION['color']=$sessionc;

This preserves session variables that may get lost within a page




Similar Threads
Thread Thread Starter Forum Replies Last Post
session variable lost after redirec in classic ASP beetle_jaipur Classic ASP Professional 8 November 21st, 2008 02:18 AM
Session Value Getting Lost sid81 .NET Framework 2.0 3 October 13th, 2007 10:15 AM
$_POST[variable] in quotes? PHP5 gs99 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 March 2nd, 2007 04:13 PM
Partial Session Lost kiasemoto Classic ASP Professional 0 January 25th, 2007 03:54 AM
Session variables being lost! LenexaKS ASP.NET 1.0 and 1.1 Basics 12 November 13th, 2006 01:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.