The ECP API uses basic HTTP authorization in order to establish a connection with clients. To establish a connection, the client needs to send an initial HTTP request containing the username and password. If authentication succeeded, the client will recieve a non-error HTTP response code and response message.
The initial HTTP login request can be either a GET request or a POST request.
Here is an example of how to establish a connection by sending a GET request.
<?php
//Basic connection parameters.
$base_url = '127.0.0.1';
$username='username';
$password='password';
//The cookie file used to store the session cookie.
$cookies_file='cookies.txt';
//Initialize the client object.
$client = curl_init();
//Do some basic client configuration. We need to be able to read cookies
//from a file. Since we are authenticating to initialize a connection,
//we don't necessarily care about the response body.
curl_setopt($client, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($client, CURLOPT_COOKIEFILE, $cookies_file);
curl_setopt($client, CURLOPT_COOKIEJAR, $cookies_file);
curl_setopt($client, CURLOPT_HEADER, 1);
curl_setopt($client, CURLOPT_NOBODY, 1);
//Initialize the authentication GET URL including authentication parmeters.
curl_setopt($client, CURLOPT_URL, $base_url."?user_name=$username&password=$password&login=Login");
//Send the request and initialize the response code.
$http_response = curl_exec($client);
$http_response_code = curl_getinfo($client, CURLINFO_HTTP_CODE);
//Close the connection.
curl_close($client);
//Test the result of the authentication attempt.
if ($http_response_code==401 || $http_response_code==0){
echo "Authentication failed.";
}
else{
echo "Authentication sucessful.";
}
?>