Search code examples
phppearfatal-errorrequire-once

Fatal error: require_once():


I'm getting the following error:

Warning: require_once(D:/xampp/htdocs/inc/head.php): failed to open stream: No such file or directory in D:\xampp\htdocs\ecommerce1\index.php on line 3

Fatal error: require_once(): Failed opening required 'D:/xampp/htdocs/inc/head.php' (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs\ecommerce1\index.php on line 3

I have the following code : located in D:\xampp\htdocs\ecommerce1 Index.php

<!--head-->
<?php $title="Gamer"?>
<?php require_once $_SERVER["DOCUMENT_ROOT"]. '/inc/head.php';?>
<?php require_once $_SERVER["DOCUMENT_ROOT"]. '/inc/menu.php';?>
<!--body of the page-->
<!--footer of the page-->
<?php require_once $_SERVER["DOCUMENT_ROOT"]. '/inc/footer.php';?>
`

This is the head.php which is located in D:\xampp\htdocs\ecommerce1\inc

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php print $title ?> </title>
    <link rel="stylesheet" type="text/css" href="/css/style.css">
    <script type="text/javascript" src="/jquery/jquery-1.12.3.min.js"></script>

</head>
<body>

Solution

  • Do this in your index.php.

    <?php $title="Gamer"?>
    <?php require_once 'inc/head.php';?>
    <?php require_once 'inc/menu.php';?>
    <!--body of the page-->
    <!--footer of the page-->
    <?php require_once 'inc/footer.php';?>
    

    Hope this helps.