Reputation: 4695
How would one go about using php include() with GET paramters on the end of the included path?
IE:
include("/home/site/public_html/script.php?id=5");
Upvotes: 0
Views: 312
Reputation: 145482
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.
Upvotes: 0
Reputation: 14956
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.
Upvotes: 2
Reputation: 449525
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`
Upvotes: 6