INCLUDE when moving to another host [SOLVED]

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
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

INCLUDE when moving to another host [SOLVED]

Post by christh »

Hi all

I'm after a bit of advice if I may.

I use INCLUDE a lot on my sites for things like site headers and footers and connection stings to SQL databases.

MY include statements look something like

include('/home/content/29/7034929/html/scripts/header.php');

Which is great and works for me...however I am about to move a site to a new host and initial part of the include path is going to change which means I am going to have to run through replacing the path with the new one in many places.

So as to avoid this problem in the future how should I correctly set the path so I need only to change it in minimal locations? In the php.ini file maybe or set the path as some sort of global variable or session variable.

Also am I correct in my understanding that I am talking about the absolute path in this example?

Any help and suggestions greatly appreciated.

Many thanks

Chris
Last edited by christh on Wed Nov 16, 2011 12:04 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: INCLUDE when moving to another host

Post by Celauran »

You're currently using absolute paths. Using relative paths will make your life much easier.
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

Re: INCLUDE when moving to another host

Post by christh »

Thanks Celauran

I can't remember why but when I first started teaching myself I couldn't get my includes to work with relatives paths.

Maybe it was my inexperience at the time.

I'll try switching and see.

Thanks

Chris
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

Re: INCLUDE when moving to another host

Post by christh »

hmmm

If I change it a relative path of /scripts/header.php

I get the following error

Warning: include() [function.include]: Failed opening '../scripts/header.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/29/7034929/html/index.html on line 10

I guess this is why I went with an absolute path in the early days and never changed.

Chris
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: INCLUDE when moving to another host

Post by Celauran »

Absolute paths start with a /, relative paths don't.

Code: Select all

include 'scripts/header.php';
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

Re: INCLUDE when moving to another host

Post by christh »

Brilliant!

Thanks for your help

Chris
Post Reply