PHP includes reference wrong path - XAMPP on Windows 11

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP includes reference wrong path - XAMPP on Windows 11

Postby stoneage » 21. April 2023 18:17

I have a new installation of XAMPP for Windows. When viewing a web page containing PHP include files, the path to the include directory that XAMPP is referencing is not correct.

I have projects in individual directories located in /xampp/htdocs/ (such as /xampp/htdocs/sitename/). I can view all elements of a web page at http://localhost/sitename/ as long as their are no includes.

Example of an include I'm using:
<?php include("_php-inc/myinclude.php"); ?>

Physical location of the include:
C:/xampp/htdocs/sitename/_php-inc/myinclude.php

However, XAMPP is looking here in the shared htdocs:
C:/xampp/htdocs/_php-inc/myinclude.php

-------------
Example error message on web page:
Warning: require_once(C:/xampp/htdocs/_php-inc/myinclude.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\sitename\index.php on line 2

Fatal error: Uncaught Error: Failed opening required 'C:/xampp/htdocs/_php-inc/myinclude.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\sitename\index.php:2 Stack trace: #0 {main} thrown in C:\xampp\htdocs\sitename\index.php on line 2
----------------

Do I need to define a path to each project's directory somewhere in Apache? I've searched this forum and the documentation, but must be missing something.
Thanks for any help!
stoneage
 
Posts: 1
Joined: 19. April 2023 21:27
XAMPP version: 3.3.0
Operating System: Windows 11

Re: PHP includes reference wrong path - XAMPP on Windows 11

Postby Altrea » 21. April 2023 18:25

hi,

don't use paranthesis around include and require statements.
These are special language costructs not functions.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11933
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP includes reference wrong path - XAMPP on Windows 11

Postby Nobbie » 21. April 2023 21:16

stoneage wrote:Example error message on web page:
Warning: require_once(C:/xampp/htdocs/_php-inc/myinclude.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\sitename\index.php on line 2


That error message does not match the PHP code you showed above. You showed an "include" statement, the error message is about require_once. You can also see, that your code calls require_once with a fully qualified path "C:/xampp/htdocs/_php-inc/myinclude.php", this is NOT the path you applied to the include, which was "_php-inc/myinclude.php". Its quite clear that you are doing something wrong, not PHP or Xampp.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: PHP includes reference wrong path - XAMPP on Windows 11

Postby Altrea » 21. April 2023 21:32

I tested it on my Testenvironment (Windows 11, XAMPP 8.2.4)

contents of \xampp\htdocs\sitename\index.php
Code: Select all
<?php include("_php-inc/myinclude.php"); ?>


contents of \xampp\htdocs\sitename\_php-inc\myinclude.php
Code: Select all
<?php echo 'Hello world'; ?>


Output of http://localhost/sitename/
Code: Select all
Hello world


Works like a charm.
Maybe there is something you didn't say us like a redirect fired by a .htaccess file or some of your provided information is not correct (which can happen easily by accident while obfuscating real data.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11933
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 194 guests