"; $API['VERSION'] = "1.03"; if(isset($_REQUEST['Login'])) { get_FriendsList(); } else if(isset($_REQUEST['startNew'])) { $arrArgs['mobile'] = $_REQUEST['mobile']; $arrArgs['password'] = create_md5password($_REQUEST['mobile'],$_REQUEST['password']); if(isset($_REQUEST['friend_id'])) { foreach($_REQUEST['friend_id'] as $key => $value) { $arrArgs['friend_id['.$key.']'] = $value; } } $arrArgs['message'] = $_REQUEST['message']; $arrArgs['method'] = "3jam.conversations.startNew"; $result = send_to_server($arrArgs); if(preg_match("//",$result)) { display_3jam_started(); } else { //Error found so re-display form and error preg_match("/msg=\"(.*)\"/",$result,$matches); $sErrorMsg = $matches[1]; get_FriendsList($sErrorMsg); } } else { display_login(); } function send_to_server($arrArgs) { global $API; //Set API Version number $arrArgs['api_version'] = $API['VERSION']; //Set API URL $url = "https://api.3jam.com/webapi.php"; //Set authentication keys $arrArgs['api_key'] = $API['KEY']; $creq = curl_init(); curl_setopt($creq, CURLOPT_URL, $url); curl_setopt($creq, CURLOPT_TIMEOUT, 20); //set timeout in case other side hangs, which won't return for a while curl_setopt($creq, CURLOPT_RETURNTRANSFER, 1); curl_setopt($creq, CURLOPT_POST,1); curl_setopt($creq, CURLOPT_POSTFIELDS, $arrArgs); curl_setopt($creq, CURLOPT_SSL_VERIFYPEER, FALSE); //Turn off certificate verification so Curl works $curl_result = curl_exec($creq); if(curl_errno($creq)) { //If there's a problem with Curl on your machine print "Curl error on local machine: ".curl_error($creq); } return $curl_result; } function get_FriendsList($sSelectFriendsErrorMsg='') { $arrArgs['mobile'] = $_REQUEST['mobile']; $arrArgs['password'] = create_md5password($_REQUEST['mobile'],$_REQUEST['password']); $arrArgs['method'] = "3jam.friends.getList"; $result = send_to_server($arrArgs); if(preg_match("//",$result)) { display_friendList($result,$sSelectFriendsErrorMsg); } else { //Error found so re-display form and error preg_match("/msg=\"(.*)\"/",$result,$matches); $sErrorMsg = $matches[1]; display_login($sErrorMsg); } } function display_login($sErrorMsg='') { $html = '

Log in to your 3jam account:

'.($sErrorMsg == '' ? '' : ''.$sErrorMsg.'').' '; print $html; } function display_friendList($result,$sErrorMsg='') { preg_match_all("/'.$sErrorMsg.''); $html .= '
'; $html .= '
Mobile number:Password:
  Need an account / password?
'; $html .= ''; $count = 1; foreach($matches as $eachmatch) { $html .= ''; $html .= ''; $html .= ''."\n"; } $html .= '
Select friend
'.$eachmatch[2].'
'; $html .= ''; $html .= '
'; $html .= '
'; print $html; } function display_3jam_started() { $html = '

3jam started!

Click here to start another.'; print $html; } function create_md5password($mobile,$password) { return md5($mobile.$password); } ?>