Access control Access-Control-Allow-Origin on the Apache PHP server side

Asked

Viewed 147 times

1

I don’t know much about PHP and I’m trying to create an application to automatically register products from my online store directly in Mercadolivre.

Ad data is captured with JavaScript and sent to the ML API via $.ajax, what happens is that the images that are passed only the URL to the API are not going up to the site, I checked the Urls and are correct.

I tried to set the website logo URL (which is smaller) and still won’t (I don’t get any feedback from the API if the image was or wasn’t, it just doesn’t appear in the ad). If I get the URL of an image from another site (I got one from Wikipedia), it goes up correctly.

The virtual store is in PHP (Opencart) on the Apache server, will this lock may be occurring on the server side by PHP or Apache?

2 answers

0

This is a type of lock that occurs on the application server you can bypass by sending an inherited that accepts all sources

header('Access-Control-Allow-Origin: *');  

Very important that this be called before anything else

Wrong

<html>
<?php
header('Access-Control-Allow-Origin: *'); 
?>

Correct

<?php
header('Access-Control-Allow-Origin: *'); 
?>
<html>
  • But as the ML API will order directly the JPG file, where I can insert this code?

-1


I was able to resolve by disabling Cloudflare’s "Always use HTTPS".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.