Forum Moderators: coopster

Message Too Old, No Replies

php include from another domain

is it possible

         

GerBot

10:13 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



I'm loading the top banner on my site (domain.com) using a php include file
Domain.com code:
<?php include("http://www.domain.com/top_banner.inc");?>

This works fine
however

when I upload the top_banner.inc file to domain2.com and then try to include that file in from the 2nd domain the banner is just not showing

Domain.com code:
("http://www.domain2.com/top_banner.inc");?>

Is is possible to execute a php include from another domain?

mcibor

10:26 pm on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot include that file from domain2, because it isn't there. As I understand the file is somewhere on the www.domain.com. So while being there you can upload the file with php. however you're not uploading the file onto the domain server (domain2) but on the client's computer.

So while executing include from domain2 there's no such file. What you have to do is include the file from www.domain.com.

The real problem is that you mix two things together: uploading the file to domain2 and uploading the file to client.

other option is to make an upload to server script, it will require writing into a file.

Hope this cleares the mess a bit. if you need a specific script for file write just post it here.

Best regards
Michal Cibor

Zipper

10:32 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



you can remotely execute php scripts as long as the remote server supports php. the result however would be the processed page rather than the source itself. make sure the calling server's php config has allow_url_fopen enabled. check the reference [php.net] for more info.

GerBot

10:46 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



thanks zipper - that is working now.

a follow up question

if I name my include topbanner.inc the php code at [domain2.com...] is viewable

If I name the include file topbanner.php the script exicutes on domain2.com rather than domain.com.

Is there a way to:
1) hide the php in the include file if the direct url is know and then also only allow it to exicute on domain.com?

JohnCanyon

10:11 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Why not make it simply include.inc.php, have it check the IP address of domain.com and if it matches spit out the formatted php code you need. This should work perfectly fine as well as hiding the source of the code.

//Untested example

if($_SERVER[REMOTE_ADDR] == "yourdomain_ip")
{
//echo your formatted php code
$code = <<<EOF
<?php
echo "hello world";
?>
EOF;
echo $code;
}
else
{
die("nothing to see here");
}

Cheers