Jump to content

Recommended Posts

Posted

Hi,

 

I tried CORS (cross origin resource sharing), just because I have some JS using it.

Is it disabled on the Johnny? I support it with the PHP script (setting header). It works on different web-hosts.

Specifically I get the following error in Chrome and Firefox:

'No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.'

 

Here is the code I used:

 

PHP:

 

    // Allow from any origin
   if (isset($_SERVER['HTTP_ORIGIN'])) {
    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']))
	    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);
   }

   // old:
   /*
header("Access-Control-Allow-Origin: *");
header("Access-Control-Expose-Headers: Origin");
header('Access-Control-Allow-Methods: GET, POST');  
header("Origin: ".CURRENT_HOST);
*/

 

Issue solved after doing some research again:

 

In some other included PHP scripts there was a blank line before "&--#60;?php".

This caused already output disallowing any headers to be set.

 

web development...

 

Btw. it seems like I can't set the title to [solved] myself

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...