开发者

PHP include with HTTP get paramters

How would one go about using php include() with GET paramters on the end of the included pa开发者_开发知识库th?

IE:

include("/home/site/public_html/script.php?id=5");


How would one go about using php include() with GET paramters on the end of the included path?

You could write into $_GET:

$_GET["id"] = 5;   // Don't do this at home!
include(".....");

but that feels kludgy and wrong. If at all possible, make the included file accept normal variables:

$id = 5;
include("....."); // included file handles `$id`


You don't, include loads files via the local filesystem.


If you really wanted to, you could just do this, which would have the same result.

<?php
    $_GET['id'] = 5;
    include "/home/site/public_html/script.php";
?>

but then you might as well just define the variable and include it

<?php
    $id = 5; 
    include "/home/site/public_html/script.php";
?>

and reference the variable as $id inside script.php.


Well you could use:

include("http://localhost/include/that/thing.php?id=554&y=16");

But that's very seldomly useful.

It might be possible to write a stream wrapper for that, so it becomes possible for local scripts too.

include("withvars:./include/that/thing.php?id=554");

I'm not aware if such a solution exists yet.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