473,387 Members | 1,540 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.

Session Variables Lost - Help

I am having difficulty in setting variables in a session, and then
accessing those variables throughout the web pages that they click
on. After having them set a user name and password, successfully
authenticating against Active Directory, I send them from the
login.php page to the index.php page. But when I get to the index.php
page, the session ID is visible, but the session variables and values
are not. Can you help me out? Also, I'm curious how to distinguish
between various sessions if multiple ones are available. My files are
below. Thanks.

Eddie

-- excerpt of login.php page

start_session();

$user= $_POST[u];
$pass= $_POST[p];

if (isset($_SESSION[user]) and ($_SESSION[user]==$user)){

$_SESSION[auth] = admin_all;
$_SESSION[user] = $user;
$_SESSION[timelast] = time();
$_SESSION[email] = 't********@testdomain.com';

header('Location: http://mydomain.com/index.php');
}

but when I go to the on to the index.php page, I cannot see the
results. What am I missing?
-- excerpt of index.php page

$sessname = session_name();
$sessid = session_id();
session_start();

print "<pre>\nContents of \$_COOKIE:\n";
foreach ($_COOKIE as $k =$v) {
print " $k = $v\n";
}

print "\nContents of \$_SESSION:\n";
foreach ($_SESSION as $k =$v) {
print " $k = $v\n";
}
print "</pre><br>";

print "sessionuser = " . $_SESSION[user] . " <br>";
print "sessiontimelast = " . $_SESSION[timelast] . " <br>";

-- output of index.php page

Contents of $_COOKIE:
PHPSESSID = e12d796fc6e373569202c58d8f096815

Contents of $_SESSION:
user =
timelast =

Session name = PHPSESSID
Session id = e12d796fc6e373569202c58d8f096815

-- excerpt of php.ini file

session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.serialize_handler = php

Aug 31 '07 #1
8 3012
Eddie wrote:
I am having difficulty in setting variables in a session, and then
accessing those variables throughout the web pages that they click
on. After having them set a user name and password, successfully
authenticating against Active Directory, I send them from the
login.php page to the index.php page. But when I get to the index.php
page, the session ID is visible, but the session variables and values
are not. Can you help me out? Also, I'm curious how to distinguish
between various sessions if multiple ones are available. My files are
below. Thanks.

Eddie
Hi Eddie,

First: A client (browser) does NOT have multiple sessions.
It can have multiple sessions to DIFFERENT DOMAINS, but not within one.

The session is defined by the value of PHPSESSID, which can be stored in
a cookie, or via URL-rewritting, or even hidden var in POST.
As long as PHP received a PHPSESSID, you have a session.

IF PHP has a corresponding file with that id, you have a session.

>
-- excerpt of login.php page

start_session();

$user= $_POST[u];
Why don't you use formal notation for associative arrays?
$_POST["u"];
$pass= $_POST[p];

if (isset($_SESSION[user]) and ($_SESSION[user]==$user)){

$_SESSION[auth] = admin_all;
What is admin_all?
Didn't you mean:
$_SESSION["auth"] = "admin_all";
or maybe
$_SESSION["auth"] = $admin_all;
$_SESSION[user] = $user;
$_SESSION[timelast] = time();
$_SESSION[email] = 't********@testdomain.com';

header('Location: http://mydomain.com/index.php');
You forgot the exit command here.
Setting a header will NOT stop the script.
It runs on, and I have no clue what follows. Maybe a reset on the session?
}

but when I go to the on to the index.php page, I cannot see the
results. What am I missing?
-- excerpt of index.php page

$sessname = session_name();
$sessid = session_id();
session_start();

print "<pre>\nContents of \$_COOKIE:\n";
foreach ($_COOKIE as $k =$v) {
print " $k = $v\n";
}
This can be done much easier with print_r, like this:
echo "<pre>";
print_r($_COOKIE);
echo "<pre>";

same for $_POST and $_GET and $_SESSION.
Use print_r() (with pre) to dump ANY (complex) array.

>
print "\nContents of \$_SESSION:\n";
foreach ($_SESSION as $k =$v) {
print " $k = $v\n";
}
print "</pre><br>";

