Tomek
Tomek

Reputation: 251

failed to open stream: no suitable wrapper could be found

hello i am implementing php files from one website into another and here is the following error message i am getting when trying to open the following page with implemented php files:

http://www.holidaysavers.ca/europe-destinations-canada.php

basically the php files i am importing from one website into another are identical , however they work on the original website but when i implement them into a new website it does not work anymore.

could you assist me in trying to get this resolved?

thank you

Upvotes: 25

Views: 86730

Answers (6)

somnath
somnath

Reputation: 1335

Solutions I found:

  1. enable allow_url_include on your php.ini
  2. If you have access to WHM then go to Multi-PHP settings and select the specific PHP version and enable allow_url_include. This will enable the option for all websites on the specific server.

Upvotes: 0

NVRM
NVRM

Reputation: 13087

Using as example a random remote php file.

The goal is to use this remote file locally, make sure it hasn't change or be altered. The remote file will be downloaded one time only.

Hard coding the sha256 signature avoid to use the network on startup. This is just a base that can be turned to many scenarios, like checking for updates, depending your needs.

<?php
$lib_url = "https://raw.githubusercontent.com/getopt-php/getopt-php/master/src/CommandInterface.php";
$lib_filename = basename($lib_url);
// SHA256 signature
$lib_signature = hash_file("sha256",$lib_url); // "dba0b3fe70b52adbb8376be6a256d2cc371b2fe49ef35f0c6e15cd6d60c319dd"
// Hardcode the signature to avoid a network call on startup:
//$lib_signature = "dba0b3fe70b52adbb8376be6a256d2cc371b2fe49ef35f0c6e15cd6d60c319dd";

if (!is_file($lib_filename) || $lib_signature != hash_file("sha256",$lib_filename)){
  // No local copy found, or file signature invalid, get a copy
  copy($lib_url, $lib_filename);
}
require $lib_filename;

It is very useful if you intent to share a program as a single file, without composer.

For the case of a file hosted on Github, an ETag HTTP header is provided, it can be used to avoid to download the whole file.

php -r 'var_dump(json_decode(get_headers("https://raw.githubusercontent.com/getopt-php/getopt-php/master/src/CommandInterface.php", 1)["ETag"]));'
//string(64) "c0153dbd04652cc11cddb0876c5abcc9950cac7378960223cbbe6cf4833a0d6b"

The ETag HTTP response header is an identifier for a specific version of a resource. It lets caches be more efficient and save bandwidth, as a web server does not need to resend a full response if the content has not changed.

Upvotes: 0

Jonathan J. Pecany
Jonathan J. Pecany

Reputation: 313

I don't really know what kind of host you are using or if you are using Xampp, I do have an easy fix to it, for xampp and possibly other web server software. Go to your php.ini file, which you can search for or just look for it in c:\\xampp\php\php.ini, the php.ini should be in the php folder in the server software folder. Now search for allow_url_include in the php.ini file and than replace Off with On, if it isn't already on or something. This is most likely the fix because it worked for me.

I might be able to help further if I know if you are using a hosting or home server. If you are using a hosting website than please share what kind of hosting service you are using so I could inspect it further.

Upvotes: 1

user2859577
user2859577

Reputation:

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/content/91/8151691/html/HolidaySavers.ca/europe-destinations-canada.php on line 52

says it all. I believe this is called XXS. It appears you're attempting to include a URL based file which is denied in your server configuration which is either one of two things.

  1. You're attempting to include the file on site B from site A which you would then use instead of include('WhateverFile'); file_get_contents('WhateverFile'); however this will only return the client side data as it is an HTTP request;

  2. You've duplicated the file on site B and forgot to update the domain configuration. Be sure that the include path reflects the site you're running the script on ie.

    include(dir($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR . 'WhateverFile.php');
    

In any case. I would have to actually examine the line 52 on the said file to see why PHP is complaining to you in detail lol

Upvotes: -1

Latheesan
Latheesan

Reputation: 24116

You can't include a PHP script that is on an external website/server into your local script - unless you enable allow_url_include on your php.ini (if you have access to it)

Instead, you can let that website/server render the page and get the resulting html output on your local script.

Replace this line in your script:

include('http://www.holidaysavers.ca/europe-canada.php?detour');

With this:

echo file_get_contents('http://www.holidaysavers.ca/europe-canada.php?detour');

Upvotes: 31

ldmo
ldmo

Reputation: 379

Could you post the code from "europe-destinations-canada.php"? It looks like the script is asking to do stuff that's not configured in your php setup on this new site/server

Upvotes: 2

Related Questions