在做项目的过程中经常需要跨域访问。这里主要介绍一下 php 中怎么解决跨域问题。
header('access-control-allow-origin: *');
header('access-control-allow-origin: https://test.com');
// 设置能访问的域名 static public $originarr = [ 'https://test1.com', 'https://test2.com', ]; /** * 公共方法调用 */ static public function setheader() { // 获取当前跨域域名 $origin = isset($_server['http_origin']) ? $_server['http_origin'] : ''; if (in_array($origin, self::$originarr)) { // 允许 $originarr 数组内的 域名跨域访问 header('access-control-allow-origin:' . $origin); // 响应类型 header('access-control-allow-methods:post,get'); // 带 cookie 的跨域访问 header('access-control-allow-credentials: true'); // 响应头设置 header('access-control-allow-headers:x-requested-with,content-type,x-csrf-token'); } }
如对本文有疑问, 点击进行留言回复!!
php 使用 yansongda/pay 进行微信,支付宝支付
Codeforces Round #658 (Div. 2) (C1、C2)
van-uploader + thinkphp6.0 图片上传
网友评论