473,385 Members | 1,630 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,385 software developers and data experts.

header() redirection/session variable problem

Hello,

I'm having an odd problem with combining an authentication session
variable with header() redirection. Basically I have an authentication
script which checks a username/password. If the login is correct a
session variable containing the username is set and the user is
redirected to the (restricted access) main menu page.

The problem is, the FIRST (and only the first) time the user attempts
to login, the "Session variable not set" error message comes up when
the user is redirected to the private page. However the SECOND attempt
to login works.

Can anyone shed some light on this? The relevant code is below; system
is PHP4.3.1 on IIS, 5 I think. The error didn't occur when the PHP was
4.2.x - is this a known 4.3 issue?

Thanks,
Nick

//////////////////////// Login/authentication script
////////////////////////

// Code to check for correct password snipped

// Save the username in a session variable. This will be used in all
// private pages.
$_SESSION['username'] = $username;

// Tried this to attempt to solve the problem. It didn't work.
// sleep(1);

// Redirect to private page

mysql_close($conn);
header("Location: main.php?page=0");

//////////////////// Private main index page
///////////////////////////////////

// Check the username session variable exists
if (isset($_SESSION['username']))
{
// Write out private page
}
else
{
echo "Session variable not set!<A HREF=login.html>Back to
login</A>";
exit;
}
Jul 17 '05 #1
1 6232
In article <c1**************************@posting.google.com >,
ni************@solent.ac.uk (Nick Whitelegg) wrote:
The problem is, the FIRST (and only the first) time the user attempts
to login, the "Session variable not set" error message comes up when
the user is redirected to the private page. However the SECOND attempt
to login works.


You have to initialize or re-open a session with a call to
session_start(); before you start working with $_SESSION variables.

There was no session_start() in your code examples. It might have been
snipped, of course, but that is the first thing that comes to mind.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2

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

Similar topics

0
by: Phil Powell | last post by:
Based upon the following articles: http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20708448.html http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20717295.html...
6
by: Lochness | last post by:
I'm hoping someone can help me with this. I've seen and tried various solutions I've seen on the net, but nothing works. Of course it works perfectly on localhost, but when I upload it to the...
10
by: Margaret MacDonald | last post by:
I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about. I have some code that does some processing and then does a...
4
by: BT3 | last post by:
I appreciate the links on the session variables. I had actually hit that and finished the login and supporting pages. Thanks for everything. I noticed that PHP.NET said to do a HEADER Location:...
0
by: Mike | last post by:
I can not figure out what is going on here. I hope somebody can please help!!! I've got an intranet ASP3 application running on a Win2k server. This application requires a login, so the user...
2
by: fReDiNi | last post by:
Hi, I have an strange problem with session variables. I have a site hosted in a local server. I have physic access to this server and its configuration.(apache, php,files...). I have external...
1
by: Mike Hofer | last post by:
I really need some help, and I'd appreciate any that you folks can provide. The ASP.NET application in question uses version 1.1 of the .NET Framework. All of the pages use a common base class...
0
by: comp.lang.php | last post by:
<? header('Pragma: no-cache'); // ENSURE CLIENT-SIDE CACHE FLUSHING $url = "$projectURLPath/index.php"; if ($_REQUEST) $url .= '?logoutMsg='. urlencode($_REQUEST); if ($willAuthenticate &&...
6
by: webgenius | last post by:
I'm designing a small site and I have this structure in mind: index.php --------------- login fields. User enters login info. LoginCheck.php is called. LoginCheck.php -----------------------...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.