PDA

View Full Version : [PHP] Question about scripts and locations.



sajro
December 9th, 2007, 11:24 PM
I am trying to make a script I can include on all my pages. However, with nowhere to test them (server's not up yet) I've run into a small roadblock. I just need to know:


Short, no examples: Are links from a script included in another relative to its location or the location of the script including it?

Long version, with examples: If foo.php is located at /var/www/lorem/foo.php and it includes a script at /var/www/include_me.php, would include_me.php's
<a href="/ipsum/content/php"> lead to /var/www/ipsum/content.php (the intended) or /var/www/lorem/ipsum/content.php (because of foo.php's location)?

Thanks in advance for any help!
- Sajro

geirha
December 9th, 2007, 11:54 PM
This might be a bit confusing :)

The html anchor in your example will use /var/www as it's root. So

<a href="/ipsum/content/php"> will link to /var/www/ipsum/content/php

PHP however, will use the filesystem's root as root, so

<?php include("/ipsum/content/php"); ?> will refer to /ipsum/content/php

To include /var/www/include_me.php, you would use

<?php include("../include_me.php"); ?>

sajro
December 10th, 2007, 12:10 AM
This might be a bit confusing :)

The html anchor in your example will use /var/www as it's root. So

<a href="/ipsum/content/php"> will link to /var/www/ipsum/content/php

PHP however, will use the filesystem's root as root, so

<?php include("/ipsum/content/php"); ?> will refer to /ipsum/content/php

To include /var/www/include_me.php, you would use

<?php include("../include_me.php"); ?>

So

<?php include("../include_me.php"); ?> in /var/www/lorem/foobar.php would include /var/www/include_me.php and /var/www/include.php's link to /var/www/ipsum/content.php would in fact go to the intended destination and not /var/www/lorem/ipsum/content.php (which is nonexistent)?