# No 'Access-Control-Allow-Origin' header is present on the requested resource while accessing php rest api

**URL:** <https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008>\
**Category:** ionic-v1\
**Created:** [December 1, 2017, 4:49am UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008 "2017-12-01T04:49:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![judhisahoo2009](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@judhisahoo2009](https://forum.ionicframework.com/u/judhisahoo2009)\
**Post date:** [December 1, 2017, 4:49am UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008/1 "2017-12-01T04:49:04Z")

</div>

Hi All,

I am working on a old project.  
Current system details are bellow.

node version : 5.0  
npm bersion : 3.3.6  
cordova version : 7.1  
ionic -v : 1.4.0

I am getting http service issue with php rest api.  
in php i have already added bellow code in on the top of the rest api file.

header(“Access-Control-Allow-Origin: \*”);  
header(“Content-Type: application/json; charset=UTF-8”);  
header(“Access-Control-Allow-Methods: POST,GET”);  
header(“Access-Control-Max-Age: 3600”);  
header(“Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With”);

But still getting belle message in chrome console.

ionic.bundle.js:19346 GET [http://www.example.com/login/app\_scripts/user\_login.php?userid=userid&pass=123456789](http://www.example.com/login/app_scripts/user_login.php?userid=userid&pass=123456789) 501 (Not Implemented)

:8100/#/login:1 Failed to load [http://www.example.com/login/app\_scripts/user\_login.php?userid=userid&pass=123456789:](http://www.example.com/login/app_scripts/user_login.php?userid=userid&pass=123456789:) No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘[http://192.168.2.149:8100](http://192.168.2.149:8100)’ is therefore not allowed access. The response had HTTP status code 501.

I need your help very badly… i have already spend last two days but nothing got any solution.

---

<div class="post-metadata">

**Author:** ![jeffreytck](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@jeffreytck](https://forum.ionicframework.com/u/jeffreytck)\
**Post date:** [December 1, 2017, 5:16am UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008/2 "2017-12-01T05:16:52Z")

</div>

Are you running in ionic-lab? There should be no issue when running on real-device.

If running on ionic-lab, what browser that you used?

Please implement disable web-security when running on browser as below in command-prompt/terminal. Below command is used for Google Chrome.

**open -n -a /Applications/Google\ Chrome.app --args --user-data-dir="/tmp/someFolderName" --disable-web-security**

---

<div class="post-metadata">

**Author:** ![spanchal](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/spanchal/32/115033_2.png) [@spanchal](https://forum.ionicframework.com/u/spanchal)\
**Post date:** [December 1, 2017, 5:30am UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008/3 "2017-12-01T05:30:03Z")

</div>

hello @judhisahoo2009

behind this error the main reason is CORS, CORS is not enable from your rest API.  
this will work perfectly without any changes in real device but not support in browser.  
to run this in development mode (browser) you have to disable browser security (CHROME) by following these steps given bellow.

1 - create Folder in your drive FolderName = chrome  
2 - right click on chrome shortcut on desktop  
3 - open properties  
4 - go to Shortcut \> Targate  
5 - put this line after the existing line **–disable-web-security --user-data-dir="E:\chrome"**  
6 - now you can access your restAPI from this desktop chrome shortcut.

## if you have Mac (safari)

open safari \> go to Developer option \> check Disable Cross-Origin Restrictions.

---

<div class="post-metadata">

**Author:** ![judhisahoo2009](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@judhisahoo2009](https://forum.ionicframework.com/u/judhisahoo2009)\
**Post date:** [December 1, 2017, 5:39am UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008/4 "2017-12-01T05:39:54Z")

</div>

Hi, @spanchal,

Do those need for run in real device with -livereload command ?

i am using reald device with bellow command from windows command pompt.

“ionic run android -l”

## then frmm google “chrome://inspect/#devices” clicking inspect … then getting issues detals from console.

ionic.bundle.js:19346 GET [http://www.example.com/login/app\_scripts/user\_login.php?userid=userid&pass=123456789](http://www.example.com/login/app_scripts/user_login.php?userid=userid&pass=123456789) 501 (Not Implemented)

## :8100/#/login:1 Failed to load [http://www.example.com/login/app\_scripts/user\_login.php?userid=userid&pass=123456789:](http://www.example.com/login/app_scripts/user_login.php?userid=userid&pass=123456789:) No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘[http://192.168.2.149:8100](http://192.168.2.149:8100)’ is therefore not allowed access. The response had HTTP status code 501.

plz help me if any.

---

<div class="post-metadata">

**Author:** ![judhisahoo2009](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@judhisahoo2009](https://forum.ionicframework.com/u/judhisahoo2009)\
**Post date:** [December 1, 2017, 5:41am UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008/5 "2017-12-01T05:41:18Z")

</div>

Hi @jeffreytck Do those need for run in real device with -livereload command ?

i am using reald device with bellow command from windows command pompt.

“ionic run android -l”

then frmm google “chrome://inspect/#devices” clicking inspect … then getting issues detals from console.  
ionic.bundle.js:19346 GET [http://www.example.com/login/app\_scripts/user\_login.php?userid=userid&pass=123456789](http://www.example.com/login/app_scripts/user_login.php?userid=userid&pass=123456789) 501 (Not Implemented)

:8100/#/login:1 Failed to load [http://www.example.com/login/app\_scripts/user\_login.php?userid=userid&pass=123456789:](http://www.example.com/login/app_scripts/user_login.php?userid=userid&pass=123456789:) No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘[http://192.168.2.149:8100](http://192.168.2.149:8100)’ is therefore not allowed access. The response had HTTP status code 501.  
plz help me if any.

---

<div class="post-metadata">

**Author:** ![judhisahoo2009](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@judhisahoo2009](https://forum.ionicframework.com/u/judhisahoo2009)\
**Post date:** [December 1, 2017, 5:47am UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008/6 "2017-12-01T05:47:28Z")

</div>

Hi All,

Just test the http service part in plucker… it is working fine as bellow.

.controller(‘DashCtrl’, function($scope, $http) {  
$http.get(“[http://www.exampe.com/login/app\_scripts/user\_login.php?userid=kautilya&pass=485810](http://www.exampe.com/login/app_scripts/user_login.php?userid=kautilya&pass=485810)”).then(function(response) {  
console.log("srvice response : ", response);

});  
})

getting proper response from plunker…

Thinking some thing issue in system settings…

I am fresher in ionic… please help me.

---

<div class="post-metadata">

**Author:** ![judhisahoo2009](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@judhisahoo2009](https://forum.ionicframework.com/u/judhisahoo2009)\
**Post date:** [December 4, 2017, 9:13am UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008/7 "2017-12-04T09:13:18Z")

</div>

Hi All,

I have seen my code is runing fine with android 6.0+ but getting above error with bellow version 6.0.

Can any one help me any solution for 6.0 version.

thanks…

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 10:01pm UTC](https://forum.ionicframework.com/t/no-access-control-allow-origin-header-is-present-on-the-requested-resource-while-accessing-php-rest-api/114008/8 "2021-07-19T22:01:10Z")

</div>


