1

I need to include some variables and code from my web, I used include "example.com/folder/file.php";, and I can't include this file from my web. I have a paid hosting.

I get these errors:

Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in 
C:\xampp\htdocs\folder\file.php on line 8

W arning: include(http:/example.com/folder/file.php): failed to open 
stream: no suitable wrapper could be found in 
C:\xampp\htdocs\folder\file.php on line 8

Warning: include(): Failed opening 'http://example.com/folder/file.php' 
for inclusion (include_path='C:\xampp\php\PEAR') in 
C:\xampp\htdocs\folder\file.php on line 8

("example.com/folder/file.php" and "C:\xampp\htdocs\folder\file.php" are illustrative urls for protect my privacity)

I hope you can help me. Thanks!

pabdani
  • 11
  • 4
  • Are you saying you want example.com to just hand out your code to anyone that requests it? The only way you can get variables and code would be to tell the remote server to not parse the php. What you really need to do is download a local copy, or better yet, use version control (like git) to make a local repository. – Tim Morton Nov 25 '20 at 05:56
  • @TimMorton No, I not want to download a local copy. I want to make a local php application, from this I want to retrieve variables stored on my web server. Example: I want to retrieve a variable from a server. This web variable controls a version value. If (in my local php app) variable $version > $local_version, the code display a "New version avaliable!" message. Sorry, I not speak english perfectly. – pabdani Nov 27 '20 at 23:43
  • To clarify, you can’t run remote code on a local server. If you have ssh access to your server snd you can see the remote as if it were a local directory, then you could possibly use an `include`, since it would then see it as being local. But if you’re using http as the transport, it will be served through your http server and the php will be parsed. You could set up a web service where the web site would report the current version; but be aware that anyone with that url could access that information. – Tim Morton Nov 28 '20 at 00:48

2 Answers2

0

You might be able to put this line at the beginning of the script

ini_set('allow_url_include',1);

If this does not work, refer to How to locate the php.ini file (xampp) and update the allow_url_include setting in the php.ini file .

https://www.php.net/manual/en/filesystem.configuration.php

user2182349
  • 9,569
  • 3
  • 29
  • 41
0

Possible solution to your problem— make your own web service:

// local script
$localVersion = '1.0.0';
$remoteVersion = '';

// get remote version as json
if( $remote = json_decode(file_get_contents('http://example.com/version.php')) {
  // $remoteVersion=$remote['version'];
  $remoteVersion=$remote->version
}

if( $localVersion < $remoteVersion ) {
  // do whatever...
}

Remote script (version.php)

// load your initialization, or just set
$version = '1.3.0';

header('Content-Type: application/json');
echo json_encode(['version'=>$version]);
die;
Tim Morton
  • 2,614
  • 1
  • 15
  • 23
  • hmmm.... `Fatal error: Uncaught Error: Cannot use object of type stdClass as array in C:\xampp\htdocs\file.php:13 Stack trace: #0 C:\xampp\htdocs\otherfile.php(4): require() #1 {main} thrown in C:\xampp\htdocs\file.php on line 13` – pabdani Nov 28 '20 at 13:55
  • Note, the JSON encoding is only so that you can pass multiple values. There could be some debugging necessary as this is just a concept I typed in with my phone. – Tim Morton Nov 28 '20 at 13:59
  • added object oriented line. I thought it would come through as an associative array, but it’s an object – Tim Morton Nov 28 '20 at 14:06
  • Don’t give up now! You got a response from the server, only it was in object notation instead of array – Tim Morton Nov 28 '20 at 14:19
  • Thank for you help. You are the first person who reply me. :) – pabdani Nov 28 '20 at 14:25