Jump to content

Login Problem


Recommended Posts

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.