douqie6454 2016-09-30 12:46
浏览 247

未定义的索引错误:Chrome中的HTTP_REFERER,但FireFox中没有

To get the right htpp/https + domain name I use $_SERVER['HTTP_REFERER']. It works well in FF but in Chrome I get the error: Undefined index: HTTP_REFERER

I can solve this simple to include next line in the code above by declaring

$_SERVER['HTTP_REFERER'] = '';

But I find it strange that this erros appears in Chrome. Or do I have to declare always $_SERVER[''] at the beginning of the function?

  • 写回答

1条回答 默认 最新

  • donglu8344812 2017-07-26 14:17
    关注

    Just check if it is set. Simply:

    if (isset($_SERVER['HTTP_REFERER'])) {
       $referer = $_SERVER['HTTP_REFERER'];
    } else {
       $referer = '';
    }
    

    or $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';

    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo