mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-08 08:17:24 +01:00
>The Origin request header indicates where a fetch originates from. It doesn't include any path information, but only the server name. It is sent with CORS requests, as well as with POST requests. It is similar to the Referer header, but, unlike this header, it doesn't disclose the whole path. From https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin Working code samples ```php <?php // We'll be granting access to only the arunranga.com domain // which we think is safe to access this resource as application/xml if($_SERVER['HTTP_ORIGIN'] == "http://arunranga.com") { header('Access-Control-Allow-Origin: http://arunranga.com'); header('Content-type: application/xml'); readfile('arunerDotNetResource.xml'); } else { header('Content-Type: text/html'); echo "<html>"; echo "<head>"; echo " <title>Another Resource</title>"; echo "</head>"; echo "<body>", "<p>This resource behaves two-fold:"; echo "<ul>", "<li>If accessed from <code>http://arunranga.com</code> it returns an XML document</li>"; echo "<li>If accessed from any other origin including from simply typing in the URL into the browser's address bar,"; echo "you get this HTML document</li>", "</ul>", "</body>", "</html>"; } ?> ``` See https://developer.mozilla.org/en-US/docs/Web/HTTP/Server-Side_Access_Control for more info. close #13835
10 KiB
10 KiB