Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php cors all

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
Comment

php cors

/**
 *  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
 *  - https://fetch.spec.whatwg.org/#http-cors-protocol
 *
 */
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

cors header php

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
Comment

php cors

<?php
 header("Access-Control-Allow-Origin: *");
Comment

PHP Cors

/**
 *  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
 *  - https://fetch.spec.whatwg.org/#http-cors-protocol
 *
 */
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

PREVIOUS NEXT
Code Example
Php :: php limit string length 
Php :: how to calculate age in laravel 
Php :: php error reporting all 
Php :: php get string after character 
Php :: get all routes laravel 
Php :: php loop 
Php :: php create file if not exist 
Php :: wordpres get_posttype 
Php :: magento 2 composer install 
Php :: php loop through lines of file 
Php :: ERROR 1071 (42000) at line 76: Specified key was too long; max key length is 767 bytes laravel 
Php :: hide wordpress error 
Php :: how to remove notice error in php 
Php :: how to remove text tab in wordpress editor 
Php :: php check whether the url is http or https 
Php :: laravel has table 
Php :: use app name in laravel blade 
Php :: remove http / https from link php 
Php :: artisan make model with migration 
Php :: row count in codeigniter 
Php :: this load session codeigniter 
Php :: random color php 
Php :: Error Call to undefined function CodeIgniterlocale_set_default() 
Php :: api headers php 
Php :: laravel db seed specific class 
Php :: wp revisions 0 
Php :: php utf-8 
Php :: laravel parse string to date 
Php :: wordpress stop redirect to https 
Php :: php artisan migrate --env=testing 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =