PHP Includes and Require not working
try :
include('../test/header.php');
it works fine in me.
Edit
: and if not on your case, try to correct the path of your init.php
:
require_once('../core/init.php');
Related videos on Youtube
Comments
-
Tauciokas almost 3 years
I know this question has been asked before, but even after reading other posts I can't figure out whats going on...
Please have a look at my code structure and see what am I doing wrong..
Folder structure:
index.php
(FOLDER - Includes) header.php
(FOLDER - browse) blog.php , ecommerce.php, other.php
(FOLDER - core) init.php
I'm trying to include Header.php from includes folder in blog.php in browse folder. Below is my header.php code.
Header file located in Includes folder
<!DOCTYPE html> <!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]--> <!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]--> <!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]--> <!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]--> <head> <!-- Basic Page Needs ================================================== --> <meta charset="utf-8"> <title>Web Awwards | Web Gallery | Submit your site</title> <meta name="description" content=""> <meta name="author" content=""> <!-- Mobile Specific Metas ================================================== --> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <!-- CSS ================================================== --> <link rel="stylesheet" type="text/css" href="../css/base.css"> <link rel="stylesheet" type="text/css" href="../css/skeleton.css"> <link rel="stylesheet" type="text/css" href="../css/layout.css"> <link rel="stylesheet" type="text/css" href="../css/styles.css"> <link rel="stylesheet" type="text/css" href="../css/menu.css"> <link rel="stylesheet" type="text/css" href="../css/submission.css"> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <!-- Favicons ================================================== --> <link rel="shortcut icon" href="images/favicon.ico"> <link rel="apple-touch-icon" href="images/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png"> </head> <body> <?php require_once('core/init.php'); ?> <!-- Menu Horizontal --> <div class="horizontal"> <div class="webName">
and Browse folder blog.php file code:
<?php include './includes/header.php'; ?> <!-- TODO PHP Scripts --> <div class="category nine columns"> <div class="category-img"> <img src="css/img/webImg/screen1.png" alt="Site Description"/> </div> <h3> Web Name </h3> <h5> Designed By: Tautvydas Slegaitis </h5> <h7> Designers url </h7> <div class="vote"> <h4> Vote for my site </h4> </br> <a href="#"> Love it </a> <a href="#"> Nope, Not for me </a> </div> </div> </div><!-- Close Container Div --> <div class="footer"> </div> </body> </html>
But it is not working. I dont know why,... Please please help me sort this out its killing me for the past 2 days. Coda 2 is showing me an error
" Warning: include(./includes/header.php): failed to open stream: No such file or directory in - on line 2 Warning: include(): Failed opening './includes/header.php' for inclusion (include_path='.:') in - on line 2 "
init.php code:
<?php session_start(); $GLOBALS['config'] = array( 'mysql' => array( 'host' => 'localhost', 'username' => 'root', 'password' => 'root', 'db' => 'webAwwards' ), 'remember' => array( 'cookie_name' => 'hash', 'cookie_expire' => 604800 ), 'session' => array( 'session_name' => 'user' ) ); // TODO Remove parenthesis in require once if doesnt work spl_autoload_register(function($class) { require_once('classes/' . $class . '.php'); }); require_once('/functions/sanitise.php'); ?>
-
christopher about 10 years
./
should be../
. -
Tauciokas about 10 yearsif I add ../ it includes the header but then stops executing the rest of blog.php and if I view source code in the browser only shows header.php code
-
christopher about 10 yearsTry using
require
instead ofinclude
. -
Tauciokas about 10 yearsif I use require it doesnt change anything. I'm really out of ideas no idea whats going on
-
-
Tauciokas about 10 yearsif i correct the path of my init.php as you suggested none of the files open then. I know it would make sense but I dont know why this is happening
-
Vainglory07 about 10 yearshave you tried to remove it first just to check if you can already check get
include('../test/header.php');
correctly? -
Tauciokas about 10 yearsRight so the problem is then with the include of init.php in the header :)
-
Tauciokas about 10 yearsBut how could I make it so it includes in all sort of different directories then>? Whether it be in main index.php and browse/blog.php
-
Vainglory07 about 10 yearsinstead of using require_once, can you also try include on init.php and see what will happen?
-
Tauciokas about 10 yearsWhen using include rather then require the server will still execute the code but dont give me error even if core/init.php is not included?