<form method='post' action=''>
<input type="text" name="otp">
<input type="submit" name="totp">
</form>
<?php
if(isset($_POST['totp'])){
$api_key = "";
$client_id = "";
//$client_secret = "YOUR_CLIENT_SECRET";
$password = "";
$totp = $_POST['otp']; // If enabled
$state = "YOUR_STATE";
$client_local_ip = "YOUR_CLIENT_LOCAL_IP";
$client_public_ip = "YOUR_CLIENT_PUBLIC_IP";
$mac_address = "YOUR_MAC_ADDRESS";
// SmartAPI Login URL
$login_url = "https://apiconnect.angelone.in/rest/auth/angelbroking/user/v1/loginByPassword";
// Login Payload
$login_data = [
"clientcode" => $client_id,
"password" => $password,
"totp" => $totp,
"state" => $state
];
// Headers
$headers = [
"Content-Type: application/json",
"Accept: application/json",
"X-UserType: USER",
"X-SourceID: WEB",
"X-ClientLocalIP: $client_local_ip",
"X-ClientPublicIP: $client_public_ip",
"X-MACAddress: $mac_address",
"X-PrivateKey: $api_key"
];
// cURL Request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $login_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($login_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// Handle Response
$response_data = json_decode($response, true);
print_r($response_data); // Prints API response
}
?>
please help me how to do the login with MPIN