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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...