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

Problem with recursive page and session variable

I set a session variable on error in the login page and then call the login
page again. I test on that session variable but it shows as not set. I
checked with an echo immediately after setting the error session variable so
I am 100% positive that it is set. The recursive entry to the login page
echos a message that the error session variable is unset.

Any clues?

Here is the setting code and the testing code (commented out)"
$MM_redirectLoginFailed = "ssLogin.php";
if ($loginFoundUser) {
......
......
} else {
$_SESSION['MM_LoginError'] = "Login Error";
// echo "session variable is " . $_SESSION['MM_LoginError'];
header("Location: ". $MM_redirectLoginFailed );
}

Here is the test to see try to get an error message echoed:
<?php
if (isset($_SESSION['MM_LoginError'])) {
echo "Login error =" . $_SESSION['MM_LoginError'];
unset($_SESSION['MM_LoginError']);
} else {
echo "_SESSION['MM_LoginError'] not set";
}
?>

Jul 17 '05 #1
11 1784
Shelly wrote:
I set a session variable on error in the login page and then call the login
page again. I test on that session variable but it shows as not set. I
checked with an echo immediately after setting the error session variable so
I am 100% positive that it is set. The recursive entry to the login page
echos a message that the error session variable is unset.

Any clues?

Here is the setting code and the testing code (commented out)"

<... SNIP CODE...>

Did you call session_start() at any point?

--
Oli
Jul 17 '05 #2

"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:ac***************@newsfe6-gui.ntli.net...
Shelly wrote:
I set a session variable on error in the login page and then call the
login page again. I test on that session variable but it shows as not
set. I checked with an echo immediately after setting the error session
variable so I am 100% positive that it is set. The recursive entry to the
login page echos a message that the error session variable is unset.

Any clues?

Here is the setting code and the testing code (commented out)"

<... SNIP CODE...>

Did you call session_start() at any point?


Yes. Anyway, the page is calling itself. In order to have set it in the
first place I needed to have called session_start().

Shelly

Jul 17 '05 #3
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:ac***************@newsfe6-gui.ntli.net...
Shelly wrote:
I set a session variable on error in the login page and then call the
login page again. I test on that session variable but it shows as not
set. I checked with an echo immediately after setting the error session
variable so I am 100% positive that it is set. The recursive entry to the
login page echos a message that the error session variable is unset.

Any clues?

Here is the setting code and the testing code (commented out)"
<... SNIP CODE...>

Did you call session_start() at any point?

Yes. Anyway, the page is calling itself.


You aren't calling the page, you're redirecting. But regardless, what does that
have to do with session_start()?
In order to have set it in the first place I needed to have called
session_start().


Not necessarily true.
Can you post the complete code for this page, so we're able to see what's going
wrong, because it's not apparent from the snippets you've posted so far.

P.S. You must use an absolute URL in a Location header. But this is unlikely to
be the cause of your problem.

--
Oli
Jul 17 '05 #4
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:wg******************@newsfe5-win.ntli.net...
Can you post the complete code for this page, so we're able to see what's
going wrong, because it's not apparent from the snippets you've posted so
far.


Here it is:

<?php require_once('Connections/ssLogin.php'); ?>
<?php
// *** Validate request to login to this site.
session_start();

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$_SESSION['PrevUrl'] = $accesscheck;
}

