大佬教程收集整理的这篇文章主要介绍了php-Laravel多域起源CORS,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在laravel中允许CORS的两个域在本地和服务器上使用它,因此我不想将我的应用程序暴露给任何域.我现在该死
public function handle($@R_874_10613@est, Closure $next)
{
return $next($@R_874_10613@est)
->header('Access-Control-Allow-Origin', 'http://localhost:4200')
// ->header('Access-Control-Allow-Origin', 'http://api.example.com')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, deletE')
->header('Access-Control-Allow-Headers', 'Content-Type');
}
我既没有评论也没有数组
解决方法:
您可以定义要允许的起源数组,然后检查传入请求中是否包含以下之一:
public function handle($@R_874_10613@est, Closure $next)
{
$allowedOrigins = ['example.com', 'example1.com', 'example2.com'];
$origin = $_SERVER['http_ORIGIN'];
if (in_array($origin, $allowedOrigins)) {
return $next($@R_874_10613@est)
->header('Access-Control-Allow-Origin', $origin)
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, deletE')
->header('Access-Control-Allow-Headers', 'Content-Type');
}
return $next($@R_874_10613@est);
}
以上是大佬教程为你收集整理的php-Laravel多域起源CORS全部内容,希望文章能够帮你解决php-Laravel多域起源CORS所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。