2013-09-27 01:38:44 +02:00
|
|
|
<?php
|
|
|
|
|
2013-09-27 12:31:55 +02:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] != "POST") {
|
|
|
|
$response = array( "status" => "error",
|
|
|
|
"msg" => "'signin' can only be accessed with the POST method");
|
|
|
|
exit(json_encode($response));
|
|
|
|
}
|
2013-09-27 01:38:44 +02:00
|
|
|
|
|
|
|
require 'connect.php';
|
|
|
|
|
|
|
|
if(!isset($_POST['localip'])) echo "missing localip </br>";
|
|
|
|
$localip = $_POST['localip'];
|
|
|
|
|
|
|
|
if(!isset($_POST['wifiboxid'])) echo "missing wifiboxid </br>";
|
|
|
|
$wifiboxid = $_POST['wifiboxid'];
|
|
|
|
|
|
|
|
$remoteip = getenv('REMOTE_ADDR');
|
|
|
|
|
|
|
|
$timestamp = time();
|
|
|
|
|
|
|
|
$id = $remoteip.'/'.$wifiboxid;
|
2013-09-27 12:31:55 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$statement = $db->prepare( "REPLACE INTO $table " .
|
|
|
|
"SET id = :id, " .
|
|
|
|
" remoteip = :remoteip, " .
|
|
|
|
" localip = :localip, " .
|
|
|
|
" wifiboxid = :wifiboxid, " .
|
|
|
|
" date = FROM_UNIXTIME(:timestamp)");
|
|
|
|
$statement->execute(array( ":id" => $id,
|
|
|
|
":remoteip" => $remoteip,
|
|
|
|
":localip" => $localip,
|
|
|
|
":wifiboxid" => $wifiboxid,
|
|
|
|
":timestamp" => $timestamp));
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
$response = array( "status" => "error",
|
|
|
|
"msg" => $e->getMessage()." (".$e->getCode().")");
|
|
|
|
exit(json_encode($response));
|
|
|
|
}
|
|
|
|
|
|
|
|
$responseData = array( "remoteip" => $remoteip,
|
|
|
|
"localip" => $localip,
|
|
|
|
"wifiboxid" => $wifiboxid,
|
|
|
|
"timestamp" => $timestamp);
|
|
|
|
$response = array( "status" => "success",
|
|
|
|
"data" => $responseData);
|
|
|
|
exit(json_encode($response));
|
2013-09-27 01:38:44 +02:00
|
|
|
|
|
|
|
// Remove old signins
|
|
|
|
$hourago = time() - 60*60;
|
2013-09-27 12:31:55 +02:00
|
|
|
try {
|
|
|
|
$statement = $db->prepare("DELETE FROM $table WHERE date < FROM_UNIXTIME(:hourago)");
|
|
|
|
$statement->execute(array( ':hourago' => $hourago));
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
$response = array( "status" => "error",
|
|
|
|
"msg" => $e->getMessage()." (".$e->getCode().")");
|
|
|
|
exit(json_encode($response));
|
|
|
|
}
|
2013-09-27 01:38:44 +02:00
|
|
|
?>
|