View Full Version : Dynamic includes?
Nightfire
07-09-2002, 05:45 PM
How can I write a dynamic include? This is what I have , but it's just writing it onto the screen as text:
session_start();
if(session_is_registered("username")) {
$nav = 'include("includes/nav2.php")';
}
else
{
$nav = 'include("includes/nav.php")';
}
echo $nav;
Flamerule
07-09-2002, 06:16 PM
Try :
session_start();
if(session_is_registered("username")) {
$nav_array = file("includes/nav2.php");
$nav = implode(" ", $nav_array);
}
else
{
$nav_array = file("includes/nav.php");
$nav = implode(" ", $nav_array);
}
echo $nav;
Should work...
EDIT :
Also you could use a user defined function.
session_start();
function fetch_include($url){
$nav_array = file($url);
$nav = implode(" ", $nav_array);
return $nav;
}
if(session_is_registered("username")) {
$nav = fetch_include("includes/nav2.php");
}
else
{
$nav = fetch_include("includes/nav.php");
}
Nightfire
07-09-2002, 06:23 PM
Thanks :) Worked perfectly
firepages
07-10-2002, 06:11 AM
errr why wont this work?
session_start();
if(session_is_registered("username")) {
include("includes/nav2.php");
}
else
{
include("includes/nav.php");
}
Mouldy_Goat
07-10-2002, 09:24 AM
It does work... I completely sympathise with your confusion here...
Nightfire
07-10-2002, 01:28 PM
It's coz I've got includes all over the place , so instead of having that code all over, I can cut it down to variables.
Jeewhizz
07-10-2002, 06:30 PM
I'm with firepages here, there's no need to define a variable with the location, and then include it.
Jee
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.