Using a query-string in require_once in PHP Using a query-string in require_once in PHP php php

Using a query-string in require_once in PHP


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.


All answes true. But most importantly: since $_GET is a global, it's present' in all included files as well, so there's absolutely no use in passing those parameters with the include.