Dynamic Include

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Dynamic Include

Post by AliasBDI »

I am making a print page that will dynamically include a page which is passed in the URL. I am able to dynamically include the file, but the file path has a variable passed in it (ex: "page.php?var=22"). The include is giving me an error when it contains the variable. But without it, it is fine (ex: "page.php").

Any ideas?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

you can't pass GET style variables in an include statement. However the included file is run in the same context as the include call. So if you want to "pass" a variable named "var" to the included script simply do

Code: Select all

$var=22;
include("page.php");
the script in page.php can now use $var.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post by AliasBDI »

Great idea. Thanks.


... works great ...
Post Reply