I have this folder-structure:
\out
\script.php
\root
\include
\calculator.php
I need that script into \\calculator.php
. How can I include it?
// calculator.php
require( what path ? );
..
Note: I can include it by this path: ../out/script.php
. But I also need to pass a argument to script.php
. So I want something like this:
.. what path/script.php?arg=value
And as you know, because I need to pass a argument to that, so I have to use http
protocol. All I want to know, How can I use both http
and ../
? Something like this:
http://../out/script.php?arg=value
You don't need to pass parameters when you include the script because it's loaded into the same scope as the first script. This means that the script ../out/script.php has access to the query string arguments through the $_GET variable:
$_GET['arg']
Also, any variables you define in calculator will be available in script.php
You could instantiate some variables inside the $_GET
superglobal before you include your file, ie
$_GET['arg'] = "value";
require('../../out/script.php');
But that isn't ideal, in my opinion.
If I were you I'd use a boring 'ol global variable (assuming you start in the global scope):
$arg = 'value';
require('../../out/script.php');
Then simply use it like any other variable (maybe with some sanity checking, though):
if (!isset($arg)) {
die('Oh my! $arg is not set! Error! Danger!');
}
do_something_with($arg);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.