开发者

In PHP :how can I use include() Function which parameter is variable?

I need to use include Function with variable.

but,when I try to do it I faced some errors .

Code :

$year=$_POST['year'];

$month=$_POST['month'];

$day=$_POST['day'];

include "Event.php?year=".$year."&month=".$mo开发者_如何学运维nth."&day=".$day;

so,can U help me ? : )


When you include files, you can't pass them any arguments. However they DO inherit any variables in the current scope (global or method).

I'm guessing at what your code does, but I assume you can just do this:

include "Event.php";


You dont need to use that kind of sintax. The $year, $month and $day variables will be perfectly visible and accessible on the Event.php file.

To get along with what you want, check PHP manual on http://php.net/manual/en/function.include.php to see some examples.


I'm not sure what you're trying to achieve, but I have a couple of guesses handy.

1 - You are trying to redirect the user, with those parameters appended to the url, in which case you will probably need to utilise header:

header("Location: http://example.com/Event.php?year=$year&month=$month&day=$day");

2 - You are trying to capture the output of that page given the presence of certain GET parameters, in which case you can utilise file_get_contents:

$output = file_get_contents("http://localhost/Event.php?year=$year&month=$month&day=$day");


Include the Event.php directly and access the $_POST or $_GET variables from there.


include('Event.php');

// Event.php:
echo $_POST['year']; // works
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