Include and Require cannot be found on my system.

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

Include and Require cannot be found on my system.

Postby Ben-Hur » 06. August 2022 15:02

I have at task to complete that needs me to use include on my index and subsequent pages. Apache cannot load them siting absence of such directory. I do not know where and how to use the $include_path = get_include_path ()statement since my XAMPP does not show an editable page on .;C: \xampp\php\PEAR directory.
Ben-Hur
 
Posts: 2
Joined: 06. August 2022 14:43
XAMPP version: Win-183(PHP 5.5
Operating System: WINDOWS 10

Re: Include and Require cannot be found on my system.

Postby Froosh » 06. August 2022 20:08

Not sure what you are expecting to be an editable page, and how you are expecting to see it in this case. If you are using a browser, then you only see the rendered output from the PHP file. To edit the pages you would need an editor, like VS Code.

My xampp/php/pear directory contains PHP files and folders. The php files are editable, but I don't think you should be editing those, as they relate to content installed by XAMPP itself. While I guess you could edit them, it is likely not a good idea. You content should really be under the xampp/htdocs folder.

With XAMPP, or more specifically, PHP, editable pages are files with extensions like .php, .html, .css, and such.
Information on the PHP get_include_path() function can be obtained here https://www.php.net/manual/en/function. ... e-path.php. Basically, though, the get_include_path() function returns the php.ini configuration value from the php.ini configuration file. That file is more about overall PHP configuration. I believe this is different from what you are tasked with doing.

Including files in your PHP code is accomplished with the PHP include and require statements. These would be used in your index.php, or other php files for your site. You can see an example on https://www.w3schools.com/PHP/php_includes.asp or read about the statements on the PHP site here https://www.php.net/manual/en/function.include.php, and here https://www.php.net/manual/en/function.require.php.
User avatar
Froosh
 
Posts: 138
Joined: 27. March 2022 17:56
XAMPP version: 8.2.0
Operating System: Windows 11 Pro

Re: Include and Require cannot be found on my system.

Postby Ben-Hur » 07. August 2022 09:41

Thanks for the timeous response, Froosh. Maybe my problem is placing the file with the include statement, because when I include that statement in the index file that I put in the root directory of the php task pages, It returns the statement, "Warning: include(menu.inc): failed to open stream: No file such directory in C:\xampp\htdocs\menu.inc\Task.php and specifies the line the include code is put. I am given the code to set the include path and the "get path code" but I do not know where and how to use them. I did open the www.php.net manual, but that also starts me up front where I do not understand where to put the code. Please bear with me, I live in a rural area where there are not many people who understand code to ask.
Ben-Hur
 
Posts: 2
Joined: 06. August 2022 14:43
XAMPP version: Win-183(PHP 5.5
Operating System: WINDOWS 10

Re: Include and Require cannot be found on my system.

Postby Froosh » 08. August 2022 14:39

I am not really sure what you are trying to achieve with "menu.inc" or "C:\xampp\htdocs\menu.inc\Task.php", but on the surface the setup appears odd. I can setup a simple PHP page and include a .php file in that, or even include a PHP file with a .inc extension, and the page renders its content, and the included content. I've done this based on setting up a folder under htdocs and cloning the bits from the w3schools example I mentioned above. The content from the main PHP file, and the included .php, and .inc files are all rendered in the browser.

index.php
Code: Select all
<html>
<body>
  <h1>Welcome to my home page!</h1>
  <p>Some text.</p>
  <p>Some more text.</p>
  <?php include 'footer.php'; ?>
  <?php include 'footer.inc'; ?>
</body>
</html>


footer.php
Code: Select all
<?php
echo "<p>Footer.php | Copyright &copy; " . date("Y") . " MySite</p>";


footer.inc
Code: Select all
<?php
echo "<p>Footer.inc | Copyright &copy; " . date("Y") . " MySite</p>";


The above renders a simple page, with the body content, and the content from the two footers. In my case all files are in xampp/htdocs/mysite.

No matter where you live, there are plenty of online resources for this sort of thing, you just have to search online. I'd also suggest that the XAMPP forms, which are useful, are probably not the best resource for PHP specific topics.

Be well.
User avatar
Froosh
 
Posts: 138
Joined: 27. March 2022 17:56
XAMPP version: 8.2.0
Operating System: Windows 11 Pro


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 230 guests