<?php
// URLs of iTunesconnect.
$urlBase = 'https://itts.apple.com';
$urlWebsite = $urlBase . '/cgi-bin/WebObjects/Piano.woa';
// function to check finance role acounts validity. This function return true is the detail is still valid.
function isAccountValid($username, $password) {
global $urlBase, $urlWebsite;
$html = curlRequest($urlWebsite, null); // First cURL request to get the login form
preg_match('/" action=".*"/', $html, $matches); // Search the form action URL because all URLs are dynamic
$urlActionLogin = $urlBase . substr($matches[0], 10, -1);
$postData = array('theAccountName' => $username, 'theAccountPW' => $password, '1.Continue.x' => '1', '1.Continue.y' => '1'); // Creating the form POST data
$html = curlRequest($urlActionLogin, $postData); // Second cURL request with form data for login
if (strpos($html, 'Report Options') === false) { // If the return HTML contain 'Report Options' text then its successful login
return false;
}
return true;
}
// function send the curl request on given URL with post variables and return the html output
function curlRequest($url, $postVars) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if (!is_null($postVars)){
curl_setopt($ch, CURLOPT_POST, count($postVars));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postVars));
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$html = curl_exec($ch);
if (curl_errno($ch)) {
die(curl_error($ch));
}
curl_close($ch);
return $html;
}
// Examples 01
if (isAccountValid('anil@test.com', 'test@anil')) {
echo "anil@test.com account is valid.<br/>";
}
else {
echo "anil@test.com account is not valid.<br/>";
}
// Examples 02
if (isAccountValid('invalid_address@test.com', 'wrong_password')) {
echo "invalid_address@test.com account is valid.<br/>";
}
else {
echo "invalid_address@test.com account is not valid.<br/>";
}
?> |