Skip to content

Instantly share code, notes, and snippets.

@rwaddin
Created April 6, 2021 09:08
Show Gist options
  • Save rwaddin/112ce785b08e5492a66d1e7fc61339b6 to your computer and use it in GitHub Desktop.
Save rwaddin/112ce785b08e5492a66d1e7fc61339b6 to your computer and use it in GitHub Desktop.
Solve CORS Origin :: My case in vue.js 2 with axios and rest api codeigniter 3.1.11
<?php
// please place this script to index.php in root folder
// in first line after open tag php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
header("HTTP/1.1 200 OK");
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment