On one of my pages I have a require_once('../path/to/url/page.php');
which works with no problems. The moment I add a query string require_once('../path/to/url/page.php?var=test');
it won't include the file anymore. It's just blank. Anyone have any ideas of why? Can you not use a query-string in a require?
Thanks, Ryan
By using require_once('../path/to/url/page.php?var=test');
, php will not make a new request to page.php, it will actually search for the file named page.php?var=test
and include it, because in unix, you are allowed to have such a filename. If you want to pass a variable to that script, just define it: $var="test"
and it will be available for use in that script.
require loads a File (from a file path) to include. It does not request that file through apache (or other webserver), therefore you cannot pass query strings in this way.
If you need to pass data into the file, you can simply define a standard php variable.
Example
<?php $a_variable = "data"; require_once('../path/to/url/page.php'); ?>
Note, the variable must be set before the include/require is called, otherwise it won't be available.
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