本文整理汇总了PHP中sendResponse函数的典型用法代码示例。如果您正苦于以下问题:PHP sendResponse函数的具体用法?PHP sendResponse怎么用?PHP sendResponse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sendResponse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateImageFile
function validateImageFile()
{
$isValid = true;
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["picToUpload"]["tmp_name"]);
if ($check !== false) {
$isValid = true;
} else {
sendResponse('INVALID_IMAGE', 'error');
$isValid = false;
return $isValid;
}
// Check file size
if ($_FILES["picToUpload"]["size"] / 1024 / 1024 > 5) {
sendResponse('FILE_SIZE_EXCEEDED', 'error');
$isValid = false;
return $isValid;
}
// Allow certain file formats
$imageFileType = $check["mime"];
if ($imageFileType != "image/jpg" && $imageFileType != "image/png" && $imageFileType != "image/jpeg" && $imageFileType != "image/gif") {
sendResponse('UNSUPPORTED_IMAGE_FORMAT', 'error');
$isValid = false;
return $isValid;
}
return $isValid;
}
示例2: onErrorResponseFromHandlers
function onErrorResponseFromHandlers($response)
{
//
// transfer some fields from the request to the response
//
print "got a response from a handler";
sendResponse($response);
}
示例3: sanitizeResult
function sanitizeResult($result, $code = 200)
{
if (count($result) > 0) {
sendResponse($code, json_encode($result));
return true;
} else {
sendResponse($code, json_encode("ERROR"));
return true;
}
}
示例4: listar
function listar()
{
require "../models/imagen.php";
$img = new Imagen();
if ($imagenes = $img->getAll()) {
sendResponse(array("error" => false, "mensaje" => "", "data" => $imagenes));
} else {
sendResponse(array("error" => true, "mensaje" => "Error al obtener imágenes"));
}
}
示例5: obtenerCantidadTweets
function obtenerCantidadTweets($request)
{
require "../models/comentario.php";
$c = new Comentario();
$id = $request->id;
if ($cantidad = $c->getCantidad($id)) {
sendResponse(array("error" => false, "mensaje" => "", "data" => $cantidad));
} else {
sendResponse(array("error" => true, "mensaje" => "Error al obtener la cantidad de tweets."));
}
}
示例6: addData
function addData($name, $detail, $price, $qty)
{
$conn = connectDB("localhost", "root", "root", "dbData");
if (!$conn) {
sendResponse("error", "เกิดปัญหาในการติดต่อฐานข้อมูล");
return;
}
$sql = "insert into products (id, name, detail, price, qty) values ('', '{$name}','{$detail}', {$price}, \n{$qty})";
mysqli_query($conn, $sql) or die(sendResponse("error", "บันทึกข้อมูลไม่ได้") . $sql);
sendResponse("success", "บันทึกข้อมูลเรียบร้อยแล้ว");
$sqlStr = "select * from products order by id asc";
$qry = mysqli_query($conn, $sqlStr) or die(sendResponse("error", "ไม่พบข้อมูล"));
?>
<table width="600" border="1" cellspacing="2" cellpadding="5">
<tr>
<td>รหัสสินค้า</td>
<td>ชื่อสินค้า</td>
<td>รายละเอียด</td>
<td>ราคา</td>
<td>จ านวน</td>
</tr>
<?php
while ($rs = mysqli_fetch_array($qry)) {
?>
<tr>
<td><?php
echo $rs["id"];
?>
</td>
<td><?php
echo $rs["name"];
?>
</td>
<td><?php
echo $rs["detail"];
?>
</td>
<td><?php
echo $rs["price"];
?>
</td>
<td><?php
echo $rs["qty"];
?>
</td>
</tr>
<?php
}
mysqli_close($conn);
}
示例7: gps_tracker_update
function gps_tracker_update()
{
$mysql_host = "mysql6.000webhost.com";
$mysql_database = "a8399093_gps";
$mysql_user = "a8399093_anoj";
$mysql_password = "anoj123";
if (isset($_POST["atti"]) && isset($_POST["lon"]) && isset($_POST['user'])) {
try {
$ati = $_POST["atti"];
$lon = $_POST["lon"];
$meUserid = $_POST['user'];
$meAtti = sprintf("%01.4f", $ati);
$meLon = sprintf("%01.4f", $lon);
$mysqli = new mysqli($mysql_host, $mysql_user, $mysql_password, $mysql_database);
if (mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit;
}
/* Create a prepared statement */
$sql = "INSERT INTO location (time , user_id ,atti, lon) VALUES (NOW(),?,?,?)";
$message = "";
$stmt = $mysqli->prepare($sql);
//$message .= $stmt . " ";
if ($stmt) {
/* Bind parameters
s - string, b - boolean, i - int, etc */
$stmt->bind_param('idd', $meUserid, $meAtti, $meLon);
/* Execute it */
$stmt->execute();
$message .= "updated";
/* Close statement */
$stmt->close();
} else {
/* Error */
printf("Prepared Statement Error: %s\n", $mysqli->error);
}
/* Close connection */
$mysqli->close();
//mysql_close($con);
$message .= $meAtti . " " . $meLon . " " . $meUserid;
//mail('dewmalnilanka@gmail.com', '$subject', $message);
sendResponse(200, $message);
return true;
} catch (Exception $e) {
$err = 'Caught exception: ' . $e->getMessage() . "\n";
sendResponse(200, $err);
return false;
}
}
sendResponse(400, 'Invalid request');
return false;
}
示例8: getUser
function getUser()
{
$db = getDB();
$app = Slim::getInstance();
// used for degugging if desired.
$startTime = time();
$results = Users::getUser($db);
if (!$results) {
return;
}
// User ID is private so don't send it back to the client
unset($results->user_id);
sendResponse($results, $startTime);
}
示例9: processUploadFile
function processUploadFile()
{
$uploadFolder = 'cache/uploads/';
if (!empty($_FILES)) {
if (!file_exists($uploadFolder)) {
@mkdir($uploadFolder);
}
$tempFile = $_FILES['file']['tmp_name'];
$uploadedFile = $uploadFolder . md5($_FILES['file']['tmp_name']);
move_uploaded_file($tempFile, $uploadedFile);
sendResponse(array('success' => true, 'uploadFilename' => $uploadedFile, 'originalFilename' => $_FILES['file']['name']), false);
} else {
sendResponse('error', true);
}
}
示例10: checkToken
function checkToken()
{
$app = \Slim\Slim::getInstance();
$token = $app->request->headers->get('token');
$app = \Slim\Slim::getInstance();
if ($token) {
$db = new dbHandler();
if ($db->isValidToken($token)) {
return true;
} else {
sendResponse(401, initBody(true, "Bad token"), null);
$app->stop();
}
} else {
sendResponse(401, initBody(true, "Token is missing"), null);
$app->stop();
}
}
示例11: gps_tracker_login
function gps_tracker_login()
{
$mysql_host = "mysql6.000webhost.com";
$mysql_database = "a8399093_gps";
$mysql_user = "a8399093_anoj";
$mysql_password = "anoj123";
if (isset($_POST["email"]) && isset($_POST["password"])) {
try {
$con = mysql_connect($mysql_host, $mysql_user, $mysql_password);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($mysql_database, $con);
$email = $_POST["email"];
$password = $_POST["password"];
$sql = "SELECT * FROM user WHERE email='{$email}' and password='{$password}'";
//echo $sql;
$result = mysql_query($sql);
//echo $result;
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
$message = NULL;
if ($count == 1) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$message = $row['id'];
} else {
$message = "Wrong Username or Password";
}
//mail('dewmalnilanka@gmail.com', '$subject', $message);
sendResponse(200, $message);
return true;
} catch (Exception $e) {
$err = 'Caught exception: ' . $e->getMessage() . "\n";
sendResponse(200, $err);
return false;
}
}
sendResponse(400, 'Invalid request');
return false;
}
示例12: doWork
function doWork()
{
try {
if (!isset($_POST["operation"])) {
$result = array("response" => 'failure', "error" => 'Invalid request. No operation given.', "POST" => $_POST);
sendResponse(400, json_encode($result));
return false;
}
$op = $_POST["operation"];
//check which method we want to call
if ($op == "testConnection") {
return $this->testConnection();
}
switch ($op) {
case "login":
// do some stuff
if (login($db, $_POST['username'], $_POST['userID']) == 200) {
$result = array("response" => 'User created!');
sendResponse(200, json_encode($result));
return true;
} else {
$result = array("response" => 'Server error: unable to create user');
sendResponse(500, json_encode($result));
return true;
}
break;
default:
break;
}
$result = array("response" => 'Invalid request. Not a valid operation.');
sendResponse(400, json_encode($result));
return false;
} catch (Exception $e) {
$error = array("response" => 'failure', "message" => 'Server exception: ' . $e->getMessage());
sendResponse(500, json_encode($error));
return false;
}
}
示例13: sendResponse
//Take and validate input param only accepting integers between 1 and 3999
if (!($input = filter_input(INPUT_GET, 'input', FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 3999))))) {
//Set HTTP response
$response['code'] = 3;
$response['status'] = $apiResponseCodes[$response['code']]['HTTP Response'];
$response['message'] = $apiResponseCodes[$response['code']]['Message'];
$response['result'] = NULL;
//Send response to browser
sendResponse($response);
}
$response['code'] = 1;
$response['status'] = $apiResponseCodes[$response['code']]['HTTP Response'];
$response['message'] = $apiResponseCodes[$response['code']]['Message'];
$response['result'] = $oConverter->generate($input);
} elseif (strcasecmp($action, 'parse') == 0) {
//Take and validate input param only accepting valid roman numbers
if (empty($_GET['input']) || !($input = filter_input(INPUT_GET, 'input', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/'))))) {
$response['code'] = 4;
$response['status'] = $apiResponseCodes[$response['code']]['HTTP Response'];
$response['message'] = $apiResponseCodes[$response['code']]['Message'];
$response['result'] = NULL;
} else {
$response['code'] = 1;
$response['status'] = $apiResponseCodes[$response['code']]['HTTP Response'];
$response['message'] = $apiResponseCodes[$response['code']]['Message'];
$response['result'] = $oConverter->parse($input);
}
}
//Send response to browser
sendResponse($response);
示例14: json_decode
<?php
require 'class.db.php';
if (isset($_POST["values"]) && isset($_POST["type"]) && isset($_POST["interferer"]) && isset($_POST["flag"])) {
$values = json_decode($_POST["values"]);
$type = $_POST["type"];
$interferer = $_POST["interferer"];
$flag = $_POST["flag"];
if ($flag == "false") {
$interferer = "";
}
foreach ($values as $item) {
$update = array('interfereBy' => $interferer);
//Add the WHERE clauses
$where_clause = array('companyName' => $item);
$updated = $database->update('Transaction', $update, $where_clause);
}
sendResponse(200, json_encode(array('isSucceed' => $updated)));
} else {
// echo "FAILED";
sendResponse(200, json_encode(array('isSucceed' => false)));
}
示例15: substr
$aes = new \RNCryptor\Decryptor();
//Load the encrypted private key from hard drive
$filename = substr($userKey, -10) . ".txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
unlink($filename);
//Decrypt the private key
$privKey = $aes->decrypt($contents, substr($userKey, 0, 256));
//Decrypt the aes key with RSA and the private key
$rsa = new RSA('', $privKey);
$password = $rsa->decrypt($ePassword);
//Decrypt the data with the aes key and iv
$data = $aes->decrypt($eData, $password);
function getStatusCodeMessage($status)
{
$codes = parse_ini_file("codes.ini");
return isset($codes[$status]) ? $codes[$status] : '';
}
function sendResponse($status, $body = '', $content_type = 'text/html')
{
$status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status);
header($status_header);
header('Content-type: ' . $content_type);
echo $body;
}
sendResponse(201, '<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Success>Yes</Success>
<Data>' . $data . '</Data>
<Password>' . $password . '</Password>
</Root>');