error when using cURL - php

Trying to access the URL https://memphis.ulbranet.com.br/ALEPH/ using cURL in PHP, but it presents the following error:
bool (false) string (80) "error: 14077417: SSL routines: SSL23_GET_SERVER_HELLO: SSLv3 alert illegal parameter"
Anyone know why?
<?php
ini_set( 'display_errors' , true );
error_reporting( E_ALL );
$curl = curl_init();
curl_setopt( $curl , CURLOPT_URL , 'https://memphis.ulbranet.com.br/ALEPH/' );
curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true );
curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER , false );
var_dump( curl_exec( $curl ) , curl_error( $curl ) );

I'm not sure whether this is a bug in CURL, an incorrectly formatted SSL setup or a version compatibility - but you can fix it by telling CURL to use SSL version 3:
curl_setopt($ch, CURLOPT_SSLVERSION, 3);

Related

PHP Request failed on SSL

Hello I would like to get some data from a url. I already tried to make a request through the console, postman, browset - all of them worked correctly. But if I make a request using php (guzzle, symfony http client) it fails on SSL. Does anybody know how to get response from this url by curl? Thanks!
Please try the following code ( That's worked for me ):
<?php
function curl( $url, $data = array(), $headers = array(), $ssl_required = false ) {
$handle = curl_init( $url );
curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
// Set post data if exist
if ( !empty( $data ) ) {
curl_setopt( $handle, CURLOPT_POST, true );
curl_setopt( $handle, CURLOPT_POSTFIELDS, $data );
}
// Set custom headers if exist
if ( count( $headers ) )
curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers );
// If url was ssl, need to true
if ( $ssl_required )
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec( $handle );
curl_close( $handle );
return $output;
}
echo curl("https://www.skroutz.gr/c/900/fakoi-epafhs.json");

file_get_content not working for https in php

Has anybody had an issue with display content from a website thats over https? The code was working until all the sites on server got ssl. maybe something to so with the certificate being tlss 1.2? So the site im trying to do this from has this certificate now.
$data = file_get_contents('https://www.ladygaga.com/');
echo $data;
According to php.net
When using SSL, Microsoft IIS will violate the protocol by closing the
connection without sending a close_notify indicator. PHP will report
this as "SSL: Fatal Protocol Error" when you reach the end of the
data. To work around this, the value of error_reporting should be
lowered to a level that does not include warnings. PHP can detect
buggy IIS server software when you open the stream using the https://
wrapper and will suppress the warning. When using fsockopen() to
create an ssl:// socket, the developer is responsible for detecting
and suppressing this warning.
Source link
Based on OpenSSL changes in PHP 5.6, try this:
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$response = file_get_contents("https://www.ladygaga.com/", false, stream_context_create($arrContextOptions));
echo $response;
Another option would be to use curl as such:
function file_get_contents_curl( $url ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
$data = curl_exec( $ch );
curl_close( $ch );
return $data;
}
$data = file_get_contents_curl("https://www.ladygaga.com");

PHP get request returning false

$data = file_get_contents("http://randomword.setgetgo.com/get.php");
var_dump($data);
I keep getting false when sending this get request, anyone have an idea why?
It works just fine with a simple php script I wrote hosted from the same domain, might that be the issue, how do I go about sending a get request to this API if that is the case?
I tried using curl as well with the same result. It works with my test script but not the API.
As noted in the various comments above, the code originally posted works fine for me but not for the OP - most likely due to a restriction placed upon various standard PHP functions by the webhost. As an alternative, cURL should be able to retrieve the content unless a similar restriction has been placed on standard curl functions too.
$url='http://randomword.setgetgo.com/get.php';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_USERAGENT, 'curl-wordfetcher' );
$result = curl_exec( $ch );
if( curl_errno( $ch ) ) echo 'Curl error: ' . curl_error( $ch );
curl_close( $ch );
print_r( $result );

Google Cloud Messaging Push Notifications only work once (PHP, Android)

I am having trouble getting Google Cloud Messaging for Android working.
I have had it working before but it decides to stop working after the first couple of times.
In order to get it working again I have to delete my API key and recreate it.
I am using PHP with a SERVER API key with a IP whitelist of ::/0 (All IPv6 apparently)
Note: My android app requests a device message key each time the app is opened (Usually returns the same message key)
The Error I get is: Unauthorized Error 401
When I got to the following url to check my app message id i get 'invalid token'.
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=APA91bHuQEWGsvlRUhlSztNpqLVOZQGZPiGFHjQw2plcF-z8t29zvNNgNoDiRe-CbY9Fb-XcPQAFqJvy4HBfWTrTPPpzcY3pd5vX38WGalOsZ5iDiJeglpafLTC7eFkN4UA9JPKWZ4lqNiGLoH3w8W_GpFAFW5F-kLLzcbrPxwSFqyfUpmM8-14
The PHP code I am using is:
$data = array( 'message' => 'Hello World!222!' );
$ids = array('APA91bHuQEWGsvlRUhlSztNpqLVOZQGZPiGFHjQw2plcF-z8t29zvNNgNoDiRe-CbY9Fb-XcPQAFqJvy4HBfWTrTPPpzcY3pd5vX38WGalOsZ5iDiJeglpafLTC7eFkN4UA9JPKWZ4lqNiGLoH3w8W_GpFAFW5F-kLLzcbrPxwSFqyfUpmM8-14');
$apiKey = 'AIzaSyATkp_UTZh....'; //obviously the complete key is used...
$url = 'https://android.googleapis.com/gcm/send';
$post = array('registration_ids' => $ids, 'data' => $data);
$headers = array( 'Authorization: key=' . $apiKey, 'Content-Type: application/json');
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
$result = curl_exec( $ch );
if ( curl_errno( $ch ) )
{
echo 'GCM error: ' . curl_error( $ch );
}
curl_close( $ch );
echo $result;
Thanks for any help given.
EDIT: It seems to work since I unregistered my device and reregistered it with GCM. I am not sure if this is a permanent fix but it works for now.

send Massive push notification to GCM

I have to send Push Notifications with different messages for large number of devices(More than 10k devices per day).But sometimes its not receiving all of the devices.I set up a function pushNotificationToUsers($heading,$message,$registraionids) to send the push notification and I am not sure about my method is correct ,if i am wrong please correct me.
function pushNotificationToUsers($heading,$message,$registraionids){
//array of registration ids in $registraionids
$key="xxxxxxxxxxx";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' =>,$registraionids,
'data' => array( "message" => $message,"title"=>$heading,"soundname"=>"beep.wav" ),
);
$headers = array(
'Authorization: key=' . $key,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
}
I'm using php in my serverside
For Android,
The message size limit in GCM is 4 kbytes.
https://developer.android.com/google/gcm/server.html#params
The message size limit in C2DM is 1024 bytes. (DEPRECATED)
https://developers.google.com/android/c2dm/#limitations
For iOS,
in iOS the size limit is 256 bytes, but since the introduction of iOS 8 has changed to 2kb!
https://forums.aws.amazon.com/ann.jspa?annID=2626
Also, see below stuffs
After Google replaced C2DM with GCM, they took off all limits.
http://developer.android.com/google/gcm/c2dm.html#history
The only limits you run into the GCM documentation is this:
http://developer.android.com/google/gcm/adv.html#lifetime
I think this answer is enough clear for your question.

Categories