<?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

1,515 Comments

https://videomesum.site · 27/01/2024 at 08:13

Do you have a spam problem on this site; I also am a blogger, and
I was curious about your situation; many of us have developed some
nice methods and we are looking to swap techniques with other folks, please shoot me an e-mail if interested.

https://forumbokep.ornop.org · 27/01/2024 at 08:34

This site really has all the information and facts I needed about this subject and didn’t know who to ask.

https://kimcil.site · 27/01/2024 at 08:41

Your style is so unique compared to other people I have read stuff from.
Thanks for posting when you’ve got the opportunity, Guess I will just book
mark this page.

forumbb21.com · 27/01/2024 at 08:52

Hi there, I discovered your website by the use of Google at the same time as looking
for a comparable matter, your web site came up, it
seems good. I’ve bookmarked it in my google bookmarks.

Hello there, just become alert to your blog thru Google, and found that it is really informative.
I am going to watch out for brussels. I will be grateful
for those who proceed this in future. A lot of other folks will likely
be benefited from your writing. Cheers!

forum lendir semprot · 27/01/2024 at 09:13

I read this piece of writing completely concerning the difference of most recent and preceding technologies, it’s
awesome article.

Gloriat · 27/01/2024 at 09:18

Cool website. There is a suggestion https://zetds.seychellesyoga.com/info

Leave a Reply

Avatar placeholder