php $_get取得空,Laravel - PHP 無法取得 Hppt Request $_GET Params 值的解決方式

這裡記錄一下,在 Nginx + PHP 環境無法取得 Http Get Request 的問題

在本機端,使用的是 apache 環境,會需要取得網址上的Get參數

public function index(Request $request) {

$message = $request->message;

...

}

上傳至 Server Side (Nginx 環境) 卻發現無法取得參數

嘗試取得完整網址與$_GET是否能取得值

這時先測看看完整網址以及檢查$_GET

public function index(Request $request) {

echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

print_r($_GET);

確定在 localhost 確實能完整捕捉到

Localhost 結果如:

http://localhost:8000?message=hello

Array

(

[message] => hello

)

但是在 server 上面有捕捉到完整網址,但同樣輸出的是空的 $_GET

Server 輸出結果如:

http://example.com?message=hello

Array

(

)

檢查Server side 設定

正式 Server 使用的是 Nginx

前往Server 設定中,檢查一下 nginx.conf ,發現原因是

try_files 沒有配置到 get 參數

location / {

try_files $uri $uri/ /index.php;

}

改成下面這樣就能正常取得 get params

location / {

try_files $uri $uri/ /index.php?$query_string;

}

或者

location / {

try_files $uri $uri/ /index.php?$args;

}

聲明,近期發現有平台大量盜用文章內容,若您發現內文非來自關於網路那些事 [https://adon988.logdown.com](https://adon988.logdown.com) ,希望您與我聯繫 [https://www.facebook.com/ThinkingWebsite](https://www.facebook.com/ThinkingWebsite)

(本文章源自"關於網路那些事)

最後,如果你喜歡這篇文章,請幫忙點個讚

Tweet

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值