예제 #1
0
function setResponse($statusCode, $message)
{
    setResponseCode($statusCode);
    echo "Conversion failed. Error log: \n";
    // Should be formatted output
    echo htmlspecialchars($message);
}
예제 #2
0
function output($data, $code = 200, $callback = '')
{
    $data = json_encode($data);
    if (empty($callback)) {
        // set content type header to json
        header('Content-Type: application/json');
    } else {
        // set content type header to script
        header('Content-Type: text/javascript');
        // wrap data in callback function
        $data = $callback . '(' . $data . ');';
    }
    setResponseCode($code);
    exit($data);
}
예제 #3
0
        $prep->bind_result($fromdb_visitor_uid_page_category_recommendation, $fromdb_visitor_uid_page_category_recommendation_count);
        $prep->fetch();
        $fromdb_affected_rows = $prep->num_rows;
        $prep->close();
        if ($fromdb_affected_rows > 0) {
            $system_allgood = TRUE;
        } else {
            $system_allgood = FALSE;
        }
    }
    // Prepare output
    if ($system_allgood == TRUE) {
        setResponseCode($response, 200);
        if (isset($fromdb_visitor_ip_page_category_recommendation) && !empty($fromdb_visitor_ip_page_category_recommendation)) {
            pushResponseData($response, 'site_log_v_ip_p_cat_recommendation', $fromdb_visitor_ip_page_category_recommendation);
        }
        if (isset($fromdb_visitor_uid_page_category_recommendation) && !empty($fromdb_visitor_uid_page_category_recommendation)) {
            pushResponseData($response, 'site_log_v_uid_p_cat_recommendation', $fromdb_visitor_uid_page_category_recommendation);
        }
    } else {
        setResponseCode($response, 400);
        pushResponseError($response, 'No rows returned.');
    }
} else {
    setResponseCode($response, 400);
    pushResponseError($response, 'No input was given.');
}
// Close the database connection
$db_con->close();
// Output response
outputResponse($response);