I'm trying to modify a login script from a File Manager I currently use on my website.
Currently, when the login attempt fails (wrong password, blank fields, etc..) an error message is stored in the $errors
variable, and at the end of the script a function will include a file.php with $errors
as a parameter, so the error message can be echo'd.
What I am unsuccessfully trying to do is replacing this include + parameter($errors) by a header() + $errors.
I have been around every thread dealing with this but so far I haven't found anything that works for me, I need some help : /
Here is the part of the login script that store the error message in $errors and include the file.php :
if(!isset($_SESSION['simple_auth']['username']) || isset($_GET["login"])) {
session_destroy();
session_start();
if(isset($_POST["submit"])) {
$user = gg::getUser($_POST['username']);
if (isset($user['permissions']) && !strstr($user['permissions'], 'r')
|| ($user['username'] == 'guest' && ggconf::get('allow_guests') == false)){
$errors = "Access Forbidden";
gg::writeLog('auth bad - not activated');
}
if (!isset($_POST['username']) || !isset($_POST['password']) || $_POST['username'] == '' || $_POST['password'] == ''){
$errors = "Enter username and password.";
gg::writeLog('auth bad - blank fields');
}
if (isset($user['akey']) && $user['akey'] != '' && strpos($user['akey'], 'otp-') === false){
$errors = "Please open your email and click on the link to proceed.";
gg::writeLog('auth bad - not activated');
}
if(!$errors && $user['username'] == $_POST['username'] && gg::checkPassword($_POST['password'], $user['password'])){
$this->loginUser($user);
}
if(!$errors){
$errors = "Wrong username or password.";
gg::writeLog('auth bad - wrong username or password');
sleep(1);
}
}
if (!isset($_GET["login"]) && ggconf::get('allow_guests') == true){
$user = gg::getUser('guest');
if($user){
$this->loginUser($user);
}
// reload
header('Location: '.ggconf::get('base_url'));
die;
}
gg::display("login.php", array('errors' => $errors));
exit;
}
As you see at the end of this code is the gg::display function that will include the file and its parameter, the function gg::display is the following :
/* DISPLAY VIEWS CONTROLLER */
public static function display($view, $params = null){
require_once ggconf::get('base_path').$view;
}
And last, here is the code inside the file.php that will display the error :
<?php if (isset($params['errors'])):?>
<div class=>
<?php echo $params['errors'];?>
</div>
<?php endif;?>
How can I get my variable $errors with a header() instead of the require_once currently used in the script ?
I found a lot threads dealing with this but nothing worked for me, also note that I'm not very experienced in php yet.
Anyways, I'm thankful for the help, and any suggestions are welcome.
-apatik