Solved

Include from other domain

Posted on 2011-02-14
11
295 Views
Last Modified: 2012-05-11
Hi folks is there a way to access with include a file in another domain? I have two domains in different servers and I want it to be able to include a file from the other server, is this possible? If it is, how would I go about it?

Cheers!
0
Comment
Question by:doRodrigo
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 34893618
Are  you wanting the rendered version of the file or the actual file contents such as the php code?

0
 
LVL 6

Expert Comment

by:t-max
ID: 34893627
Hi!
Have a look here: http://us2.php.net/manual/en/features.remote-files.php
Hope this will help you out. Good luck doRodrigo!
0
 

Author Comment

by:doRodrigo
ID: 34893634
The file has a conditional if that checks the domain from which the script is being opened, and if it is a certain domain it gives a certain html and if it is from another it gives another html.

Cheers!
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 6

Expert Comment

by:t-max
ID: 34893676
That shouldn't be a problem. Once you know the domain from where the request is done, you can decide with the if what html file you need on the remote domain.
You can then "fopen" the html file from the second domain, and use it locally.
0
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 34893678
Ok, so you just need to grab the rendered html - That makes is a lot easier.  

The php settings on the "remote" server will need allow_url_fopen enabled.  If it isn't you will have to go the cURL route or use other options such as fsockopen().

If allow_url_fopen is enabled this should work:

include "http://www.yoursite.net/included_file.php";

if the page that is calling the included file requires the file you may want to use the require() or require_once() functions: http://php.net/manual/en/function.require-once.php

If you need additional help troubleshooting, just let us know.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34895982
Whether you can "include a file in another domain?" will depend on whether your hosting company allows it.  It should be very easy to test.  As long as you control both of the domains in question there is not much security to worry about.
0
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 34896021
Ray is right about the host allowing it, that is why I previously mentioned:

 "The php settings on the "remote" server will need allow_url_fopen enabled.  If it isn't you will have to go the cURL route or use other options such as fsockopen()."

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34896031
Some important information to read before you depend on this:

http://bugs.php.net/bug.php?id=47444
http://www.php.net/manual/en/filesystem.configuration.php

So you want to set the permission in your php.ini file -- it is not settable inside your script with a line like this:

ini_set('allow_url_include', TRUE); // DOES NOT WORK

The code snippet failed with this message. Warning: require_once() [function.require-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/websitet/public_html/RAY_temp_dorodrigo.php on line 5


<?php // RAY_temp_dorodrigo.php
error_reporting(E_ALL);
ini_set('allow_url_include', TRUE);
echo "Hello World from LAPRBass.com";
require_once('http://nationalpres.org/RAY_temp_dorodrigo.php');

Open in new window

0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34896037
This version worked fine.
<?php // RAY_temp_dorodrigo.php
error_reporting(E_ALL);
echo "Hello World from LAPRBass.com";
echo file_get_contents('http://nationalpres.org/RAY_temp_dorodrigo.php');

Open in new window

0
 

Author Closing Comment

by:doRodrigo
ID: 34896054
Cheers Ray, as usual it worked!

Thanks a lot.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34896559
Thanks for the points, and good luck with your project! ~Ray
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question