Jump to content


Photo

Login Problem


  • Please log in to reply
1 reply to this topic

#1 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 16 December 2005 - 07:40 PM

Hi, I am having massive trouble with my login page.
I have ceated it in DWMX and DW8 and neither work.
I have created a document login2.php and it passes the MM_Username created by DW well.
As soon as I try and add anything to the page or try to copy the script directly into a template it doesn't pass on the session variable.
I have posted the entire script below, can someone please see if they can spot the reason why it wont work for me.
Anothr bug is it works fine on the localhost, which is even more annoying.

This is the login page that works login2.php

<?php require_once('Connections/tbbdb.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 = "index.php";
$MM_redirectLoginFailed = "login_bad.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_tbbdb, $tbbdb);

$LoginRS__query=sprintf("SELECT username, password FROM users 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, $tbbdb) 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 );
}
}
?>
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
Username:
<input name="username" type="text" id="username">
Password:
<input name="password" type="text" id="password">
<input type="submit" name="Submit" value="Submit">
</form>


I wont submit the entire code for the login page that doesn't work unless anybosy asks for it but can anybosy see why t wouldn't work from this script.
and can someone please tell me how I get the code colour coded in the posts as that is the main reason I have not posted the full page that doesn't work.
Thanks in advance.
John
Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#2 xRhysx

xRhysx
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 22 December 2005 - 08:41 PM

i think i see the problem.. try using the code below.

<?php
session_start();
require_once('Connections/tbbdb.php');
// *** Validate request to login to this site.
if(!session_is_registered('loginUsername'))
{
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$accesscheck = $_GET['accesscheck'];
session_register('accesscheck');
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "index.php";
$MM_redirectLoginFailed = "login_bad.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_tbbdb, $tbbdb);

$LoginRS__query=sprintf("SELECT username, password FROM users 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, $tbbdb) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";

//declare two session variables and assign them
session_register('loginUsername');
session_register('loginStrGroup');

if (isset($_SESSION['PrevUrl']) && false) {
session_register('MM_redirectLoginSuccess');
}
header("Location: " . $_SESSION['MM_redirectLoginSuccess'] );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
Username:
<input name="username" type="text" id="username">
Password:
<input name="password" type="text" id="password">
<input type="submit" name="Submit" value="Submit">
</form>

i think thats all that needs fixing. the main error i found was session_start(); was not the first function in the php tags. remember, session_start(); must become before ANYTHING in your php code for it to work. try this :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users