0

I have installed Xampp, and I'm accessing a test page with this url: http://localhost/php8/test.php

test.php has the following code in it which works fine in production.

<?php include ($_SERVER["DOCUMENT_ROOT"] . "/includes/nav-blue.php"); ?>

However, when I call this url http://localhost/php8/test.php, I have the following error:

Warning: include(C:/xampp/htdocs/includes/nav-blue.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\php8\test.php on line 1

Warning: include(): Failed opening 'C:/xampp/htdocs/includes/nav-blue.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\php8\test.php on line 1

So my question is how can I call include files in my php page on Xampp? Somehow the domain name needs to be implemented somwhere to get the full path e.g. mydomain.com/includes/nav-blue.php

Seb
  • 83
  • 1
  • 10
  • Does the file `c:/xampp/htdocs/includes/nav-blue.php` exist? If not what is the correct path?Please update the question to clarify. – AD7six Oct 27 '22 at 20:28
  • @AD7six — The full path easy to work out from the last paragraph – Quentin Oct 27 '22 at 20:36
  • but where do I have to add the mydomain.com in Xampp? – Seb Oct 27 '22 at 20:40
  • `where do I have to add the mydomain.com in Xampp`...what do you mean? This has nothing to do with your error. And you can't really host a domain on your local machine, that would be something you'd do on an internet-facing server. `http://localhost/` is correct for accessing a local development server. – ADyson Oct 27 '22 at 20:43
  • So your code `$_SERVER["DOCUMENT_ROOT"] . "/includes/nav-blue.php"` is causing you the error... it would appear that your document root is `C:/xampp/htdocs`, but it seems you don't have a file called `includes/nav-blue.php` that folder. That's what the error is telling you. It's unclear what that has to do with domain names? – ADyson Oct 27 '22 at 20:46
  • ok thanks I thought I could call external files :-) – Seb Oct 27 '22 at 20:49
  • Do you mean you want to `include` something from another website? Why? And obviously that won't work anyway because you generally don't have access to another server's filesystem, unless you can mount it across the network. See also https://stackoverflow.com/questions/2752783/including-php-file-from-another-server-with-php – ADyson Oct 27 '22 at 21:13
  • `The full path easy to work out from the last paragraph` @Quentin well, not really. At least not without making some assumptions/guessing. – AD7six Oct 28 '22 at 20:43

0 Answers0