0

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");
2
  • 2
    That is just not possible. include reads the file form the file system and does not initiate a HTTP request. Commented Feb 14, 2011 at 0:55
  • Ok, what exactly are you trying to do? If you need to pass a value to the script.php it will be able to read the existing $_GET in the calling script. Commented Feb 14, 2011 at 1:05

4 Answers 4

6

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`
Sign up to request clarification or add additional context in comments.

1 Comment

Might be even tidier to have a function or class in the included file, and pass the required variables as arguments to the function/constructor.
5

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

2 Comments

Unless the specified path is a url, in which case an 'http://' type path WOULD be requested via http, but that's highly ugly and incredibly insecure.
yes, it's possible, but oh so horrible. (If "URL fopen wrappers" are enabled in PHP, you can do it, you can also make me projectile-vomit this way too.)
2

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.