Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php cors allow origin

header('Access-Control-Allow-Origin: *');

header('Access-Control-Allow-Methods: GET, POST');

header("Access-Control-Allow-Headers: X-Requested-With");
Comment

php Access-Control-Allow-Origin

header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
Comment

php header allow cross origin

/**
 *  An example CORS-compliant method.  It will allow any GET, POST, or OPTIONS requests from any
 *  origin.
 *
 *  In a production environment, you probably want to be more restrictive, but this gives you
 *  the general idea of what is involved.  For the nitty-gritty low-down, read:
 *
 *  - https://developer.mozilla.org/en/HTTP_access_control
 *  - http://www.w3.org/TR/cors/
 *
 */
function cors() {

    // Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        // Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
        // you want to allow, and if so:
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }

    // Access-Control headers are received during OPTIONS requests
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            // may also be using PUT, PATCH, HEAD etc
            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

        exit(0);
    }

    echo "You have CORS!";
}
Comment

php cors allow methods

HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE
Vary: Access-Control-Request-Headers
Access-Control-Allow-Headers: Content-Type, Accept
Content-Length: 0
Date: Fri, 05 Apr 2019 11:41:08 GMT
Connection: keep-alive
Comment

PREVIOUS NEXT
Code Example
Php :: tinker color auto | tinker lost color cli | tinker not colorful 
Php :: how to make a php info 
Php :: php artisan clear commands 
Php :: phpmailer utf8 
Php :: laravel back button 
Php :: how to create random alphanumeric in php 
Php :: php date in human readable form 
Php :: wp cron disable 
Php :: sail alias 
Php :: check composer php version 
Php :: refresh a specific migration in laravel 
Php :: php only my ip 
Php :: php info file 
Php :: laravel password confirmation 
Php :: Warning: Cannot modify header information - headers already sent by (output started at C:xampphtdocsheermatkamyprofile.php:48) in C:xampphtdocsheermatkamyprofile.php on line 144 
Php :: laravel undefined type DB 
Php :: laravel command to create symlink storage 
Php :: php get string after character 
Php :: php create file if not exist 
Php :: php version 
Php :: laravel migation error 
Php :: php location 
Php :: if ip is php 
Php :: laravel has table 
Php :: illuminate database queryexception could not find driver laravel 9 
Php :: wordpress disallow_file_edit 
Php :: Disable update notification for individual plugins 
Php :: check if text exists in string php 
Php :: sleep microseconds php 
Php :: api headers php 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =