Login Script is not working!!! Driving me CRAZY

ALRIGHT, SO…i’ve been working with this script for 2 days… I have it set up how I want it…
HOWEVER, whenever I try to secure a page, instead of the page going through after logging in I just get the login page. For some reason it’s not showing that I am logged in. I don’t know where the error is in the script. I’ve looked through it over and over again… Here is the login script…

[b]<?php

/* Start session */
if($startSession == TRUE){ session_start();}

/* Config file */
include(‘config.php’);

/* Check for submition */
if($_POST[‘submitID’] == 1){

/* Connect to database */
if($connectDatabase == TRUE){$action=TRUE;include('connect.php');}
	
/* sanitize and check info */
$userName = mysql_real_escape_string($_POST['userName'],$dbc);
$password = mysql_real_escape_string($_POST['password'],$dbc);

if($userName == NULL) { $message = 'Please enter username.';}
if($message == NULL && $password == NULL){ $message = 'Please enter password.';}

if($message == NULL)
{				
	$userQuery = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM " . $tableName .
	" WHERE `" . $userNameField . "`='$userName' AND `" . $userPasswordField . "`='$password'"));		
	
	/* If usercount is more than 0 -> ok */
	if($userQuery[0] > 0){
		/* Disconnect from database */
		if($connectDatabase == TRUE){$action=FALSE;include('connect.php');}

		$_SESSION['isLoged'] = 'yes';
		$_SESSION['userName'] = $userName;
					
		/* add cookies ?*/
		/* expire in 1 hour */
		if($useCookies == TRUE)
		{
			setcookie("isLoged", 'yes', time()+logedInFor, "/", ".$domainName", 1);
			setcookie("userName", $userName, time()+logedInFor, "/", ".$domainName", 1);
		}

		/* Redirect to login page */
		header("Location: $loginPage");
		exit();
	} else {
		$message = 'Invalid username and/or password!';
	}
}
/* Disconnect from database */
if($connectDatabase == TRUE){$action=FALSE;include('connect.php');}

}
?>

<?php /* Display error messages */ if($message != NULL){?>
<?=$message;?>
<?php } ?>
Please log in:
Username:
Password:
[/b]

And here is the script for securing my page…
[b]<?php

session_start();

if($_SESSION[‘isLoged’] != ‘yes’ || $_SESSION[‘userName’] == NULL)
{
header(“Location: login.php”);exit();
}
?>[/b]

for some reason when I used the following it worked UNTIL I logged out and now it’s not working. HELP!?!?

<?php session_start(); if($_SESSION['isLoged'] != 'yes') { header("Location: login.php");exit(); } ?>

I would do something like this in a config.php or utilities.inc.php page:
[php]session_start()
$user = (isset($_SESSION[“username”])) ? $_SESSION[“username”] : NULL;[/php]

Of course you would have to put that info in sessions when the user logs in, most likely in the login.php page?

Then you can just direct them when they are logged in by doing the following:

[php]require ‘lib/includes/utilities.inc.php’;
if ($user) {
header(‘Location: members.php’);
exit();
}[/php]

and to keep a person who isn’t logged in from going to a members only page:
members.php (for example) ->
[php]require ‘lib/includes/utilities.inc.php’;
if (!$user) {
header(‘Location: index.php’);
exit();
}[/php]

or something like that. You’re also using obsolete mysql, you should be using mysqli or PDO (My Recommendation).

[member=57087]Strider64[/member] , is this a typo? $user = $user =

There is no need for the second $user=

Oops, me bad…cut and past will do that all the time…LOL ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service