Forum Moderators: coopster
I would like to create this PHP script
<?php
$value = 18;
include('script.php?value=$value');
?>
But I get this error message:
Warning: main(script.php?value=$value): failed to open stream: No such file or directory
Warning: main(): Failed opening 'script.php?value=$value' for inclusion (include_path='.;c:\php4\pear')
Any suggestion? Thank you very much.
The inlcuded file also doesn't have its own $_GET collection so what's the point of passing it a querystring?
if it were so, then include() could be used for recursive including, which it's not intended to do.
And here I was thinking I had offered good advice by fixing someone's syntax. (blush)
sorry!
<?php
echo $value;
?>, the script
<?php
$value= 18;
include('script.php');
?>
I guess this comes closest to what the original question was asking for. However using Variables in the global context is bad idea, especially when you are using includes like that.
If register_globals is turned on, and the included file lies in the document root of the webserver anybody cann call the script passing it whichever value it wants. There have been loads of exploits for popular Software-Packages that resulted from this behaviour.
Possible solution: Prevent the included script from being directly called by a user. Either by moving it out of the document-root, or by denying acces to it via .htaccess, or by checking for a defined constant in the included file (which you then have to define in all the scripts that include those files - if it is undefined, die()). Which leads to the above example looking like:
<?php
if (!defined(MY_CHECK)) die();
echo $value;
?>, the script
<?php
$value= 18;
define('MY_CHECK', true);
include('script.php');
?>