print "sessionuser = " . $_SESSION[user] . " <br>";
print "sessiontimelast = " . $_SESSION[timelast] . " <br>";

-- output of index.php page

Contents of $_COOKIE:
PHPSESSID = e12d796fc6e373569202c58d8f096815

Contents of $_SESSION:
user =
timelast =

Session name = PHPSESSID
Session id = e12d796fc6e373569202c58d8f096815

-- excerpt of php.ini file

session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.serialize_handler = php
Also: are you sure you stay in the same domain after the
header("Location.....");
??
Sessions cannot (easily) span domains, luckily. ;-)

Regards,
Erwin Moller
Aug 31 '07 #2
Erwin Moller wrote:
<snip>

PS: Make sure you have ALL error/notices reporting on.

add above your script:
error_reporting(E_ALL);

Regards,
Erwin Moller
Aug 31 '07 #3
On Aug 31, 6:58 am, Eddie <eddieandr...@gmail.comwrote:
I am having difficulty in setting variables in a session, and then
accessing those variables throughout the web pages that they click
on. After having them set a user name and password, successfully
authenticating against Active Directory, I send them from the
login.php page to the index.php page. But when I get to the index.php
page, the session ID is visible, but the session variables and values
are not. Can you help me out? Also, I'm curious how to distinguish
between various sessions if multiple ones are available. My files are
below. Thanks.

Eddie

-- excerpt of login.php page

start_session();

$user= $_POST[u];
$pass= $_POST[p];

if (isset($_SESSION[user]) and ($_SESSION[user]==$user)){

$_SESSION[auth] = admin_all;
$_SESSION[user] = $user;
$_SESSION[timelast] = time();
$_SESSION[email] = 'testem...@testdomain.com';

header('Location:http://mydomain.com/index.php');

}

but when I go to the on to the index.php page, I cannot see the
results. What am I missing?

-- excerpt of index.php page

$sessname = session_name();
$sessid = session_id();
session_start();

print "<pre>\nContents of \$_COOKIE:\n";
foreach ($_COOKIE as $k =$v) {
print " $k = $v\n";

}

print "\nContents of \$_SESSION:\n";
foreach ($_SESSION as $k =$v) {
print " $k = $v\n";}

print "</pre><br>";

print "sessionuser = " . $_SESSION[user] . " <br>";
print "sessiontimelast = " . $_SESSION[timelast] . " <br>";

-- output of index.php page

Contents of $_COOKIE:
PHPSESSID = e12d796fc6e373569202c58d8f096815

Contents of $_SESSION:
user =
timelast =

Session name = PHPSESSID
Session id = e12d796fc6e373569202c58d8f096815

-- excerpt of php.ini file

session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.serialize_handler = php
start_session() isn't a php function (unless you declared a function
by that name I didn't notice), replace it with session_start().

Aug 31 '07 #4
On Aug 31, 12:37 pm, 4sak3n 0ne <4sak3n...@gmail.comwrote:
On Aug 31, 6:58 am, Eddie <eddieandr...@gmail.comwrote:
I am having difficulty in setting variables in a session, and then
accessing those variables throughout the web pages that they click
on. After having them set a user name and password, successfully
authenticating against Active Directory, I send them from the
login.php page to the index.php page. But when I get to the index.php
page, the session ID is visible, but the session variables and values
are not. Can you help me out? Also, I'm curious how to distinguish
between various sessions if multiple ones are available. My files are
below. Thanks.
Eddie
-- excerpt of login.php page
start_session();
$user= $_POST[u];
$pass= $_POST[p];
if (isset($_SESSION[user]) and ($_SESSION[user]==$user)){
$_SESSION[auth] = admin_all;
$_SESSION[user] = $user;
$_SESSION[timelast] = time();
$_SESSION[email] = 'testem...@testdomain.com';
header('Location:http://mydomain.com/index.php');
}
but when I go to the on to the index.php page, I cannot see the
results. What am I missing?
-- excerpt of index.php page
$sessname = session_name();
$sessid = session_id();
session_start();
print "<pre>\nContents of \$_COOKIE:\n";
foreach ($_COOKIE as $k =$v) {
print " $k = $v\n";
}
print "\nContents of \$_SESSION:\n";
foreach ($_SESSION as $k =$v) {
print " $k = $v\n";}
print "</pre><br>";
print "sessionuser = " . $_SESSION[user] . " <br>";
print "sessiontimelast = " . $_SESSION[timelast] . " <br>";
-- output of index.php page
Contents of $_COOKIE:
PHPSESSID = e12d796fc6e373569202c58d8f096815
Contents of $_SESSION:
user =
timelast =
Session name = PHPSESSID
Session id = e12d796fc6e373569202c58d8f096815
-- excerpt of php.ini file
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.serialize_handler = php

