I'm using readfile() to serve a download from Rapidshare's API through my server. This is the relevant code:
readfile("http://rs$server_id$short_host.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=$file_id&filename=$file_name&login={$account['username']}&password={$account['password']}");
But when I request the page, I get this error:
Warning: readfile(http://rs869l34.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=3457766962&filename=some_file.rar&login=mylogin&password=mypassword) [function.readfile]: failed to open stream: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? in C:\xampp\htdocs\dl\downloaders\rapidshare_com.php on line 25
According to the Rapidshare API, there's no way to stop it returning an SSL response.
Do I need to configure some special wrapper to handle this or something?
Thanks for any help!
libCurl is used to download file from a remote server like as readfile(http://....).
Though it can handle finer details like as cookie, post and ssl certificates. read more at http://cn.php.net/manual/en/book.curl.php
enable curl in php.ini and try the following code :
$ch=curl_init("http://rs$server_id$short_host.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=$file_id&filename=$file_name&login={$account['username']}&password={$account['password']}");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); // follow http redirect
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true); //temporary ignore certificate error for easier testing
$data=curl_exec($ch);
Related
I’ve been trying to access a HTML page on my own server over HTTPS. So script returns following errors:
PHP Version is 5.6.38
Warning: file_get_contents(): SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL
routines:ssl3_get_server_certificate:certificate verify failed in
/home/user/public_html/index.php on line 11
Warning: file_get_contents(): Failed to enable crypto in
/home/user/public_html/index.php on line 11
Warning: file_get_contents(https://myniceurl.com/file.html): failed to
open stream: operation failed in /home/user/public_html/index.php on
line 11
<?php
$contextOptions = [
'ssl' => [
'verify_peer' => true,
'cafile' => '/etc/pki/tls/cert.pem',
]
];
$context = stream_context_create($contextOptions);
$data = file_get_contents('https://myniceurl.com/file.html', false, $context);
I've tried many solutions from different forums, but none helped. When I try to fetch a page from other sites over HTTPS it works, even I tried to fetch (over HTTPS) the same HTML page on my local machine, it worked properly. I thought the server cannot communicate itself. For investigation purposes, I changed HTTP and it worked properly.
I have tried so far:
Downloaded certificate bundle, added it php.ini file
verify_peer = true and CAfile for stream_context_create
I also confirm that allow_url_fopen is working. Due to the specialized nature of this problem; I’m not finding a lot of information for help. Have any of you come across something like this? Thanks.
I found the reason why this is not working.
It was because of Cloudflare SSL/TLS encryption mode. My selected option was Full strict.
As seen from the image the request has to hit Cloudflare request first, then Cloudflare forwards it to the origin server. However, I added my IP address and hostname to /etc/hosts file, that is why the request was not going out from my network and it causes SSL verification problems.
I'm trying to use the http://ip-api.com/json/ api for get and show the information of a visitant that conects to my website on hostinguer.com.
When I do the next, it should responds me with a json with all the info in a json format:
echo file_get_contents("http://ip-api.com/json/{$user_ip}");
But I get the following error message:
Warning: file_get_contents(http://ip-api.com/json/[MY PUBLIC IP]): failed to open stream: Connection refused in /home/[HOSTINGUER USER]/public_html/ip2.php on line 31
And other strange thing: if I use another API it works correctly and returns me the correct Json! The other API command:
echo file_get_contents("http://ipinfo.io/{$user_ip}/json");
So, I want to use the ip-api.com API cause the results are more accurate, but only works if I use ipinfo.io API... Why can I do the petition to a website and not to the other?
Otherwhise, I tried both in local using curl or writting in my webrowser and it works correctly. Also I tried in local in a Lammp and the both works perfectly. And finally I tried somthing like this post: PHP file_get_contents() returns "failed to open stream: HTTP request failed!" in hostinguer and it doesn't works..
I thought maybe is something in the hostinguer configuration but...
Thanks in advance!
Your IP address is banned. If you're using normal web hosting, your outgoing IP address is shared with other users, who probably did more requests than allowed.
Go to http://ip-api.com/docs/unban and enter your server's outgoing IP address (check it via http://ipinfo.io/json)
One of our suppliers has requested we change from an ftp to ftps for sending them files.
I have a PHP script that uses ftp_connect to transfer the files.
I've modified the script to now use ftp_ssl_connect and while it can open the connection and login, it fails to transfer the files.
This is the error I get from the ftp_put operation:
"Warning: ftp_put(): Unable to build data connection: Operation not permitted in....."
Could this be a firewall issue? The server is an EC2 instance.
Paddy
I ran into the exact same problem today. Using
ftp_pasv($conn_id, true);
to enforce passive transfers before the actual call to ftp_put() solved the problem for me.
I recently downloaded and installed "PHP for Android." I created a .php file that utilizes an SSL connection with port 2195. I followed a guide for writing a php server that sends push notifications to Apple's APNS, and SUCCESSfully ran it on my Mac. When I put both the .php and the .pem onto my Android phone in the same folder and tried to run it with the same WIFI connection, I get the following error message:
Error:14094410:SSL routines:func(148):reason(1040) in /mnt/sdcard/sl4a/scripts/lot.php on line 19
Warning: stream_socket_client(): Failed to enable crypto in /mnt/sdcard/sl4a/scripts/lot.php on line 19
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /mnt/sdcard/sl4a/scripts/lot.php on line 19
Does anyone have any ideas of how I can fix this?
THANKS!
I had the SSL error on my Windows desktop, with a PHP script that accessed a HTTPS resource.
The solution was to enable the openssl extension. So maybe it's the same kind of problem you have here, something related to opensll on Php for Android.
I'm not sure how to fix it, but Google has it's own push notification framework. There is an example here: http://code.google.com/android/c2dm/
Edit to Answer:
I think that most likely the problem has to do with the certificates needed to make the call over SSL. It is possible that the PHP for Android app does not have permissions to access security certificates you need.
I'm having some problems with my PHP server. Most of the functions when run gives the same error.
Warning: fopen(http://www.ietf.org/rfc/rfc2475.txt) [function.fopen]: failed to open stream:
A connection attempt failed because the connected party did not properly respond after a
period of time, or established connection failed because connected host has failed to respond. D:\inetpub\vhosts\coolfbapps.in\httpdocs\test\merger2.php on line 3
Fatal error: Maximum execution time of 30 seconds exceeded in D:\inetpub\vhosts\coolfbapps.in\httpdocs\test\merger2.php on line 3
The same error comes when i use imagecreate functions, get_image functions.
I talked to service providers but they said I should tell them the cause of this error so that they can rectify it. Please se if any one can make out what changes should be done to server to remove those errors.
CODE USED
$ch = curl_init("http://www.gravatar.com/avatar/95111e2f99bb4b277764c76ad9ad3569?s=32&d=identicon&r=PG");
$fp = fopen("http://www.ietf.org/rfc/rfc2475.txt", "r");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Sorry for this, but I'm unable to comment yet. You need to post the code that is causing these errors. Are you explicitly requesting that URL?
To debug this, you should logon to the server and attempt to request the file to see if you're actually able to have outbound connections on port 80. To do this on a linux server just run
wget http://www.ietf.org/rfc/rfc2475.txt
.. and see if it fails or not. If it does, you need to talk to your hosting provider / ISP.
If you don't have access to the server you could simply try (in PHP):
<?php
file_get_contents('http://www.google.com/'); // Google so that it's not the same URL
?>
If there's an error, same as above.
The first error (the fopen() one) is caused because of a timeout in the response of the server you're trying to load the data from. i.e. the server is taking too long to respond, so the connection times out.
The second error is that the script is running for too long. PHP has a setting called max_execution_time so that a script can't eat up all the resources on a server. Your server has a setting to allow 30 seconds to execute, or die() with a fatal error.
Seems your server can't connect to these sites. Perhaps your server is not allowed to start outgoing connections or is blocking that outgoing HTTP traffic somehow?
I bet this isn't a PHP problem but instead has to do with your server connection. If you have SSH access, try to open these URLs from the command line without PHP.