Issue When Including PHP File Located Outside Document Root
Posted: 30. June 2017 19:35
I am attempting to use AJAX in an HTML file in the "DocumentRoot" folder to return a response from a PHP file. It works fine if the PHP file is located in the “DocumentRoot” folder, but does not work if it is located outside the “DocumentRoot” folder and included by another PHP file located in the “DocumentRoot” folder. Specifically, no response is received from the server and the following error is returned via the PHP error log (memory_limit set to 1M to reduce the amount of time before the PHP error is presented – a higher memory limit only increases the delay before presenting the error):
I am running XAMPP (version 7.0.18) on a Windows 10 machine. The path for the “DocumentRoot” folder is set in the httpd.conf file:
I created a simple test case with a “test.php” file and a “test-process.php” file. The “test.php” file has the following code (in its entirety):
The “test-process.php” file has the following code (in its entirety):
The following include_path is set in the php.ini file:
Removing/renaming the PHP file from the includes folder and removing/renaming the includes folder itself have no effect on the error. I would expect to see some error stating that the file or directory could not be found, but there is none.
I tried using "include_once" (instead of "include") in the "test.php" file and no errors are given. So perhaps the "Allowed memory size..." error is caused from attempting to repeatedly include the "test-process.php" file.
I am new to XAMPP and cannot figure this out. Although I haven’t tried this exact situation on a production server, I have used AJAX in the past with no such issues on production servers. Any suggestions would be appreciated.
- Code: Select all
PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 4096 bytes) in C:\Users\Username\Desktop\site\DocumentRoot\test.php on line 1.
I am running XAMPP (version 7.0.18) on a Windows 10 machine. The path for the “DocumentRoot” folder is set in the httpd.conf file:
- Code: Select all
DocumentRoot "C:\Users\Username\Desktop\site\DocumentRoot"
<Directory "C:\Users\Username\Desktop\site\DocumentRoot">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
I created a simple test case with a “test.php” file and a “test-process.php” file. The “test.php” file has the following code (in its entirety):
- Code: Select all
<?php include 'test-process.php'; ?>
The “test-process.php” file has the following code (in its entirety):
- Code: Select all
<?php
$output['message'] = 'Hello World';
echo json_encode($output);
?>
The following include_path is set in the php.ini file:
- Code: Select all
include_path = ".;c:\Users\Username\Desktop\site\includes"
Removing/renaming the PHP file from the includes folder and removing/renaming the includes folder itself have no effect on the error. I would expect to see some error stating that the file or directory could not be found, but there is none.
I tried using "include_once" (instead of "include") in the "test.php" file and no errors are given. So perhaps the "Allowed memory size..." error is caused from attempting to repeatedly include the "test-process.php" file.
I am new to XAMPP and cannot figure this out. Although I haven’t tried this exact situation on a production server, I have used AJAX in the past with no such issues on production servers. Any suggestions would be appreciated.