Now I’m pretty new to PHP and server scripting so I could be having a problem with some no brainer rules or simple syntax but I can’t get this code to work…
So the aim is to have a global variable ($logfail) to be set it the username/password doesn’t exist then redirect to the login page and an error message will be displayed through the if statement checking is $logfail is true… but I’m doing something wrong because it’s not working… Any pointers or solutions would be helpful.
login.php:
<?php include("variables.php"); ?>
<html>
<head></head>
<body>
<?php
session_start();
function check_logged(){
global $_SESSION, $USERS;
if (!array_key_exists($_SESSION["logged"],$USERS)) {
header("Location: /index.php");
};
};
if ($_POST["portal"]=="log") {
if ($USERS[$_POST["logn"]]==$_POST["pswd"]) {
$_SESSION["logged"]=$_POST["logn"];
} else {
echo 'Incorrect username/password. Please, try again.';
};
};
if (array_key_exists($_SESSION["logged"],$USERS)) {
header("Location: statelist.php");
} else {
global $logfail;
$logfail = true;
check_logged();
};
?>
...
variables.php:
<?php
$logfail;
?>
index.php:
<?php include("php/variables.php"); ?>
<html>
<head></head>
<body>
.......
<?php
global $logfail;
if ($logfail) {
?>
<p class="logFail red">Incorrect username/password combination...</p>
<?php
};
?>
......