Tuesday, 4 October 2016

php - while making login page, I am unable to redirect to another page

There is an error while redirecting the page from login to index(i.e server error // error 500). I used redirect_to function to call function.php from login.php file and i have included header function in function.php file. unfortunately, there is server error.I tried to solve it but i could not.i have posted my all four file.



login.php



        require_once("../../includes/function.php");
require_once("../../includes/database.php");
require_once("../../includes/session.php");
require_once("../../includes/user.php");


if($session->is_logged_in()){
redirect_to("index.php");
}
//remember to give your form's submit tag a name= "submit" attribute
if(isset($_POST['submit'])){

$username = trim($_POST['username']);
$password = trim($_POST['password']);


//check database to see if username/password exit.
$found_user = User::authenticate($username,$password);

if($found_user){

$session->login($found_user);
redirect_to("index.php");
}else{

//username/password combo was not found in the database

$message ="Username/password incorrect.";
echo $message;

}
}
else{//form has not been submitted

$username = "";
$password = "";
}

?>

$database->close_connection();
}
?>


Photo Gallery

="text/css"/>





staff login























Username:


Password:










index.php



    
require_once('../../includes/function.php');
require_once('../../includes/session.php');
if(!$session->is_logged_in()) {
redirect_to("login.php");

}
?>



Photo Gallery
="text/css"/>






staff login










function.php



        ob_start();
function strip_zeros_from_data($marked_string =""){
//first remove the marked zeros

$no_zeros = str_replace('*0','',$marked_string);
//then remove any remaining marks
$cleaned_string = str_replace('*','', no_zeors);
return $cleaned_string;
}
function redirect_to($location = NULL){
if ($location != NULL){
header("Location : {$location}");
exit;
}


}

function output_message($message = ""){
if($empty($message)){
return "

{$message}

";
}
else{
return "";
}

}
function __autoload($class_name){
$class_name = strtolower($class_name);
$path = "../includes/{$class_name}.php";
if(file_exists($path)){
require_once($path);
}else{
die("the file {$class_name}.php could not found.");
}


}
ob_end_flush();
?>


sesssion.php



// A class to help work with Sessions
//In our case, primarily to mange logging users in and out


//keep in mind when working with sessions that it is generally
//inadvisable to store DB-relate objects in sessions
class Session{
private $logged_in = false;
public $user_id;
function __construct(){

session_start();
$this->check_login();

if($this->logged_in){
//actions to take right away if user is logged in
}else{
//actions to take right away if user is not logged in
}
}

public function is_logged_in(){
return $this->logged_in;
}



public function login($user){
//database should find user based on username/password
if($user){
$this->user_id = $_SESSION['user_id'] = $user -> id;
$this->logged_in = true;

}



}

public function logout(){
unset($_SESSION['user_id']);
unset($this->user_id);
$this->logged_in = false;
}

private function check_login(){

if(isset($_SESSION['user_id'])){
$this->user_id = $_SESSION['user_id'];
$this->logged_id = true;

}else{
unset($this->user_id);
$this->logged_in = false;
}
}
}


$session = new Session()
?>


error message

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...