What did I do wrong? Header snet ahead?
I have those tree files:
menulogged.php
<?php
require_once('includes/helper/sessi开发者_如何学Con.php');
require_once("includes/helper/initialize.php");
if (!$session->is_logged_in())
{ Header("location:/public/userview/ctr_login.php"); }
include_layout_template('admin_header.php');
?>
ctr_login.php
<?php
require_once("includes/helper/session.php");
if($session->is_logged_in())
{
$mess='You are already logged in';
}
?>
and session.php
<?php
// A class to help work with Sessions
// In our case, primarily to manage logging users in and out
class Session {
private $logged_in=false;
public $user_id;
public $message;
function __construct() {
session_start();
$this->check_message();
$this->check_login();
}
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;
}
$session = new Session();
$message = $session->message();
?>
For some reason since I am not logged in I get to the login controller and then I get this error:
Warning: require_once(includes/helper/initialize.php) [function.require-once]: failed to open stream: No such file or directory in /home/content/40/7141640/html/public/userview/ctr_login.php on line 2
Fatal error: require_once() [function.require]: Failed opening required 'includes/helper/initialize.php' (include_path='.:/usr/local/php5/lib/php') in /home/content/40/7141640/html/public/userview/ctr_login.php on line 2
I can not believe I am having so many issues with deploying the website I just made. I thought in an hour at most it would be done, but apparently only a person that never made a website would believe that. I looked at the code for at least an hour and I can't figure it out. What did I do wrong?
EDIT I noticed that no matter which two files I call, on the first file the include works fine, and on the second one it can't find the file.
You're trying to include a file that doesn't exist, initialize.php
. Make sure your include path is set up correctly, and that the paths you type in are correct.
You have to tell PHP where to look for include files. By default, PHP will look in the same directory where the script that is being run is resident and obviously in /usr/local/php5/lib/php. You are looking for includes/helper/initialize.php. Make sure, the "includes" folder is in the same directory as the file ctr_login.php OR that the include path is set correctly. (set_include_path()).
Double-check if there are space characters before the <?php
in each included file. This could cause the headers to be sent out.
Well I'm not very sure though, but could you try to change the header syntax into:
header("Location: /public/userview/ctr_login.php");
Also try to use the the absolute path (e.g. www.example.com/userview/ctr_login.php) rather than relative path.
Hope it could help, :)
精彩评论