Hi All,

I'm trying to access php-code on another url:

Local php-code test.php:

ob_start();
include( "http://www.mysite.eu/ext.php");

  echo "Local call!";
  echo "External call: ".GetExternal( );
ob_end_flush();
?>

And the code on the other url in ext.php:

<?php

function GetExternal( )
{
  $output = "This is external text";
  return $output;
}
?>

My page comes up with the error:
Local call!
Fatal error: Call to undefined function GetExternal() in D:\Develop\www\test\test.php on line 6

Can someone give me a hint on how to solve this ??

Thanks in advance!

Regards,
disc

Dani AI

Generated

Short version for : is correct — an HTTP include will not import the other server's PHP functions into your process. When you request a PHP file over HTTP the remote host executes its PHP and returns the resulting output (HTML/text), not the raw function definitions, so a function defined on the remote machine will not be available locally. The ability to include URLs is also governed by PHP INI settings (see the allow_url_include/allow_url_fopen documentation on php.net).

Two safe ways to fix this: share the PHP code as a library that the local app can require, or expose the remote behavior as a service and call it over HTTP. For a local solution, put shared functions into a library/helper (in CodeIgniter, create a helper or library and load it from your controller) or publish a Composer package or Git submodule so both sites use the same source. If the code must run remotely, make it an API endpoint that returns data (JSON/text) and call it with cURL or file_get_contents, then parse the response.

Example of a simple client call (replace URL and add error checks/auth in real usage):

$ch = curl_init('https://example.com/endpoint');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

Do not enable allow_url_include on production servers — it is a security risk and not the intended way to share code. See the PHP INI notes for remote include behavior and CodeIgniter helper docs for the recommended local approach: PHP filesystem/INI docs and .

Recommended Answers

All 2 Replies

Can't do that, has to be a local file. If you do an include() on a remote file it'll pretty much just gets the file like you would hit it in the browser. Remote file includes are just a bad idea all around.

oh may gloeh

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.