1
我在我的APIController.php
上有錯誤Only variables should be passed by reference
,我已經閱讀了關於這個錯誤的所有問題,但沒有解決它。異常'只有變量應該通過引用傳遞
我的代碼:
$ip = $_SERVER['REMOTE_ADDR'];
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
$ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = array_pop(end($ip));
}
error.log中:
[2016-12-06 15:43:00] production.ERROR: exception 'ErrorException' with message 'Only variables should be passed by reference' in /var/www/app/Http/Controllers/Api/ApiController.php:33
Stack trace:
#0 /var/www/app/Http/Controllers/Api/ApiController.php(33): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2048, 'Only variables ...', '/var/www/app/Ht...', 33, Array)
謝謝。
錯誤'ErrorException'與消息'array_pop()期望參數1是數組,字符串給定'在/var/www/app/Http/Controllers/Api/ApiController.php:34 – Pixel
是的錯誤是非常正確的,你應該在array_pop()中傳遞數組'' –
如何修復我的代碼以獲取用戶IP? – Pixel