Reputation: 848
i'm trying to include a file from my subdomain into a file located in the main domain...
So for example:
sub.domain.com/inc/template/file.php <--- (I need to include THIS file)
domain.com/index.php <----- (INTO this file)
so far i've tried:
include('http://sub.domain.com/inc/template/file.php')
but this is not safe because i would need to enable url_fopen with php... so i'm trying to find an alternate way to do this...
Also i'd like to know if when i include a file, can i for example echo a variable once the file it's included.
Thanks in advance.
Upvotes: 0
Views: 1132
Reputation: 21
$source = $_SERVER['DOCUMENT_ROOT'].'/inc/template/file.php';
$destination = $_SERVER['DOCUMENT_ROOT']."/".$subDomainName."/file.php";
if( !copy($source, $destination) ) {
echo "File can't be copied! \n";
}
else {
echo "File has been copied! \n";
}
Upvotes: 0
Reputation: 1545
allow_url_include and allow_url_fopen allow a huge number of web attacks to be successful. Many websites get hacked because they have PHP vulnerabilities. If those sites had been using allow_url_include = Off, or the more general allow_url_fopen = Off, many of those hacks would NOT have been successful even if the underlying vulnerability were not fixed. If you can get by without it, turn it off because it provides very real protection.
When you are including a file from the same website, you do not have to use the full URL, and should not.
If you're including a file from another website, ask yourself whether it's really necessary to do it that way. If it's a static file from another site you manage, you could make a local copy of the file and include it without the URL.
There are some situations where you might have to include by URL, but always try to find an alternative method first.
One more thing- On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include, include_once, require, require_once and the imagecreatefromXXX functions in the GD and Image Functions extension. Read more
Upvotes: 1
Reputation: 408
As long as the file is on the same server you should be able to include it with the full path.
In /home/user/public_html/file.php
, it should work if you add:
include('/home/user/sub1.domain.com/file.php');
For more information read: http://php.net/manual/en/function.include.php
Upvotes: 1