473,405 Members | 2,421 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,405 software developers and data experts.

my session variables aren't lasting when posting to SELF

My login.htm takes the value (a password) of a textfield and POSTS it
to page2.php. This works correctly.

The first thing Page2.php does is start a session, put the password in
it, then open a MySQL database, and insert various values (which start
off NULL) and then closes the connection. Following this, an HTML form
is displayed and the user enters values. This form is POSTed to itself
(no 'action') and the idea is that the php at the head of the page will
run the SQL query again with the new values. Unfortunately, on
reloading the page, my $_SESSION['pass'] variable has nothing in it.

the relevant code looks like this ;

<?php
session_start();
$_SESSION['pass']=$_POST['pass']; //posted from login page

.......
$pass=$_SESSION['pass']; //turn it into var for MySQL
query

?>

The first time I get to this page, via login page, it works correctly
because the password is posted. When it rePOSTs to itself however, the
$_SESSION['pass'] remains empty. Does the php need to be inside the
form ?
I have tried adding session_write_close() directly after writing
$_SESSION['pass'], but to no avail.

Thank you

Sep 13 '05 #1
2 2086
go****@charliefortune.com wrote:
My login.htm takes the value (a password) of a textfield and POSTS it
to page2.php. This works correctly.

The first thing Page2.php does is start a session, put the password in
it, then open a MySQL database, and insert various values (which start
off NULL) and then closes the connection. Following this, an HTML form
is displayed and the user enters values. This form is POSTed to itself
(no 'action') and the idea is that the php at the head of the page will
run the SQL query again with the new values. Unfortunately, on
reloading the page, my $_SESSION['pass'] variable has nothing in it.

the relevant code looks like this ;

<?php
session_start();
$_SESSION['pass']=$_POST['pass']; //posted from login page

......
$pass=$_SESSION['pass']; //turn it into var for MySQL
query

?>

The first time I get to this page, via login page, it works correctly
because the password is posted. When it rePOSTs to itself however, the
$_SESSION['pass'] remains empty.


Two things to check:

* Is there any character output in page2.php before the opening <?php ?
This includes *any* whitespace, newlines, etc. If there is, then
session_start() will not work correctly (or at all).

* Do you have cookies enabled on your browser? Check in your browser's
cookie list whether you're getting a PHPSESSID cookie from the domain
your script is running on.
--
Oli

Sep 13 '05 #2
>My login.htm takes the value (a password) of a textfield and POSTS it
to page2.php. This works correctly.

The first thing Page2.php does is start a session, put the password in
it, then open a MySQL database, and insert various values (which start
off NULL) and then closes the connection. Following this, an HTML form
is displayed and the user enters values. This form is POSTed to itself
(no 'action') and the idea is that the php at the head of the page will
run the SQL query again with the new values. Unfortunately, on
reloading the page, my $_SESSION['pass'] variable has nothing in it.

the relevant code looks like this ;

<?php
session_start();
$_SESSION['pass']=$_POST['pass']; //posted from login page
When the user clicks SUBMIT (on Page2, not the login page), the HTML
form doesn't have a $_POST['pass'] in it, so you wipe out the one from
the session.

......
$pass=$_SESSION['pass']; //turn it into var for MySQL
query

?>

The first time I get to this page, via login page, it works correctly
because the password is posted. When it rePOSTs to itself however, the
$_SESSION['pass'] remains empty.
Seems like it doesn't REMAIN empty, your code empties it.
Does the php need to be inside the
form ?
I have tried adding session_write_close() directly after writing
$_SESSION['pass'], but to no avail.


Gordon L. Burditt
Sep 13 '05 #3

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

Similar topics

2
by: Martien van Wanrooij | last post by:
I am working on a site that will have several pages and where the user will find some investment advices. I must say that the concept of sessions/session variables is relatively new for me. What I...
4
by: A Web Master | last post by:
I am designing a site for a client where I have a frameset and 3 frames (all in ASP). I am creating session variables in the frameset that need to be accessed in the frames. It seams that in...
1
by: Steve Remer | last post by:
My application (relevant code snippets below) originally used Session variables in order to maintain state from page to page. After being unable to solve the mystery of why those variables were...
31
by: Harry Simpson | last post by:
I've come from the old ASP camp where session variables were not used. When i started using ASP.NET in 2001, I started using them again because it was ok from what I'd read. I've been merrily...
7
by: DC Gringo | last post by:
I was under the impression that when I create session variables such as session("myVar1"), they get stored on the client in a cookie. When I look in my Temporary Internet Files directory for the...
1
by: ChrisN | last post by:
Hi there, Two questions related to each other. 1. Session variables expire by defualt when not used for 20 minutes. Does "used" mean that a user has not access any session varibles in 20...
3
by: Me | last post by:
I am unable to pass the values using session variables. Here is what I tried thus far - 1. In the 1st program I have created a session variable called name Session.Name= <the value I would like...
22
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is...
3
by: Saint | last post by:
My Server Enivronment: MS Windows Server 2003 Standard Edition, Service Pack 1 (running as a VM on a Intel Xeon server) IIS running on Port 80 Apache 2.0.63 running on port 8080 PHP 5.2.5
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.