htaccess的PHP 5.3的选择打破访问控制 - 允许 - 产地的选择吗?产地、访问控制、htaccess、PHP

2023-09-02 00:45:03 作者:有求必硬

让我先说,我是一个共享的Linux服务器与HostGator的运行。

我的问题是我此行的code在我的.htaccess:

 标题设置访问控制 - 允许 - 原产地*
 

这使得跨域XHR请求。这是工作,直到找到我的托管服务提供商告诉我补充这让PHP 5.3(其中我的程序要求):

 #使用PHP 5.3
行动应用程序/ x-HG-php53 / CGI-SYS / php53
AddHandler的应用程序/ x-HG-php53的.php
 
12.13 Nginx防盗链12.14 Nginx访问控制12.15 Nginx解析php相关配置 php weixin 34198583的博客 CSDN博客

现在我再也不能做跨域XHR请求。没有人知道为什么这不再起作用? (我得到的PHP 5.3虽然)

** 更新 **

嗯,它看起来像它的东西,这不是我的错,有什么东西我无法修复。下面是HostGator的技术支持官方回应:

  

我检查您的网站,错误日志和htaccess的指令,   不幸的是,我得出的结论是,头集   访问控制 - 允许 - 产地*行不兼容我们   执行PHP 5.3作为我们共同的服务器中。我真诚地   歉意,这会导致,但我们的方式   实现和调用PHP 5.3(因为5.2是默认的,不能   改变感谢的cPanel)显然覆盖了头处理   机制,使其无法正常工作。

解决方案

它的应的工作,两者一起,但是,如果你想提供一个端点与标题明确设置,你可以做到这一点PHP还有:

 头(访问控制 - 允许 - 产地:*');
 

把它放进你的PHP code的任何输出开始之前。请参见

Let me first say that I am running on a shared linux server with HostGator.

My problem is I had this line of code in my .htaccess:

Header set Access-Control-Allow-Origin *

Which allowed cross-domain xhr requests. It was working find till my hosting provider told me to add this to get php 5.3 (which my program requires):

# Use PHP 5.3
Action application/x-hg-php53 /cgi-sys/php53
AddHandler application/x-hg-php53 .php

Now I can no longer make cross-domain xhr requests. Does anyone know why this no longer works? (I do get PHP 5.3 though)

** Update **

Well, it looks like it's something that's not my fault and something I can't fix. Here's the official response from HostGator Tech Support:

I've examined your site, the error logs, and the .htaccess directives, and unfortunately I've come to the conclusion that the "Header set Access-Control-Allow-Origin *" line is not compatible with our implementation of PHP 5.3 as found in our shared servers. I sincerely apologize for the inconvenience that this causes, but the way we implement and call PHP 5.3 (since 5.2 is the default and cannot be altered thanks to cPanel) apparently overrides the Header handling mechanism, making it not work correctly.

解决方案

It should work both together, however, if you want to provide an endpoint with that header explicitly set, you can do it with PHP as well:

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

Put it into your PHP code before any output starts. See header.