I know that it is possible to include php file with variables. It looks like this sample.
include 'http://www.example.com/file.php?foo=1&bar=2';
How to include php file on local file system (instead of url) with variables? Smth like that.
include 'file.php?foo=1&bar=2';
Is it possible?
UPDATE I wanna get variable from index page and include the file with exact variable from local system to content div. smth like that
<?php
$foo=$_GET['foo'];
$bar=$_GET['bar'];
?>
<body>
<div id="ma开发者_JS百科in">
<div id="content">
<?php
include 'file.php?foo='.$foo.'&bar='.$bar;
?>
</div>
</div>
</body>
Variables are simply available in the file to be included. There is no file scope for variables.
so if you do this
$foo=1; $bar=2;
include 'file.php';
$foo
and $bar
will be available in the file.php
.
The variables declared above this included statement will be available in the file.php
file.
Included files have access to whatever variables are defined in the scope they were called in. So, anything you define before the include
will be set in the included file.
# foo.php
$foo = 'bar';
include 'bar.php';
# bar.php
echo $foo;
When foo.php
is run, the output will be 'bar'.
What do you expect the variables to do? Maybe something like this:
<?
$_GET["foo"] = "1";
$_GET["bar"] = "2";
include "file.php";
?>
I think you have it reversed: should be $foo = $_GET['foo'] etc.
精彩评论