Forum Moderators: coopster
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"> </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]
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
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.