Frustrated with include() statement

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
kyoru
Forum Commoner
Posts: 26
Joined: Mon Feb 13, 2006 9:35 pm

Frustrated with include() statement

Post 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

Code: Select all

include 'title_bar.php';
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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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()
kyoru
Forum Commoner
Posts: 26
Joined: Mon Feb 13, 2006 9:35 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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... ;)
Post Reply