start_session() isn't a php function (unless you declared a function
by that name I didn't notice), replace it with session_start().
You're right. My code says session_start(). :-)

Aug 31 '07 #5
On Aug 31, 3:02 pm, Eddie <eddieandr...@gmail.comwrote:
On Aug 31, 12:37 pm, 4sak3n 0ne <4sak3n...@gmail.comwrote:
On Aug 31, 6:58 am, Eddie <eddieandr...@gmail.comwrote:
I am having difficulty in setting variables in a session, and then
accessing those variables throughout the web pages that they click
on. After having them set a user name and password, successfully
authenticating against Active Directory, I send them from the
login.php page to the index.php page. But when I get to the index.php
page, the session ID is visible, but the session variables and values
are not. Can you help me out? Also, I'm curious how to distinguish
between various sessions if multiple ones are available. My files are
below. Thanks.
Eddie
-- excerpt of login.php page
start_session();
$user= $_POST[u];
$pass= $_POST[p];
if (isset($_SESSION[user]) and ($_SESSION[user]==$user)){
$_SESSION[auth] = admin_all;
$_SESSION[user] = $user;
$_SESSION[timelast] = time();
$_SESSION[email] = 'testem...@testdomain.com';
header('Location:http://mydomain.com/index.php');
}
but when I go to the on to the index.php page, I cannot see the
results. What am I missing?
-- excerpt of index.php page
$sessname = session_name();
$sessid = session_id();
session_start();
print "<pre>\nContents of \$_COOKIE:\n";
foreach ($_COOKIE as $k =$v) {
print " $k = $v\n";
}
print "\nContents of \$_SESSION:\n";
foreach ($_SESSION as $k =$v) {
print " $k = $v\n";}
print "</pre><br>";
print "sessionuser = " . $_SESSION[user] . " <br>";
print "sessiontimelast = " . $_SESSION[timelast] . " <br>";
-- output of index.php page
Contents of $_COOKIE:
PHPSESSID = e12d796fc6e373569202c58d8f096815
Contents of $_SESSION:
user =
timelast =
Session name = PHPSESSID
Session id = e12d796fc6e373569202c58d8f096815
-- excerpt of php.ini file
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.serialize_handler = php
start_session() isn't a php function (unless you declared a function
by that name I didn't notice), replace it with session_start().

You're right. My code says session_start(). :-)
This is most likely not your problem, but I thought I'd mention it
because I just had the same thing happen to me today.

If you have anything like Zone Alarm installed, make sure it isn't
messing with your sessions. Mine was, and as soon as I disabled it,
everything worked fine.

Aug 31 '07 #6
On Fri, 31 Aug 2007 15:58:43 +0200, Eddie <ed**********@gmail.comwrote:
I am having difficulty in setting variables in a session, and then
accessing those variables throughout the web pages that they click
on. After having them set a user name and password, successfully
authenticating against Active Directory, I send them from the
login.php page to the index.php page. But when I get to the index.php
page, the session ID is visible, but the session variables and values
are not. Can you help me out? Also, I'm curious how to distinguish
between various sessions if multiple ones are available.
Multiple sessions in a single request are not really supported using
'normal' PHP. It is theoretically possible, but it would require a lot of
tinkering, and normally wouldn't be something you want.
-- excerpt of login.php page

start_session();

$user= $_POST[u];
$pass= $_POST[p];

