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.
Related
I'm trying to get a file's content into a variable but I don't get anything when I read the file. I used both methods JFile::read() and file_get_contents() but both return the same thing: a blank string, not an error , not any boolean values or anything.
I want to mention that I'm working on a Linux machine (just for 2 days) and recently I changed the permissions for the entire machine to 777 ( I don't know if this affects something or not).
Is the a connection between my OS, permissions and the php's file_get_contents()? or Joomla restricts file reading?
Also I want to mention that my file_get_contents() function was added manually by me in the index.php file , also the file I want to read was manually added in the same folder with index.php.
We had the same problem with one of our clients, it turned out it was a firewall issue. It was very hard to debug this issue. I suggest you check with your networking team.
I am assuming, of course, that you have set the PHP error reporting level to the maximum and that you have checked the error logs.
It seemed the problem was from my system . I messed it up when I changed the permissions so I have to re-install it.
Never change the permissions on a Linux for the entire file system.
I hope you all are in the best mood to help me in my problem .
Ok now I'm using a free hosting that doesn't allow url_allow_include , my domain is example.com and I wanna include a php file from eample2.com/file.php always when I want to do that it doesn't work , please I don't want answers that says contact your hosting provider to enable it for you. I wanna some trick using curl for example or anything else that will solve my problem and thanks in advance
Sure you don't want to hear it... But still, the answer is contact your hosting provider.
But before you do, let me tell you why you probably shouldn't do so in the first place:
If the PHP file you want to include is included over a url (that is with http:// in front of it) , you will be asking the webserver of example2.com to give you that file. The webserver will then run that file through PHP (thus already parsing that file) and give you the parsed HTML that the script produces. And you will end up including the parsed HTML in stead of the original contents of the PHP file you are trying to include.
If by any chance example.com and example2.com are hosted on the same machine, try including the desired file by using an absolute file path to that file. (eg include "/var/www/example2/yourPHPfile.php";)
Contact your host. Option #1 see if they can change that setting. Option #2 see if you can access the php.ini file and find that option in it and change the value. That's about the best you can do but also try this before both options and see if you get an error. If you do the host is blocking it and probably wont allow you to change it.
ini_set('allow_url_include', "0");
here's the problem:
i have a 3rd party script for my website... i have bought hosting from enom.com (i hope this doesn't offend anyone)
i installed the script and works great, except when i try to import rss feeds from other websites.
it's importing the xml file, except the images. The url path is correct, the image exists....
trying to figure out what is wrong, i installed "wamp" on my computer, installed the script and on localhost from my computer the import xml is working perfect, it downloads and add the picture into database + folder
i assume this is a hosting issue, and i want to fix it, can anyone point me where to look?
the hosting plan is using PHP Support as FastCgi application (php safe mode on)
"Server API CGI/FastCGI"
on localhost i have php support on apache
"Server API Apache 2.0 Handler "
thank you!
the answer is very simple, change the hosting company, or pay attention when you place your order.
It's related to allow_url_fopen setting which caused the problem.
in my case i couldn't modify the php.ini file because this was the hosting company policy...
however php.ini can be "bypassed" or modified for each php file by calling the "ini_set" php function which is available for php4/php5 engines...
here's an example
ini_set("allow_url_fopen", 1);
if (ini_get("allow_url_fopen") == 1) {
echo "allow_url_fopen is ON";
} else {
echo "allow_url_fopen is OFF";
}
print ini_get("allow_url_fopen");
and it didn't work for me, because of the hosting company policy...
it can be also "bypassed" or modified by adding one simple line to .htaccess file
php_value allow_url_fopen On
but again, this wasn't an option for me...
CONCLUSION: pay attention when you purchase hosting packages!!!
As for those who can't understand when you can't paste your code as an example because is under specific license and it also encrypted with ioncube, before you post comments sit back and think before you act / or simply do something else...
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
I have just moved my CodeIgniter project to a new server and now I'm getting a 500 error and no output from the project. It works fine on my old server and in my test environment. I'm completely stumped how to troubleshoot this, especially as there's nothing of use in the log files. Any help would be great!
Well, this is embarrassing. I was missing php-mysql. CodeIgniter wasn't logging the fact that it couldn't find it, nothing was appearing in /var/log/messages. Installed it and suddenly, it works. Thanks all for your answers.
I get this problem on my live server with SuPHP. To avoid it, all PHP files must have permissions 0644, and directories 0755.
To do this without a headache, do one of the following:
Get an FTP client that will upload using permissions you specify
Find a PHP script that will change permissions, based on filtering criteria, after upload
Get shell access to your host!
Some ideas for you:
Are you sure there is nothing in the log files? Have you checked both the web server's log files as well as the system logs (EG: /var/log/messages)? Have you checked all of the logs enabled in php.ini?
Double-check your CI configuration settings. Perhaps you are pointing to the wrong database?
Have you confirmed that a basic PHP script <?phpinfo(); ?> works? This would isolate the problem to CI
Most likely you have not specified the base url for the new location, you can set it from file:
/system/config/config.php
at line:
$config['base_url'] = 'your new url here';
have you try load a new CodeIgniter project, and try to load in ur test environment? is it work?
From my experiment 500 error normally due with web server problem. But from what your said you didn't have any .htaccess. You better try just load a clean CI project and see your webserver OK or not.