Ask a Question related to PHP Development, Design and Development.
-
Nick Whitelegg #1
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;
}
Nick Whitelegg Guest
-
session variable increment problem
session_start(); $_SESSION++; print 'You have visited here '.$_SESSION.' times.'; why the visit variable is not incremented the next time i... -
session variable problem
I have a Session object set on Session_Start... I figured out that the object is never created... Cannot understand why.. Also I noticed that... -
Session Variable problem with CFLOCK
Hi Guys here is my error message: Cannot lock Session scope.CFLock cannot be used to lock the application or session shared scopes without... -
Session and Server variable problem
Hi all, Have an interesting problem. Worked on a web site for a client. They have the server (IIS) set up and we are using php. Have been... -
some kind of redirection (not the header function)
Hi!!! I´m programming a site in PHP, where I want to do the following: I will have a set of different directories, where each directory must... -
Jan Pieter Kunst #2
Re: header() redirection/session variable problem
In article <c12cf038.0309171127.3ca4290f@posting.google.com >,
[email]nick.whitelegg@solent.ac.uk[/email] (Nick Whitelegg) wrote:
You have to initialize or re-open a session with a call to> 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.
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, <devnull@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jan Pieter Kunst Guest



Reply With Quote