if (isset($_SESSION[user]) and ($_SESSION[user]==$user)){
How does $_SESSION['user'] (mind the quotes as indicated earlier) get set
_before_ this if statement? In these excerpts it will not be set anywhere,
so all the code in the if statement will not run?
>
$_SESSION[auth] = admin_all;
$_SESSION[user] = $user;
$_SESSION[timelast] = time();
$_SESSION[email] = 't********@testdomain.com';

header('Location: http://mydomain.com/index.php');
}

but when I go to the on to the index.php page, I cannot see the
results. What am I missing?
Heed Erwin's advice about error_reporting(E_ALL); (and possibly an
ini_set('display_errors',true); If these are true excerpts there are more
problems then just the carrying on of a session.
--
Rik Wasmus

My new ISP's newsserver sucks. Anyone recommend a good one? Paying for
quality is certainly an option.
Sep 1 '07 #7
On Aug 31, 10:35 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Fri, 31 Aug 2007 15:58:43 +0200, Eddie <eddieandr...@gmail.comwrote:
I am having difficulty in setting variables in a session, and then
accessing those variables throughout the web pages that they click
on. After having them set a user name and password, successfully
authenticating against Active Directory, I send them from the
login.php page to the index.php page. But when I get to the index.php
page, the session ID is visible, but the session variables and values
are not. Can you help me out? Also, I'm curious how to distinguish
between various sessions if multiple ones are available.

Multiple sessions in a single request are not really supported using
'normal' PHP. It is theoretically possible, but it would require a lot of
tinkering, and normally wouldn't be something you want.
-- excerpt of login.php page
start_session();
$user= $_POST[u];
$pass= $_POST[p];
if (isset($_SESSION[user]) and ($_SESSION[user]==$user)){

How does $_SESSION['user'] (mind the quotes as indicated earlier) get set
_before_ this if statement? In these excerpts it will not be set anywhere,
so all the code in the if statement will not run?
$_SESSION[auth] = admin_all;
$_SESSION[user] = $user;
$_SESSION[timelast] = time();
$_SESSION[email] = 'testem...@testdomain.com';
header('Location:http://mydomain.com/index.php');
}
but when I go to the on to the index.php page, I cannot see the
results. What am I missing?

Heed Erwin's advice about error_reporting(E_ALL); (and possibly an
ini_set('display_errors',true); If these are true excerpts there are more
problems then just the carrying on of a session.
--
Rik Wasmus

My new ISP's newsserver sucks. Anyone recommend a good one? Paying for
quality is certainly an option.
I would try using session_write_close() right before your header()
statement - and see if that helps. From time to time, setting new
variables in sessions won't stick for whatever reason, unless you
close a session on that page first.

Sep 1 '07 #8

Thanks for all the tips and suggestions. It works now!

Eddie

Sep 4 '07 #9

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

Similar topics

3
by: Microsoft | last post by:
I am using Session variables in my ASP application. I have tested the application on a Win2k professional and it works fine. When the same web app is installed on a win2k advanced server from the...
7
by: Billy Jacobs | last post by:
I am having a problem with my session variable being set to Null for no apparent reason. I am declaring it like the following when the user logs in. dim objUserInfo as new clsUserInfo 'Set...
1
by: Eliyahu Goldin | last post by:
When I run my ASP.NET application first time after deployment, it runs OK. On the second run, when one of my web forms tries to read session variables set in another form, it finds them empty....
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
2
by: Tomas Martinez | last post by:
Hi, Well, my problem is so simple as it says in the subjet but very frustrating also. I have a project and it is losing the session variables with each postback, so I downloaded from the web a...
7
by: Erik | last post by:
I have an application that uses sessions variables a lot but one I publish the application on the prod server these variables are lost. The application is written i c# 2.0 and I've set the...
4
by: Not Me | last post by:
Hi, I have a set of pages that use forms authentication for access. There are times when one of the session objects I'm using appears to disappear. The session is not timing out, however. (if...
2
by: maxkumar | last post by:
Hi, I am running a ASP.NET 1.1 site on Win Server 2003 with IIS 6.0. The website has been running for about 1.5 years now. In the past, we used to have random cases of session variables getting...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...

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.