www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Calling a php file from another website

  1. #1
    Join Date
    Oct 2006
    Location
    Ables Springs, Texas
    Posts
    141

    resolved [RESOLVED] Calling a php file from another website

    I have two websites: mysite1.com and mysite2.com

    On mysite1.com I store all my articles in the "library" folder as .php files (they contain nothing but the actual article content - no headers, footers, other includes, etc.). To call those articles on mysite1.com I use a "title" folder to store another .php file that contains the formatting (header, footer, other includes, etc.). Everything works just fine on mysite1.com.

    Now, I want to use some of those articles on mysite2.com without having to create another article file. Unfortunately, the code returns an error for line 11, which is the call to the external .php file:
    Code:
    <?php include("http://www.mysite1.com/library/thearticleiwant.php"); ?>
    No such file or directory in /home2/myserver/public_html/mysite2/library/titles/thearticletitle.php on line 11
    What this tells me is, the code is looking inside mysite2.com for the include, not at mysite1.com. (NOTE - I also tried using "require_once" with a similar result.) Is it possible to call an external .php file?

  2. #2
    Join Date
    Nov 2012
    Location
    Jakarta
    Posts
    42
    For cross-domain, it is better to use API.

    To my knowledge, include only parses local files, not cross-domain files.

    For cross-domain, you should look into file(), file_get_contents(), fopen() and friends or curl library inside PHP.

    Good luck!

    PS. Take a look at the following stackoverflow conversation:
    http://stackoverflow.com/questions/3...p-code-failing
    Last edited by firesnaker; 12-09-2013 at 11:10 PM. Reason: additional info

  3. #3
    Join Date
    Oct 2006
    Location
    Ables Springs, Texas
    Posts
    141
    Quote Originally Posted by firesnaker View Post
    For cross-domain, it is better to use API.

    To my knowledge, include only parses local files, not cross-domain files.

    For cross-domain, you should look into file(), file_get_contents(), fopen() and friends or curl library inside PHP.

    Good luck!

    PS. Take a look at the following stackoverflow conversation:
    http://stackoverflow.com/questions/3...p-code-failing
    Tried using
    Code:
    <?php
    $response = http_get("http://www.mysite2.com/library/myarticle.php", array("timeout"=>1), $info);
    print_r($info);
    ?>
    However, that returns:
    Fatal error: Call to undefined function http_get()

  4. #4
    Join Date
    Oct 2006
    Location
    Ables Springs, Texas
    Posts
    141
    Seems my last two posts never made it past the moderators. The problem has been resolved.

    I changed the code to:
    Code:
    <?php
    // init the resource
    $ch = curl_init();
    // set a single option...
    curl_setopt_array(
        $ch, array(
        CURLOPT_URL => 'http://www.mysite2.com/library/myarticlecontent.php',
        CURLOPT_RETURNTRANSFER => true
    ));
    // execute 
    $output = curl_exec($ch);
    echo $output;
    // close the resource
    curl_close($ch);
    ?>
    This should have worked, but it returned a Forbidden 500 error. The culprit was in my .htaccess file:
    Code:
    # Forbid if blank (or "-") referer *and* UA
    RewriteCond %{HTTP_referer} ^-?$
    RewriteCond %{HTTP_user_agent} ^-?$
    RewriteRule .* - [F]
    #
    Removed that entry and all is well now. Thanks for your help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles