define('URL', 'https://call-api.gradwell.com/0.9.3/call'); define('AUTH', '676ZPLS2ZXTY76IACG34399X76'); define('AUTHID', 103092); define('INTDEST', '2004400'); if (isset($_POST['phonenumber'])) { $phone = cmn_validate_phonenumber($_POST['phonenumber']); if ($phone) { # valid phone number, so make API request cmn_call($phone); } else { print '

Sorry, the phone number you entered is not permitted.

'; cmn_form(); } } else { cmn_form(); } function cmn_form() { print '

Call Me Now...

'; } function cmn_call($phone) { $Success = '

Thank you - we are calling you now.

'; $Error = '

Sorry, there was an error trying to call you.

'; $res = file(URL.'?getchallenge=1'); if (!preg_match('/^OK:(\w+)/', $res[0], $m)) { print $Error; return; } $url = URL.'?authid='.AUTHID.'&authresponse='.md5($m[1].AUTH).'&challenge='.$m[1].'&source='.$phone.'&destination='.INTDEST.'&callerid='.$phone; $res = file($url); if (preg_match('/^OK:/', $res[0])) print $Success; else print $Error; } function cmn_validate_phonenumber($phone) { $phone = preg_replace('/\D/', '', $phone); if (preg_match('/^01/', $phone)) return $phone; if (preg_match('/^02/', $phone)) return $phone; if (preg_match('/^03/', $phone)) return $phone; if (preg_match('/^075/', $phone)) return $phone; if (preg_match('/^077/', $phone)) return $phone; if (preg_match('/^078/', $phone)) return $phone; if (preg_match('/^079/', $phone)) return $phone; if (preg_match('/^08/', $phone)) return $phone; if (preg_match('/^05/', $phone)) return $phone; return false; }