473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sessions not getting updated

Hi,

I posted on this matter earlier with the subject line "Trouble with
sessions," but someone else started a different thread with the same
subject line that arrived before my post, so I'm changing my subject
line in order to avoid confusion.

I was asked to provide a code example for analysis, so here it is,
along with a
a description of what the problem is.

I'm working with sessions and the values for HTML text fields
(input="text") aren't getting updated after the first time I submit
the form. If I shut down my browser and start anew, I can write to the
session just once, as before. On the other hand, radio buttons -- used
with the Sticky Multivalued Parameters script on pages 170-171 of
O'Reilly's "Programming PHP" -- are updated every time. Here's an
example of my code. Many thanks to anyone who can make sense of what's
going on here.

Best wishes,

Mountain Man
<html>
<head>
<title>First Form Sessions</title>
</head>
<body>
<form action="form_processor.php4" method="POST">
First Name: <input type="text" name="firstName" value="<?php echo
$firstName ?>" /><br />
<input type="submit" />
</form>

</body>
</html>

// Next, the form processing script which is on another page.
// In my more complex script of actual use the form is only
// included if it doesn't pass validation.

<?php
session_start();
session_register("firstName");
?>

<html>
<head>
<title>Form Processor Sessions</title>
</head>
<body>

<?php
echo "$firstName<br />";
include 'first_form.php4';
?>

</body>
</html>
Jul 17 '05 #1
1 1776
Mountain Man wrote:
I'm working with sessions and the values for HTML text fields
(input="text") aren't getting updated after the first time I submit
the form. If I shut down my browser and start anew, I can write to the
session just once, as before. On the other hand, radio buttons -- used
with the Sticky Multivalued Parameters script on pages 170-171 of
O'Reilly's "Programming PHP" -- are updated every time. Here's an
example of my code. Many thanks to anyone who can make sense of what's
going on here.


Using php version >= 4.1? Then start using the $_SESSION superglobal:

<?

// Enable sessions
session_start();

// Get the page URL
$page = $_SERVER['PHP_SELF'];

// Destroy the session var
if (isset($_GET['unset'])) {
if (isset($_SESSION['test'])) {
unset($_SESSION['test']);
header("Location: $page");
exit;
}
}

// Update/create the session var
if (isset($_SESSION['test'])) {
$_SESSION['test']++;
} else {
$_SESSION['test'] = 1;
}

// Debug output
print "test = {$_SESSION['test']}<br />";
print "<a href='$page?unset=1'>Destroy session</a>";

?>
JW

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mountain Man | last post by:
Hi, I'm having trouble with sessions. Text fields from a form aren't getting updated when the form is resubmitted. On the other hand, my radio buttons are updated every time. Many thanks to...
10
by: Mark H | last post by:
Hey all-- I'm building a database and I basically need to keep out people who aren't authorized, but it's not like I need top security here. I'm just doing basic user/pass of a SQL database, and...
15
by: Jazzis | last post by:
I recently moved an application from W2K / IIS5 to W2K3 / IIS6. In the new environment user sessions expire after 2-3 minutes? I can't find any solution to this, although I found quite a few...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
4
by: Edgardo Sepulveda | last post by:
Hi, one question, is there a limit on the numbers of sessions that a client can have? i dont know why but suddently, as i handle a lot of the user information with sessions, and also have added a...
1
by: Duncan | last post by:
I have a strange problem with sessions in PHP 5. I have a simple script that prints a random number both as a string and a picture on the screen. When I run the script for the first time, it works...
3
by: Max2006 | last post by:
Hi, Is Page.Cache global and shared between all session? What would be the best way to cache an object and share it btween all sessions? I like to avoid Application object because it doesn't...
7
by: deciacco | last post by:
The code below works as expected on my ubuntu linux server 7.04 with LAMP installation.(out of the box) The problem is on my Windows 2k3 Server. It seems the garbage collector never deletes the...
9
by: Gilles Ganault | last post by:
Hello Some data are common to all user sessions, and to improve performance/save resources, I'd like to share those data between all sessions, so that each user doesn't have to hit MySQL for the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.