Forum Moderators: coopster

Message Too Old, No Replies

PHP linking with /

         

ffoeg

6:19 pm on Feb 24, 2007 (gmt 0)

10+ Year Member



Hey all.

Rather n00b question I have.

You know how it is possible to link to domain-relative files using a '/' in HTML? (eg. to link to an image, you can do

<a href="/images/image.png">img</a>
)

Is there any way to accomplish the same thing in php using the include function? I've tried doing

include("/included_file.php");
, but PHP doesn't like it at all.

Thanks
*g

Birdman

6:23 pm on Feb 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure, but PHP starts at the server root level. So it needs the full server path (eg. /var/www/html/images/im.jpg). This will vary from server to server.

Luckily there is a simple way to do this and if you ever move to another server with a different path, it'll still work!

include($_SERVER['DOCUMENT_ROOT'] . '/included_file.php')

ffoeg

6:40 pm on Feb 24, 2007 (gmt 0)

10+ Year Member



Of course. Thanks.

I should have realised that. Its been a loooong day :)

thanks a mil
*g