<HTML>
<HEAD>
<TITLE>GuestBook</TITLE>
<meta http-equiv=
"content-Type"
content=
"text/html"
charset=
"utf-8"
>
</HEAD>
<BODY BGCOLOR=
"#006699"
LINK=
"#99CCFF"
VLINK=
"#99CCCC"
TEXT=
"#FFFFFF"
>
<center>
<br><p>
<?
$apiKey =
"AIzaSyAwhIjAqve0UP91qse-iL6f41Vu1s6gMTg"
;
$message = $_POST[
'message'
];
echo("
<FORM name=
'form'
method=
'post'
action=
'$PHP_SELF'
>
<TABLE border=
'0'
cellspacing=
'1'
>
<TR>
<TD width=
'109'
bgcolor=
'#5485B6'
><P align=
'center'
><FONT face=
'굴림'
size=
'2'
color=
'#CDDAE4'
>
message</FONT></TD>
<TD width=
'541'
><P> <INPUT type=
'text'
name=
'message'
SIZE=
25
MAXLENGTHTH=
'20'
></TD>
</TR>
<TR>
<TD><P> </TD>
<TD><P> <INPUT type=
'submit'
name=
'submit'
value=
'sendMessage'
></TD>
</TR>
</TABLE>
<input type=hidden name=mode value=
'up'
>
</FORM>");
if
($mode ==
'up'
) {
$messageData = addslashes($message);
sendNotification($apiKey,$messageData);
}
function sendNotification( $apiKey, $messageData )
{
$headers = array(
'Content-Type:application/json ; charset=utf-8'
,
'Authorization:key=AIzaSyAwhIjAqve0UP91qse-iL6f41Vu1s6gMTg'
);
$connect = mysql_connect(
"165.229.88.50"
,
"ID"
,
"PASSWORD"
) or die(
"SQL server에 연결할 수 없습니다."
);
mysql_select_db(
"gcm"
,$connect);
$result = mysql_query(
"SELECT gcm_regid FROM gcm_users"
);
$conidx=
0
;
$arr = array();
$arr[
'data'
] = array();
$arr[
'data'
][
'msg'
] = $messageData;
$arr[
'registration_ids'
] = array();
while
($row = mysql_fetch_array($result))
{
$arr[
'registration_ids'
][$conidx] = $row[
'reg_id'
] ;
$conidx++;
}
mysql_close($connect);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST,
true
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false
);
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($arr));
$response = curl_exec($ch);
echo $response;
curl_close($ch);
}
echo("
<p>
</BODY>
</HTML>");
?>