Web Hosting Talk







View Full Version : <? include("whtrules.php"); ?> In a differant directory?


MarkioE
02-08-2006, 04:27 PM
Hey all.

I am having some problems.
Say the file is: http://www.mysite.com/header.php
Is there a way I can include that file from the directory http://www.mysite.com/mysite/rules/and/so/does/wht

PaddysPlace
02-08-2006, 04:32 PM
Sparky,

Look into chdir();

Example:

If you're in a directory and want to include a file from the parent directory...

<?php

chdir('../');

require('./global.php');

chdir('./directory/'); // change back

?>


Or you can use an absolute path (such as chdir('/home/username/public_html/');

I hope this helps you!

Regards,
Patrick

require('./

MarkioE
02-08-2006, 04:34 PM
Cheers mate :) Just what I was looking for.

latheesan
02-08-2006, 05:50 PM
This is how i do it:

<?php
define ('SCRIPT_PATH', $_SERVER['DOCUMENT_ROOT']);
include(SCRIPT_PATH . "/mysite/rules/and/so/does/wht/header.php");
?>

Easy.. is it not?

tamasrepus
02-08-2006, 06:29 PM
You can also modify the PHP include path in php.ini or your Apache's mod_php configuration. If you did this, you could simply do:

include('header.php');

Burhan
02-09-2006, 02:43 AM
If your host supports URL wrappers, then you can simply do include('http://www.mysite.com/header.php');