<?php
function cURLops ( $method, $SSL, $url, $data, $headers )
{
$ch = curl_init();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 5 ); // 5 saniye boyunca bağlantı kuralmaması durumunda bağlantıyı kes
curl_setopt ( $ch, CURLOPT_HEADER, TRUE );
if ( $method == "GET" )
{
curl_setopt ( $ch, CURLOPT_POST, FALSE );
curl_setopt ( $ch, CURLOPT_FRESH_CONNECT, TRUE );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
}
else if ( $method == "POST" )
{
curl_setopt ( $ch, CURLOPT_POST, TRUE );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
}
else
{
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, $method );
curl_setopt ( $ch, CURLOPT_FRESH_CONNECT, TRUE );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
}
// SSL sertifikasını devre dışı bırakmak için bu alan kullanıyor curl.exe de -k parameteresine denk
if ( $SSL == FALSE )
{
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
}
else
{
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, TRUE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, TRUE );
}
$response = curl_exec ( $ch );
if( $response == NULL )
{
return json_encode
(
array
(
"Response"=>"Error",
"MSG"=>"Error: " . curl_error ( $ch ) . " - Code: " . curl_errno ( $ch )
)
);
}
else
{
return json_encode
(
array
(
"Header"=>HeaderFormater ( substr ( $response, 0, curl_getinfo ( $ch, CURLINFO_HEADER_SIZE ) ) ),
"Response"=> json_decode ( substr ( $response, curl_getinfo ( $ch, CURLINFO_HEADER_SIZE ) ) )
)
);
}
curl_close ( $ch );
}
function HeaderFormater ( $headerText )
{
$headers = array();
$lines = explode ( "\n", $headerText );
foreach ( $lines as $line )
{
if ( trim ( $line ) === '' )
{
continue;
}
if ( preg_match ( '/^HTTP\/\d+\.\d+\s+\d+\s+.+$/', $line ) )
{
// Status line, ignore
continue;
}
$parts = explode ( ':', $line, 2 );
if ( count ( $parts ) < 2 )
{
continue;
}
list ( $key, $value ) = explode ( ':', $line, 2 );
if ( $key === NULL OR $value === NULL )
{
continue;
}
$headers[ trim ( $key ) ] = trim ( $value );
}
$parsedHeadersObj = (object) $headers;
return $parsedHeadersObj;
}
$LoginStatus = json_decode
(
cURLops
(
"POST",
FALSE,
"https://durukanbal.com/api/token",
json_encode
(
array
(
"email"=>"Username",
"password"=>"şifres123"
)
),
array
(
'accept: application/json',
'Content-Type: application/json'
)
)
);
print_r( $LoginStatus );
?>
Categories: PHP language
7 Comments
Kaufen Sie die Cannabissorte Blue Cheese online in Essen Nordrhein-Westfalen Deutschland · 30/10/2024 at 21:52
… [Trackback]
[…] Read More on that Topic: durukanbal.com/2023/04/14/php-curl-basic-function/ […]
โรงงานผลิตสายรัดพลาสติก · 07/11/2024 at 05:46
… [Trackback]
[…] Find More to that Topic: durukanbal.com/2023/04/14/php-curl-basic-function/ […]
som777 · 12/11/2024 at 21:55
… [Trackback]
[…] Info to that Topic: durukanbal.com/2023/04/14/php-curl-basic-function/ […]
jaxx download · 14/11/2024 at 09:49
… [Trackback]
[…] Read More to that Topic: durukanbal.com/2023/04/14/php-curl-basic-function/ […]
เว็บพนันออนไลน์เกาหลี · 20/11/2024 at 02:04
… [Trackback]
[…] Info to that Topic: durukanbal.com/2023/04/14/php-curl-basic-function/ […]
Nexus Market Exit Scam · 23/11/2024 at 17:08
… [Trackback]
[…] Info to that Topic: durukanbal.com/2023/04/14/php-curl-basic-function/ […]
pgslot168 · 04/12/2024 at 08:41
… [Trackback]
[…] Read More to that Topic: durukanbal.com/2023/04/14/php-curl-basic-function/ […]