473,395 Members | 1,815 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,395 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 1790
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.