0) { if ($user_code_from==0){ $sql=mysql_query("select ID,user_code from contest_nick where nick='$nick' and pwd='$password' limit 1"); if (mysql_num_rows($sql)) { $user_code_from=mysql_result($sql,0,"user_code"); $match=1; } else { $match=0; } } else{ $match=1; } if ($match==1){ $sql=mysql_query("select last_known_user_id,nick from contest_nick where user_code=$user_code_to limit 1"); if (mysql_num_rows($sql)) { $user_id_to=mysql_result($sql,0,"last_known_user_id"); $user_nick_to=mysql_result($sql,0,"nick"); $sql=mysql_query("select count(*) as ban_count from personal_ban where user_id_from=$user_id_to and user_id_to=$user_id limit 1"); $ban_count=mysql_result($sql,0,"ban_count"); if ($ban_count==0){ if ($user_id_to<>0){ $sql=mysql_query("insert into personal_chat (user_id_from,user_id_to,nick_from,nick_to,message) values ($user_id,$user_id_to,'$nick','$user_nick_to','$message')"); $sql=mysql_query("select reg_id from gcm where user_id=$user_id_to limit 1"); if (mysql_num_rows($sql)){ $dataArray = array('message'=>$message_gcm, 'user_code_from'=>$user_code_from, 'user_code_to'=>$user_code_to, 'user_nick_from'=>$nick, 'user_nick_to'=>$user_nick_to, 'type'=>'chat_personal'); $regidArray[0]=mysql_result($sql,0,"reg_id"); $headers = array( 'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI', 'Content-Type: application/json'); $fields = array( 'registration_ids' => $regidArray, 'data' => $dataArray); $context = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => $headers, 'content' => json_encode($fields)))); $response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context); $response=json_decode($response); if ($response->success==1) { print("ok"); } else { print("wrong"); } } else { print("usergone"); } } else { print("usergone"); } } else { print("banned"); } } else { print("wrong"); } } else { print("wrong"); } } else { print("wrong"); } mysql_close(); ?>