Forum Moderators: coopster

Message Too Old, No Replies

Problems with login script.

login script will not redirect to url.

         

ski442

8:32 pm on Oct 7, 2007 (gmt 0)

10+ Year Member



Hi guys.

This is another problem i have from the last thread I posted, but not sure how to link to it from here, or even if it's allowed.

The script is for a login page, a few of answered last time, thanks for that, but now have a new problem. The script below works fine on 1 of my sites, then i have completed the same code on to another of my sites I am just starting, and will not go to the url set out in the code. The only differance between my 2 site is this time the page has lots of other text on it but all html from a template.

All that happens is once the text boxes are filled with username and password, when the submit button is pressed, the page looks like it refreshes itself and the data in the boxes are gone.

But then if I type in the destination url which has acess rights to it, I can view the page, so the session is working fine. I have been on this one all day tweaking the code but to no a vail. Sorry about the amount of code, have taken out none relavent stuff.

<!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"><!-- InstanceBegin template="/templates/pagetemplate.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>example.co.uk</title>

<?php require_once('Connections/registration1.php');?>

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

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

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/tenants/bevington/home.php";
$MM_redirectLoginFailed = "/login.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_registration1, $registration1);

$LoginRS__query=sprintf("SELECT username, password FROM deposits WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc()? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc()? $password : addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $registration1) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";

//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<div id="bodycontent">

<div align="center">
<form ACTION="<?php echo $loginFormAction;?>" name="form1" method="POST">
<table width="400" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="100">Username:</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td width="100">Password:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td><input type="submit" name="login" id="login" value="Submit"></td>
</tr>
</table>
</form>
</div>

</div>

Maybe I have put some code in wrong order, or am I missing a bit of script. I have also tried using the full url links but no differance.
All help will be most welcome.
Thanks ski

[edited by: eelixduppy at 4:31 am (utc) on Oct. 8, 2007]
[edit reason] removed specifics [/edit]

scnww

4:27 am on Oct 8, 2007 (gmt 0)

10+ Year Member



I think if you want to redirect with php, you need to put the php redirect code before any html code (like <html>, ...).

henry0

11:28 am on Oct 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



scnww, welcome to WebmasterWorld!
this is not the gotten error
I believe OB is "On" for the error is not about
"Header already sent etc..."

for trial purpose and simplify the debugging I would
forget about SELF and create a form that goes to the second script.
Do it a piece at a time and echo each received values

gettopreacherman

8:01 pm on Oct 8, 2007 (gmt 0)

10+ Year Member



In this case, the best thing to do is take all of your html and put it into a $content variable...then if it's invalid then you can redirect.

The statement is correct that you must do the redirect prior to any html is sent to browser, else it won't work...if it is a valid user then echo the $content.

ski442

9:09 pm on Oct 8, 2007 (gmt 0)

10+ Year Member



Hey Guys.

Thanks for all the replies.

So i started with the first reply from SCNWW and it worked.

That is why i like Webmaster World the most because your all brill.

One day I should be able to put back the knowledge I have taken from here.

Thanks again Ski