if (isset($_POST['username'])) {

$loginUsername=$_POST['username'];
$MM_fldUserAuthorization = "";
$MM_redirecttoReferrer = false;
$MM_redirectLoginSuccess = "ssLounge.php";
$MM_redirectLoginFailed = "ssLogin.php"; //Redirected to
itself <=====
// Make the connection
mysql_select_db($database_ssLogin, $ssLogin);

// Encrypt the password
$encryptedPassword = md5($_POST["password"]);
// Define the query
$LoginRS__query=sprintf("SELECT username, password, level, status
FROM ssusername WHERE username='%s' AND
password='%s'",
get_magic_quotes_gpc() ? $loginUsername :
addslashes($loginUsername),
$encryptedPassword);
// Do the query
$LoginRS = mysql_query($LoginRS__query, $ssLogin) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
// Found this user/password
$loginStrGroup = "";
// Put the fetched row into an array
$row = mysql_fetch_assoc($LoginRS);
$level = $row['level'];
$_SESSION['MM_UserLevel'] = $level;

// Check if status is paid
if (strcmp($row['status'], "paid")) {
// Need a payment
$MM_redirectLoginSuccess = "ssPayment.php";
} else {
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
$MM_redirectLoginSuccess = "ssLounge.php";
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
} // End of test if paid
} //End of successfully found the user/password
header("Location: " . $MM_redirectLoginSuccess );

} else {
// log in error
$_SESSION['MM_LoginError'] = "Login Error";
//==> this is where I checked with an echo statement that the
$_SESSION['MM_LoginError']
//==> had been set. It validated that it was set when incorrect info was
put in.
header("Location: ". $MM_redirectLoginFailed );
} //End of checking if logged in

}
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<div align="center">
<h3>Login Page
</h3>
</div>
<form ACTION="<?php echo $loginFormAction; ?>" name="ssLoginPage" id="form1"
method="POST">
<?php
if (isset($_SESSION['MM_LoginError'])) {
echo "Login error =" . $_SESSION['MM_LoginError'];
unset($_SESSION['MM_LoginError']);
//==> this is what it is supposed to do. I checked with and echo statement
by adding
// } else {
//==> an echo statement that the $_SESSION['MM_LoginError'] was not set
}
?>
<p>Username:
<input name="username" type="text" id="username" />
</p>
<p>Password:
<input name="password" type="password" id="password" />
<label></label>
</p>
<blockquote>
<blockquote>
<p align="left">
<input name="Submit" type="submit" value="Log In" />
</p>
</blockquote>
</blockquote>
<p><a href="ssLounge.php"><img src="images/return.gif" width="138"
height="27" border="0" /></a><a href="ssLostPassword.php"> <img
src="images/lost.gif" width="163" height="27" border="0" /></a></p>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
Jul 17 '05 #5
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:wg******************@newsfe5-win.ntli.net...
Can you post the complete code for this page, so we're able to see what's
going wrong, because it's not apparent from the snippets you've posted so
far.

Here it is:

<...SNIP CODE...>

Hmmm, that all looks ok (I haven't actually tried to run it, but I looked over
the code). One thing to check, do you have any whitespace after the closing ?>
in Connections/ssLogin.php? There must be no output (including whitespace)
before session_start() is called...

--
Oli

Jul 17 '05 #6

"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:st******************@newsfe1-gui.ntli.net...
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:wg******************@newsfe5-win.ntli.net...
Can you post the complete code for this page, so we're able to see what's
going wrong, because it's not apparent from the snippets you've posted so
far.

Here it is:

<...SNIP CODE...>

Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
over the code). One thing to check, do you have any whitespace after the
closing ?> in Connections/ssLogin.php? There must be no output (including
whitespace) before session_start() is called...


There is absolutely nothing between that closing and the openning of the
next php for session_start() except that it is on the next line.

Shelly
Jul 17 '05 #7

"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:st******************@newsfe1-gui.ntli.net...
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:wg******************@newsfe5-win.ntli.net...
Can you post the complete code for this page, so we're able to see what's
going wrong, because it's not apparent from the snippets you've posted so
far.

Here it is:

<...SNIP CODE...>

Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
over the code). One thing to check, do you have any whitespace after the
closing ?> in Connections/ssLogin.php? There must be no output (including
whitespace) before session_start() is called...


Just to be sure, I changed the code to have put them in the same php and had
the session_start() be right after the semi-colon for the require. Same
result.

Shelly
Jul 17 '05 #8
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:st******************@newsfe1-gui.ntli.net...
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:wg******************@newsfe5-win.ntli.net...
Can you post the complete code for this page, so we're able to see what's
going wrong, because it's not apparent from the snippets you've posted so
far.
Here it is:


<...SNIP CODE...>

Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
over the code). One thing to check, do you have any whitespace after the
closing ?> in Connections/ssLogin.php? There must be no output (including
whitespace) before session_start() is called...

There is absolutely nothing between that closing and the openning of the
next php for session_start() except that it is on the next line.


I meant the closing ?> tag *inside* the Connections/ssLogin.php file.

