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');}
}
?>
<?=$message;?> |
Please log in: |
|
Username: | |
Password: | |
|
|
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(); } ?>