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 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

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 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 :: valide email php 
Php :: form post self php 
Php :: cast array to object php 
Php :: You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode. Alternatively, you can run Composer with `--ignore-platform-req=ext-curl` to temporarily ignore these required extensions. 
Php :: beautify var_dump 
Php :: show php erros 
Php :: laravel make migration controller resource mcr 
Php :: php yesterday 
Php :: laravel session flash 2020 
Php :: php close window after script runs 
Php :: php mysql create table 
Php :: upload file in wp from url 
Php :: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress. 
Php :: laravel carbon count days between dates 
Php :: php artisan migrate reset 
Php :: put img in timestamp using php 
Php :: create session in wordpress 
Php :: save html form data to text file using php 
Php :: how to split url in php 
Php :: for install perticular version in vue with laravel 
Php :: setcookie php 
Php :: twig symfony get route 
Php :: Check duplicate email using Jquery validation 
Php :: laravel env google smtp 
Php :: php pdo rowcount 
Php :: php pakistan time zone 
Php :: laravel helper function for check string is exist in another string 
Php :: laravel plural 
Php :: redirect wordpress 
Php :: check if input file is set codeigniter 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =