0

I'm trying to set all header inside 1 folder name header.php

So that everytime i can just use

<? php include ("header.php")?>

to set up all my stylesheet, JS and etc... but once i created a new file and create new php try to include my "header.php" it shows this error message

Warning: include(header.php): failed to open stream: No such file or directory in 
C:\xampp\htdocs\WebEnt\Certain View File\Register.php on line 5

Warning: include(): Failed opening 'header.php' for 
inclusion (include_path='C:\xampp\php\PEAR') in 
C:\xampp\htdocs\WebEnt\Certain View File\Register.php on line 5

header.php

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="Picture/SEGI2.png">
    <title>EC-Submission</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/custom.css" rel="stylesheet">

    <!--Own Customized CSS by Jake-->
    <link href="css/WebCustom.css" rel="stylesheet">


    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
</head>

can anyone provide the easiest solution? Thank YOU

9
  • try include_once("header.php"); Commented Mar 25, 2017 at 10:32
  • @NishitManjarawala Tried this the error message still the same, just from "include" became "include_once" Commented Mar 25, 2017 at 10:34
  • have you tried require_once ? Commented Mar 25, 2017 at 10:38
  • @Mazz tried, same error message Commented Mar 25, 2017 at 10:45
  • Is it in the same directory? Try require_once(__DIR__."/../header.php") Commented Mar 25, 2017 at 10:47

3 Answers 3

1

To fix the problem with the CSS files, you need to use path

/WebEnt/css/WebCustom.css

or

/css/WebCustom.css

I'm not sure which one is working, but it's easy to test.

The explanation for this is that now the paths are in the HTML-code, which is processed only in browser while showing the page. Thereby the path must be relative to the directory where the server is serving the pages from. When you visit your site, I guess you go to address http://localhost/, that points to either C:\xampp\htdocs\ or C:\xampp\htdocs\WebEnt\. That is what you need to take into consideration on the css path.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot ! After certain testing and with your answer i've successful solve this problem! I'll also provide the solution in this post.
1

You haven't provided correct path for your header.php file, check in which folder is your header.php and correct its path in include

7 Comments

my "header.php" is placed at "htdocs\WebEnt" but the new php file is on "htdocs\WebEnt\Certain View File\Register.php" so is much deeper. By only using "include("header.php")" should be working... but not for me.
I think you need to use C:\xampp\htdocs\WebEnt\header.php I'm afraid PHP doesn't look back in the directory tree
@TuomasK I also tried this method, it will causing all my css not working.
I think there would be something wrong in your header.php file. Please update your question with new/more information or open a new question
@JakeCube In which folder is your css? Can you also list your directory structure of the project you are working on?
|
0

I've found a solution also thanks to whoever comment and help me to solve this issue. Here i'll list out how i solve this problem.

  1. Create a external file to store header, footer, navbar and etc...
  2. Changing the path from "css/Webcustom.css" to "/WebEnt/css/WebCustom.css"
  3. Back to "C:\xampp\htdocs\WebEnt\Certain View File\Register.php" and changing the include path via this method

    <?php include "$_SERVER[DOCUMENT_ROOT]/WebEnt/HVF/header.php"; ?>
    
  4. And it works for me!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.