Manage cross domain request in php

9:30 PM

If you are making a app and using web services(WS) then don't need to worry because if you requesting throw app then this will work but if you'll run this same app on your desktop browser then there is a 'cross domain' error, you can remove this by writing following code on the top of your PHP file :


    header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
    header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
    header('Access-Control-Max-Age: 1000');
    header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');


on the place of '$_SERVER['HTTP_ORIGIN'])', you can write the server name(like : localhost etc.), if you want to allow cross domain request form a specific server.

You Might Also Like

0 comments