I want to include()
a php file located on my server, with additional GET attributes. But it won't work:
include('search.php?q=1');
The error it gives:
PHP Warning: include(): Failed opening './search.php?q=1' for inclusion
Seems like it tries to open a file literally named 'search.php?q=1' instead of opening the 'search.php' file and sending it the GET attributes.
*Note that it does work if I don't put any GET attributes:
include('search.php');
PHP Include Files. The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.
The require() function will stop the execution of the script when an error occurs. The include() function does not give a fatal error. The include() function is mostly used when the file is not required and the application should continue to execute its process when the file is not found.
You need to try the path of functions. php within the system and not its url. Do you have console access? If so just find out what directory is the file in and include it using the full path.
You don't want to do this: You'd have to do a http request to be able to pass GET parameters. A PHP script you call in this way will run in a separate PHP process.
The optimal way is to include the file locally:
include('search.php');
and to pass any parameters to it manually, like e.g.
$q = "1"; include('search.php'); // expects `$q` parameter
or, more cleanly, putting whatever you have in search.php
into a function or class that you can call with a parameter:
include('search.php'); // defines function my_search($q) my_search(1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With