I have two server(say server1 and server2). There is a login panel on server1, if I login using server1 then I need to redirect to server2.
Here is the curl code I have:
Sample Curl request
curl -X POST -H "user_name: aaa" -H "auth_type: email" -H "app_key: someapikey" -H "platform: Android_MDA" -H "password: 123456" -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d '' "here is server1 login url"
How can implement this using PHP.
Here is what I had done so far:
<?php
$post_fields = '{"login": "aaa", "password": "123456"}';
$cookie_file = tempnam('/temp', 'cookie');
$ch = curl_init('here is server1 login url');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
// Execute request and read response
$response = curl_exec($ch);
// Check errors
if ($response) {
echo $response . "
";
} else {
$error = curl_error($ch). '(' .curl_errno($ch). ')';
echo $error . "
";
}
// Close connection
curl_close($ch);
?>
Response I get: Failed to connect to server1(i.e the url Iam using): Connection timed out(7)