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 :: add like and equal in same query in laravel 
Php :: get all post meta 
Php :: woocommerce remove related products 
Php :: Split 10 email out of 50 email using coma separated via php 
Php :: how to fetch particular css file in wordpress 
Php :: if is checkout page woocommerce 
Php :: deprecated filter_var() phpmailer 
Php :: how to claer the input php 
Php :: php file read 
Php :: print value in laravel console 
Php :: php detect mobile 
Php :: php fwrite new line 
Php :: Classified script with mobile app laravel 
Php :: php iterate array 
Php :: php get day diff 
Php :: php get ip by domain 
Php :: a backwards counting forloop 
Php :: php microtime 
Php :: set null on foreign key deletion in laravel 
Php :: php sql last 10 rows 
Php :: how to run a specific test in laravel 
Php :: .htaccess for laravel in hostinger 
Php :: php hide decimals if zero 
Php :: How to read session in laravel 
Php :: Error: php@7.2 has been disabled because it is deprecated upstream! 
Php :: wordpress do shortcode 
Php :: codeigniter count rows 
Php :: get word between two characters php 
Php :: carbon date format 
Php :: laravel public access inserver using htaccess 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =