Tauciokas
Tauciokas

Reputation: 99

PHP Includes and Require not working

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');

?>

Upvotes: 2

Views: 32232

Answers (3)

flyingMarsu
flyingMarsu

Reputation: 31

I had the same issue and finally discovered that OVH deactivates the option allow_url_include on their shared web servers by default. This is a general setting that can not be changed.

The solution is to use something like

require ($_SERVER['DOCUMENT_ROOT'].'/wp-config.php');

as Lucas said.

Upvotes: 0

LUCAS NANTES
LUCAS NANTES

Reputation: 1

You could try something like:

include $_SERVER['DOCUMENT_ROOT'] .'*/project_name_if_needed*/test/header/';

I don't know if this is recommended, so use with caution.

Upvotes: 0

Vainglory07
Vainglory07

Reputation: 5273

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');

Upvotes: 3

Related Questions