I have my framework set up as MVC type, where a core library redirects url. This is useful say if a link is as: Some_class/some_method
, it will load some_method from Some_class. Also I have configured everything to pass through index.php using .htaccess file.
Code in index.php
<?php
session_start();
require_once 'config.php';
if (!isset($_SESSION['username']) && empty($_GET['url'])) { ?>
<a href="Users/login">Login</a><br>
<a href="Users/register">Register</a>
<?php } ?>
Code in config.php
// Redirect to the homepage if not signed in
if(!isset($_SESSION['user'])){
header('location: http://localhost/index.php');
}
Code in Users Controller
public function login(){
// Code to verify the entered credentials
// If entered data is valid
$_session['user'] = $_POST['user'];
}
public function log_out(){
session_unset();
}
If someone logs out using log_out method from users controller, the method executes. And if the code were right ideally it should redirect to index.php, because the code in config.php says that if $_SESSION['user']
is not set, it should redirect to index.php. However, whenever someone logs out I get the error mentioned in the title. What mistake am I doing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…