Angular Access-Control-Allow-Origin PHP htaccess

Today, We want to share with you Angular Access-Control-Allow-Origin PHP htaccess.
In this post we will show you Access-Control-Allow-Origin solution – Angularjs PHP Javascript and htaccess, hear for Access-Control-Allow-Origin solution – Angularjs PHP Javascript we will give you demo and example for implement.
In this post, we will learn about Angular .htaccess – htaccess Access-Control-Allow-Origin with an example.

Access-Control-Allow-Origin stands for other name is CORS (Cross-Origin Resource Sharing) header.

The Access-Control-Allow-Origin Resource Sharing standard works by adding new HTTP headers mean request that allow servers(permitted) to describe the set of origins(all) that are permitted to read(data read) that information using a web browser(chrome,mozila…).

READ :  C# pointers Tutorial with Examples

It’s one type of Read permitted.

Solution for PHP – Using htaccess Access-Control-Allow-Origin

Error code or Angularjs,Javascript File Request in PHP

// Using Error Javascript File request to the server
			 type: "GET",
			 web_url: "",
			 data: "post_id=" + s_id + "&url_data=" + web_url,
			 dataType: 'json',   
			 cache: false,
			 success: function(data)
				var People_list_data = data[1];              
				var data_list = data[2];           
				$('#maindivid').html("<b>Example of cors: </b>"+People_list_data+"<b><br> Listing data view: </b>"+data_list);

// Using Error Angularjs File request to the server
			error genrated
			//Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at (Reason: CORS header 'Access-Control-Allow-Origin' missing).

Server side code Solution

There just put in file

READ :  Vue-router - Routing using Vuejs - Dynamic Components in Vuejs

Solution No 1
			 // all permission include this Headers
			 header('Access-Control-Allow-Origin: *');  
			 your code here - respnse code
 Solution No 2
				//  include this Headers with content-type
				 header('content-type: application/json; charset=utf-8');
				 header("access-control-allow-origin: *");


Solution No 3

				// two include this Headers
				header('Content-type: text/html');
				header('Access-Control-Allow-Origin: *');

Solution for htaccess – Using htaccess Access-Control-Allow-Origin

Go to Root Folder and First of all take a backup in htaccess file and past this code in .htaccessfile

 <ifmodule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"


<ifmodule mod_headers.c>
    Header set Access-Control-Allow-Origin
    Header set Access-Control-Allow-Credentials true

How to Enable Access-Control-Allow-Origin chrome

please click this link and add the cors chrome extensions and after than send request.

READ :  VueJS Directory Application Structure Example

A Simple requests of client side to server side send Request

A simple Access-Control-Allow-Origin or cross-site request is one that meets all the List of following conditions:

The only allowed methods are:

Using GET Method
Using HEAD Method
Using POST Method

Apart from the headers(CORS) set automatically by the user agent (e.g. Connection, Content-Type,User-Agent, etc.), the only cors(headers) which are allowed to be manually header type set are below:


There are list of allow the Content-Type header are: