How do I make the include function url absolute? For example instead of this: <?PHP include("../folder2/folder3/file.php"); ?> I want this: <?PHP include("http://www.mysite.com/folder1/folder2/folder3/file.php"); ?> Can I do this? Thanks! ~imozeb
It depends on your server. Most servers have the configuration variable allow_url_include set to off. It's not terribly secure, so relative path (your first example) are highly preferred. However, if it is set to on, you may be able to use the URL includes. To check if it's on, create a new php file and place the following information in it <?php phpinfo(); ?> Code (php): Under the "Configuration" heading, allow_url_include is close to the top, the third or fourth down. If it's set to off, you can't use the url includes, and dimes to dollars, your host won't change the setting for you.
You could also use the full path to the file you want from the root. On linux this might look somthing like: /home/ME/MYSITE/older2/folder3/file.php
if you start it with a / it goes from the root, if you dont include the / it will start at whatever folder is currently open. so you can do: include("/folder1/folder2/folder3/file.php"); PHP: what does that have to do with his question?
It doesn't work. It says that there is no such file in my folder. It doesn't seem to want to start from the root (most top) folder, it just takes the folder of the file that is open and checks there. Plz help me!
I did and it is set to off. I was just wondering if there is any workaround like Killaklown tried to do. His code didn't work though. Does anyone know a workaround?
It will only work if the server holding the file is outputting the source of the PHP file and not the output of a command etc for example echo. You can use file_get_contents on the file to get its source and perform an eval() on it if you don't want to worry about external include permissions.
You could also try readfile(), but that might not work either. Usually, if the url access is set to off, you can't get anything with a URL value
Even for a windows server see the full path of your document root, and use that to include files. For example if your document root is: C:/wamp/www/ and your script is inside www/codes/file.php you can use: include('C:/wamp/www/codes/file.php'); Thanks