473,241 Members | 2,005 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,241 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 2081
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.