Page 1 of 1
Frustrated with include() statement
Posted: Mon Feb 13, 2006 9:40 pm
by kyoru
Hey guys wondering if you could help me with this...
I have a php file that generates a title bar when you give it a variable (title_bar.php?id=car)
I'm trying to include this file in another php file...so i used
Now it works but the picture does not work so i'm guessing theres a file path issue...not a big deal. But how do i send the car variable into the php file? when i try this i get an error saying file does not exist. I also tried to use include in the echo statement of the main page with no success. Any ideas?
Posted: Mon Feb 13, 2006 9:59 pm
by feyd
if title_bar.php is in a different directory, you'll need to tell php where to find it. Either using absolute paths (
/home/server/yourdomain/public_html/includes/title_bar.php), relative paths (
../includes/title_bar.php), or alter the include_path (php.ini or dynamic) settings:
set_include_path()/
get_include_path()
Posted: Mon Feb 13, 2006 10:00 pm
by kyoru
feyd wrote:if title_bar.php is in a different directory, you'll need to tell php where to find it. Either using absolute paths (
/home/server/yourdomain/public_html/includes/title_bar.php), relative paths (
../includes/title_bar.php), or alter the include_path (php.ini or dynamic) settings:
set_include_path()/
get_include_path()
yes it works, but when i try to use title_bar.php?id=car it does not work, thank you
Posted: Mon Feb 13, 2006 10:06 pm
by feyd
you don't use that. Set the variable before including:
Code: Select all
$id = 'Porsche Cayman';
include('title_bar.php');
On a side note, if that works, you have register globals on, which generally is very much not a good thing. You may either want to talk to your host about turning it off, or be very careful how you write scripts to make sure they do not rely on the feature.
Always remember to initialize variables before reading from them...
