0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Notice: Undefined index: HTTP_REFERER のエラー解決法

Last updated at Posted at 2019-02-03

##環境

 XAMPP7.2.6 

##概要

以下のコードを書いました。
コード内容は、テキストファイル読み込みコードです。

php.file_write.rb
<?php

$data[] = date('Y/m/d H:i:s');
$data[] = $_SERVER['SCRIPT_NAME'];
$data[] = $_SERVER['HTTP_USER_AGENT'];
$data[] = $_SERVER['HTTP_REFERER'];
$file = @fopen('access.log', 'ab') or (die('ファイルを開けませんでした!'));

fwrite($file, implode("\t", $data) . "\n");

flock($file, LOCK_UN);
fclose($file);
print 'アクセスログを記録しました。' ?>

   

そしたら、以下のエラーが出ました。


Notice: Undefined index: HTTP_REFERER in /opt/lampp/htdocs/dokusyuphp/file_write.php on line 6
ファイルを開けませんでした!

##エラーの原因 
   HTTP_REFERERの値が定義されていないことが原因でした

##解決法

6行目のHTTP_REFERERの値を定義しました。

値は、このコードでは不要なのでnullにしました。

$data[] = $_SERVER['HTTP_REFERER'];

$data[] = isset($_SERVER['HTTP_REFERER'])? $_SERVER['HTTP_REFERER'] : NULL;

##参考記事

https://php1st.com/574
https://dev.w.ezic.info/1387.html

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?