--
Oli
Jul 17 '05 #9

"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:Ix*****************@newsfe2-gui.ntli.net...
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:st******************@newsfe1-gui.ntli.net...
Shelly wrote:

"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:wg******************@newsfe5-win.ntli.net...
>Can you post the complete code for this page, so we're able to see
>what's going wrong, because it's not apparent from the snippets you've
>posted so far.
Here it is:

<...SNIP CODE...>

Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
over the code). One thing to check, do you have any whitespace after the
closing ?> in Connections/ssLogin.php? There must be no output (including
whitespace) before session_start() is called...

There is absolutely nothing between that closing and the openning of the
next php for session_start() except that it is on the next line.


I meant the closing ?> tag *inside* the Connections/ssLogin.php file.


The closing tag greater-than sign is the very last character in that file.

Shelly
Jul 17 '05 #10
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:Ix*****************@newsfe2-gui.ntli.net...
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:st******************@newsfe1-gui.ntli.net...
Shelly wrote:
>"Oli Filth" <ca***@olifilth.co.uk> wrote in message
>news:wg******************@newsfe5-win.ntli.net...
>
>
>
>>Can you post the complete code for this page, so we're able to see
>>what's going wrong, because it's not apparent from the snippets you've
>>posted so far.
>
>
>Here it is:

<...SNIP CODE...>

Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
over the code). One thing to check, do you have any whitespace after the
closing ?> in Connections/ssLogin.php? There must be no output (including
whitespace) before session_start() is called...
There is absolutely nothing between that closing and the openning of the
next php for session_start() except that it is on the next line.


I meant the closing ?> tag *inside* the Connections/ssLogin.php file.

The closing tag greater-than sign is the very last character in that file.


Ok... the only other thing I can spot is that you need an exit() call after the
header() call.

--
Oli
Jul 17 '05 #11

"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:gJ******************@newsfe5-win.ntli.net...
Shelly wrote:
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:Ix*****************@newsfe2-gui.ntli.net...
Shelly wrote:

"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:st******************@newsfe1-gui.ntli.net...
>Shelly wrote:
>
>
>>"Oli Filth" <ca***@olifilth.co.uk> wrote in message
>>news:wg******************@newsfe5-win.ntli.net...
>>
>>
>>
>>>Can you post the complete code for this page, so we're able to see
>>>what's going wrong, because it's not apparent from the snippets
>>>you've posted so far.
>>
>>
>>Here it is:
>
><...SNIP CODE...>
>
>Hmmm, that all looks ok (I haven't actually tried to run it, but I
>looked over the code). One thing to check, do you have any whitespace
>after the closing ?> in Connections/ssLogin.php? There must be no
>output (including whitespace) before session_start() is called...
There is absolutely nothing between that closing and the openning of the
next php for session_start() except that it is on the next line.
I meant the closing ?> tag *inside* the Connections/ssLogin.php file.

The closing tag greater-than sign is the very last character in that
file.


Ok... the only other thing I can spot is that you need an exit() call
after the header() call.


That was it. You are a scholar and a gentlemen. My deepest thanks. It was
driving me crazy

Shelly
Jul 17 '05 #12

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

Similar topics

1
by: Nick Whitelegg | last post by:
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...
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...
0
by: farooq | last post by:
Hi guys, I’m facing some problem can u solve it. Problem is: I’m giving user Id and password in (Login_sess.asp) and submit it to page (sess_test.asp). I am setting session variable...
1
by: farooqazeem | last post by:
Hi guys, I’m facing some problem can u solve it. Problem is: I’m giving user Id and password in (Login_sess.asp) and submit it to page (sess_test.asp). I am setting session variable...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
4
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add"...
13
by: Simon Matthews | last post by:
I am having issues with the right way to architecture the following (using c# asp.net):- The question I have is how best pass the collected data from one web page for use in another. The...
8
by: Nacho | last post by:
Hello people I have the following problem I have a private area in my site. The user enters the username and password, then clicks "enter" and the session is created and also a session...
0
by: shantibhushan | last post by:
Hi I am facing specific problem with firefox browser. I have integrated payment gateway in my website. it is working fine in internet explorer. But I am facing problem with firefox and opera...
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...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...
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.