Forums

PHP

This topic is locked

Redirect

Posted 15 Feb 2005 01:04:22
1
has voted
15 Feb 2005 01:04:22 Noel Stratton posted:
Hello,
I want to have a site setup where if a user has never logged on before they are redirected to page where they have to change their password. I am using Dreamweaver mx2004 and my login script is working. I have the login script going to a new page called login_check.php with a redirect script. However, it is not working. It appears the code simple redirects to the first page listed. Below is the code:

<?
if($row_Recordset1['status']=="2"
{
header("Location: change_password.php";
}
elseif($row_Recordset1['status']=="2"
{
header("Location: vote.php";
}
{
exit;
}
?>

Replies

Replied 15 Feb 2005 01:15:17
15 Feb 2005 01:15:17 Noel Stratton replied:
Sorry, the code is actually:

<?
if($row_Recordset1['status']=="1"
{
header("Location: change_password.php";
}
elseif($row_Recordset1['status']=="2"
{
header("Location: vote.php";
}
{
exit;
}
?>
Replied 15 Feb 2005 03:30:06
15 Feb 2005 03:30:06 Chris Charlton replied:
I would remove the quotation marks (&quote<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle> around the interger values (variable==2, not =="2". That's the first thing you should replace. And move the <i>exit();</i> function to be right under the <i>header();</i> redirect calls. Let's start there. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replied 15 Feb 2005 19:39:22
15 Feb 2005 19:39:22 Noel Stratton replied:
I made both changes with the same result. Here is all my code: Thank you for your help <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

&lt;?php require_once('../Connections/board.php'); ?&gt;
&lt;?php
$colname_Recordset1 = "1";
if (isset($_SESSION['MM_Username'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_board, $board);
$query_Recordset1 = sprintf("SELECT * FROM authentication WHERE status = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $board) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?&gt;
&lt;?
if($row_Recordset1['status']==1)
{
header("Location: change_password.php";
exit();
}
elseif($row_Recordset1['status']==2)
{
header("Location: vote.php";
exit();
}
?&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;
&lt;?php
mysql_free_result($Recordset1);
?&gt;
Replied 16 Feb 2005 01:23:27
16 Feb 2005 01:23:27 Iain Stewart replied:
I can only assume that the default value for the status column in your db is 1 and when they change their password and hit the update button to insert the new password the table is also set to update status to 2 or they'll always be asked to change the password.

try

&lt;?
if($row_Recordset1['status']==1)
{
header("Location: change_password.php";
exit();
}
else {
header("Location: vote.php";
exit();
}
?&gt;

this way your only checking that the status is 1, if its anything else they get to move to the page you want them to go to.

Iain

head hurts, 'mental note to self, stop banging head !'
Replied 16 Feb 2005 01:49:23
16 Feb 2005 01:49:23 Noel Stratton replied:
Well I played all day and found an error in my login script. Dumb dumb is all I can think of myself right now. Anyways it is working. I changed my code a little to make it cleanier for anyone who comes to this from google. Thank you for your help!!

&lt;?php if ($row_Recordset1['status']==1)
{
header("Location: change_password.php";
exit();
}
else
{
header("Location: vote.php";
exit();
}
?&gt;
Replied 16 Feb 2005 03:32:07
16 Feb 2005 03:32:07 Chris Charlton replied:
Awesome.

~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>

Reply to this topic