Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass value to an include file in php

Tags:

php

How do you pass a parameter into an include file? I tried the following but it doesn't work.

include "myfile.php?var=123";

and in myfile.php, I try to retrieve the parameter using $_GET["var"].

include "myfile.php?var=123"; will not work. PHP searches for a file with this exact name and does not parse the parameter

for that I also did this:

include "http://MyGreatSite.com/myfile.php?var=123";but it does not also work.

Any hints? Thanks.

like image 620
PHP Ferrari Avatar asked Dec 07 '22 03:12

PHP Ferrari


1 Answers

Wrap the contents of the included file in a function (or functions). That way you can just do

include "myfile.php";
myFileFunction($var1, $var2);
like image 105
Yacoby Avatar answered Dec 09 '22 16:12

Yacoby