本文整理汇总了PHP中setXsrfCookie函数的典型用法代码示例。如果您正苦于以下问题:PHP setXsrfCookie函数的具体用法?PHP setXsrfCookie怎么用?PHP setXsrfCookie使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setXsrfCookie函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connectToEncryptedMySql
//grab the mySQL connection
$pdo = connectToEncryptedMySql("/etc/apache2/capstone-mysql/timecrunch.ini");
//if the user session is empty, the user is not logged in, throw an exception
if (empty($_SESSION["user"]) === true) {
setXsrfCookie("/");
throw new RuntimeException("Please log-in or sign up", 401);
}
//determine which HTTP method was used
$method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
$reply->method = $method;
//sanitize the id
$id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
//Handle REST calls
if ($method === "GET") {
//Set XSRF cookie
setXsrfCookie("/");
//Get Request based on given field
if (empty($id) === false) {
$request = Request::getRequestByRequestId($pdo, $id);
if ($request !== null) {
$reply->data = $request;
}
} else {
$request = Request::getAllRequests($pdo);
if ($request !== null) {
$reply->data = $request;
}
}
} elseif ($method === "PUT" || $method === "POST") {
$requestContent = file_get_contents("php://input");
$requestObject = json_decode($requestContent);
示例2: dirname
<?php
require_once dirname(__DIR__) . "/lib/xsrf.php";
/**
* simple controller simply for handing out an xsrf token when booting the mobile app
*
* @author Bradley Brown tall.white.ninja@gmail.com
*/
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
setXsrfCookie('/');
示例3: session_start
**/
// verify the session, start if not active
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;
try {
$pdo = connectToEncryptedMySQL("/etc/apache2/encrypted-config/ng-abq-dev.ini");
$method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
$id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
$profileId = filter_input(INPUT_GET, "profileId", FILTER_VALIDATE_INT);
if ($method === "GET") {
//set XSRF cookie
setXsrfCookie();
if (empty($id) === false) {
$event = Beta\Event::getEventByEventId($pdo, $id);
if ($event !== null) {
$reply->data = $event;
}
} else {
if (empty($profileId) === false) {
$events = Beta\Event::getEventByEventProfileId($pdo, $profileId)->toArray();
if ($events !== null) {
$reply->data = $events;
}
} else {
$events = Beta\Event::getAllEvents($pdo)->toArray();
if ($events !== null) {
$reply->data = $events;