0

So I am a newbie in PHP but I need to make an assignment, in which I have to put together a web page using PHP and MYSQL.

While I was creating my pages in PHP with ATOM text editor, I wanted to create the different elements of the page in separate files. For example, I created a head.php and a header.php, and I wanted to include them in the index.php.

No matter how I adjusted the path, I just couldn't get it to work.

I even tried:

-include($_SERVER['DOCUMENT_ROOT']."/includes/head.php")
    and require()
    and The full path to the file

Here are some screens to help you better understand.
This one shows the index.php with the including
This one shows the head.php with the path to the screen.css

dhilmathy
  • 2,800
  • 2
  • 21
  • 29

1 Answers1

0

Change your include(s) to:

include(__DIR__.'/head.php');

or (older php)

include (dirname(__FILE__).'/head.php');

Otherwise your include directive will just search for the file using your 'php include path', which might be wrong.

Have a look here:

How to use __dir__?

https://www.php.net/manual/de/function.get-include-path.php

Community
  • 1
  • 1
michael - mlc
  • 376
  • 5
  • 5