By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,408 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,408 IT Pros & Developers. It's quick & easy.

Problem with recursive page and session variable

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a

"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

P: n/a

"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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.