Web Hosting Talk







View Full Version : Passing URL Variables Using PHP Include


sbaar
09-25-2008, 04:26 PM
Hi

when I try to pass the URL variable, it doesn't include the file at all. If I take off the URL variable it does work.

include("page.php?id=home&cat=3");

error :
Warning: include(page.php?id=home&cat=3) [function.include]: failed to open stream: No such file or directory in /home/xx111/public_html/index.php on line 7


I can't get this to work and can't find anything about it using Google. Can anyone help me out?

bigfan
09-25-2008, 04:59 PM
When you include a local file, the entire include string is taken as the filename. So, as the message indicates, a file named "page.php?id=home&cat=3" is being looked for and not found.

Since an included file inherits the scope from where it's included, you could just set a couple variables, e.g. $id and $home, and use them in the included file.

sbaar
09-25-2008, 05:27 PM
thank you for your reply

can give me exsample for this ??

bigfan
09-25-2008, 05:42 PM
In "index.php":$id = 'home';
$cat = 3;
include 'page.php';In "page.php":$str = "There's no place like " . $id . '.<br />';
echo str_repeat($str, $cat);
Edited for better example.

sbaar
09-25-2008, 06:43 PM
Thank you for your support i will try now
Have a nice day