failed to open stream: no suitable wrapper could be found - php

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

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');

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

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.

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.

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.
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;
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

Related

How to access a file on my local server from a program residing on my own server?

I need to run a localhost php file (without uploading it to my website).
I have a php file calld myfile.php on my website. Here is the code.
<?php
include "local_file.php";
?>
Is there any way to make this program work such that I store local_file.php on my local server(localhost), and still access it using the above code(myfile.php) which is stored on my website?
You can use PHP's eval() function and load code as plaintext through HTTP (I assume that you have: installed HTTP server, public IP address, redirected ports on your router).
$code = file_get_contents("http://your_public_ip/local_code.txt");
eval($code);
Remember to use your public IP and store PHP code in file with other extension, so that code won't be executed on localhost.
Generally, I strongly discourage executing code from remote location, as it is a big security hole. Consider whether it is needed to execute included code. If you just want to include HTML code or some data - use file_get_contents() and print it usingecho.
More: http://www.php.net/manual/en/function.eval.php
I believe you can, you have to disable a security feature in php that allows only local includes. Then you will need to have a static IP or dynamic dns setup to point to your local. Your local will then need to be setup to share the file. I don't recommend this though as it opens a lot of potential security holes. Here is some more info:
including php file from another server with php
The security setting you are looking for is: allow_url_include
http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-include
If you are going to go this route I would highly recommend blocking all connections to your localhost other than a single white listed IP address.

Viewing PHP properly with my Localhost using XAMPP

This is my first attempt at using a localhost while editing PHP website files (I'm a HTML girl, but have been asked to make some aesthetic changes to a PHP site).
I've installed XAMPP on my Mac already and configured it (as far as I know). MySQL Database, ProFTPD, and Apache Web Server are running. I've succeeded at viewing a simple index.php file from the htdocs files using localhost/index.php. I've placed the entire website directory (named newsite) inside the htdocs folder. When I attempt to view the website in Firefox or Safari via localhost/newsite/index.php I get this message in the browser:
Warning:
include_once(/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc):
failed to open stream: No such file or directory in
/Applications/XAMPP/xamppfiles/htdocs/newsite/index.php on line 2
This is referring to a block of PHP at the beginning of the index.php document. I've checked, the simplepie.inc file is in file inc under file newsite. If I try go around it by commenting out that section of code and any related calls, the browser goes blank. Can anyone please tell me what else I need to do to just view these files via localhost?
Okay, this is simple but might be complex. So you state:
I've checked, the simplepie.inc file is in file inc under file
newsite.
And then the error states:
Warning:
include_once(/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc):
failed to open stream: No such file or directory in
/Applications/XAMPP/xamppfiles/htdocs/newsite/index.php on line 2
So the error is being thrown because it is trying to read this file:
/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc
But it is located here:
/Applications/XAMPP/xamppfiles/htdocs/newsite/inc/simplepie.inc
What are the actual contents of that include_once?
Since you will probably be moving this site from one place to another, I recommend doing this. I am assuming I know what your include_once looks like, but the general concept holds true.
First, in your index.php or main config/init file (if you have one) add this line:
$BASE_PATH='/Applications/XAMPP/xamppfiles/htdocs/newsite';
Then for your include_once change it to read:
include_once($BASE_PATH . '/inc/simplepie.inc');
Basically that will do the equivalent of changing the include_once to this:
include_once('/Applications/XAMPP/xamppfiles/htdocs/newsite/inc/simplepie.inc');
But the flexibility of using $BASE_PATH is it allows you to change the general site $BASE_PATH in one place & then use it wherever in your site you wish.

[PHP]: Read file from another site's API

I'm trying to download the file https://gdata.youtube.com/feeds/api/users/testuser to a string (this file contains the youtube API details from the user 'testuser'). But when I download it with fopen I just get a blank file. I searched a bit but nothing helped, what could be wrong? I tested the same code with a file from the same server and it worked.
Also, I know it's possible because some sites do exactly what I'm trying to do (such as SocialBlade)
did you try file_get_contents check if you get the file using this..
Try with file_get_contents. Seems more appropriate.
Beware of the allow-url-fopen setting
If you are on a hosting service on a shared server, Chances are high that you can not change the allow-url-fopen configuration since it is in PHP_INI_SYSTEM mode. Ask your hosting service for more information about this.

include statement using a variable in the filename

(Please be patient, this does have something to do with include.) I am waiting for a domain to transfer over and am trying to set it up on the new hosting service ahead of time. I realized that on the old site all the path names were absolute, so all my links on the new host point to pages on the old host. I decided to make them all relative (for future possible moves also). I first did it like this:
index.php
include ('./header.php');
header.php
include "./panel.php";
panel.php
Contents of panel.
This works, and my page displays:
Contents of panel.
Then I decided to set a variable for the domain because I want to include this header file from files in subdirectories and I can use the domain variable to make an absolute path. Right now I have a temporary domain name, which I can change later to the real domain name when the transfer comes through. So I changed header.php to:
$domain="http://tempdomain.com"; //I can change this after the transfer
$panel=$domain."/panel.php";
echo $panel;
if ((include $panel) !== 1)
{
echo "<br>include failed";
}
What I get is:
http://tempdomain.com/panel.php
include failed
I've looked at various sites for include syntax, but I can't find any error in my code. All these files are in the / directory. Any ideas?
When you include, you have to give the directory structured, not the url.
Your hosting server path may be home/public/www/htdocs/your_directory_name/panel.php something like this. Then it will work.
remort include is also posiible
if
1. server's php.ini should allow it.
2. the file which will be included should not be preprossed before include. That means it must return unprocessed code :)
First, the allow_url_fopen flag must be set in php.ini. Otherwise remote include() cannot be done. Run var_dump(ini_get("allow_url_fopen")); to see if it is the case.
Second, "Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled." - see PHP docs
Third, your remote PHP script must produce valid PHP code as output. If you include() via http, then not the script itself, but its output will be included.

I have a problem with my php script

I have a form where it request name,email,zipcode. However the problem is that. when you click on submit. it ask you to open the file it doesn't go to the script.
The website is http://childcarelv.org/newsletter.html
PHP isn't being handled by your server. Instead, it is just being output straight to the browser.
This is a server configuration issue.
Your server is configured with the correct MIME type (it is returning application/x-httpd-php), but isn't set up to actually use PHP to process it.
Since you are using Apache, read the configuration instructions here: http://www.php.net/manual/en/install.unix.apache2.php
Looks like you might be hosting with ipower.com. If that is the case, this is an issue for them to solve.
From your description it seems that server is not able to execute the php script, and thus gives it as download to the client.
You should try to put the following code in a file named testphp.php and place in your public home directory and go to the page to see if php extension is mapped to the php module on your server.
<?
phpinfo();
?>
This is just to verify/prove that there is nothing wrong in your script, and even a simple test script won't work.

Categories