Skip to content

Instantly share code, notes, and snippets.

@caironm
Created September 29, 2019 14:34
Show Gist options
  • Save caironm/89844e4c3d06f667b360db7cabe6df28 to your computer and use it in GitHub Desktop.
Save caironm/89844e4c3d06f667b360db7cabe6df28 to your computer and use it in GitHub Desktop.
Abilitando put e delete
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
$_PUT = array();
if (!strcasecmp($_SERVER['REQUEST_METHOD'], 'PUT')) {
parse_str(file_get_contents('php://input'), $_PUT);
}
$_DELETE = array();
if (!strcasecmp($_SERVER['REQUEST_METHOD'], 'DELETE')) {
parse_str(file_get_contents('php://input'), $_DELETE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment