PHP cURL add "Access-Control-Allow-Origin: *" header for specific endpoint
<p>I have such code on my php server (5.2) endpoint <code>GET http://mydomain/get-code.php</code>:</p>

<pre><code>&lt;?php
    header("Access-Control-Allow-Origin: *");

    $data = 'id=' . '123456' . '&amp;' .
            'text=' . 'some text' . '&amp;' .
            'code=' . urlencode($_GET['code']);
    $ch = curl_init('https://someapi.com/login/oauth');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);

    preg_match('/hash=([0-9a-f]+)/', $response, $out);
    echo $out[1];
    curl_close($ch);
?&gt;
</code></pre>

<p>I'm requesting GET <a href="http://mydomain/get-code.php" rel="nofollow">http://mydomain/get-code.php</a> from another domain.</p>

<p>I'm getting CORS error in browser console:</p>

<p><code>XMLHttpRequest cannot load http://mydomain/get-code.php No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9292' is therefore not allowed access.
</code></p>

<p>Any ideas?</p>