ホームページ バックエンド開発 PHPチュートリアル PHP: 404 エラーをトラップして管理者に電子メールを送信するプログラム_PHP チュートリアル

PHP: 404 エラーをトラップして管理者に電子メールを送信するプログラム_PHP チュートリアル

Jul 13, 2016 pm 05:19 PM
404 email php プログラム 管理者 間違い トラップ

# 404.php, 8/10/2000.
# Traps 404 errors and mails a notice to the webmaster.
# Requires PHP 3.0 or newer, and mail capability on your system.
#
# Copyright 2000 shaun@shat.net under the GNU Public License.
# Disclaimer: I wrote this script for me, and it works for me.
# If it doesnt work for you, or makes your server explode,
# thats life. Please email with questions or bug reports.

# Set these variables to configure the script:

# Set $domain to your domain name (no www)

$domain = "your.domain.com";

# Set $docroot to the URL of the directory which contains your
# .htaccess file. Dont include trailing slash.

$docroot = "http://your.domain.com";

# Font face youd like to use on the 404 page

$fontface = "Verdana";

# Font size youd like to use on the 404 page

$fontsize = "2";

# Background color of the 404 page (default is white)

$bgcolor = "#ffffff";

# Text color youd like to use on the 404 page (default is black)

$textcolor = "#000000";

# This script is capable of mailing the details of each 404 error
# to the webmaster. Use the $reportlevel variable to control when
# you receive these reports.
#
# 0 = dont use the email capabilities at all
# 1 = send email only if the errors referer contains your domain name
# (i.e. the 404 was generated by a broken link on your site)
# 2 = send email any time a 404 error is generated (useful for tracking
# broken links at other sites which link to you)

$reportlevel = 2;

# Set $emailaddress to the email address of whoever should be
# notified of 404 errors. Dont escape the @ symbol. This will also
# be used as the "from" address on any emails the script generates.
# You can leave this unassigned if youre not using email features.

$emailaddress = "you@your.domain.com";

################################################################
# DONT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOURE DOING #
################################################################
# If you want to edit the script, Ive commented profusely :) #
################################################################

# The print_details function is what prints the 404 error to
# the visitor. As far as I know, PHP3 doesnt incorporate Perls
# print <<"EOT" ability. PHP4 does allow this capability
# but the script was written for PHP3. So, you have to use
# a lot of echo statements if you want to retain PHP3 compat.

function print_details()
{
# Request access to the global variables we need
global $fontface, $fontsize, $docroot, $REQUEST_URI, $reportlevel;
global $bgcolor, $textcolor

# Print the 404 error in web format
echo "404 Not Found";
echo "";
echo "

404 Not Found

";
echo "

";
echo "Were sorry. The page you requested, $docroot$REQUEST_URI, doesnt exist";
echo " on this server.

";

# If an email report is being generated, let the visitor know:
if ($reportlevel != 0)
{
echo "

";
echo "The details of this error have automatically been mailed to the webmaster.";
}

# Close up the HTML tags
# echo "";

return;
}


# The send_email function sends the details of the 404 error to the
# webmaster.

function send_email()
{
# Request access to the global variables we need
global $REQUEST_URI, $HTTP_REFERER, $emailaddress, $REMOTE_ADDR, $docroot;

# Build the $errortime variable to contain the date/time of the error.
# Using date() likely would have been better, but I already had this code
# elsewhere, and Im lazy.
$today = getdate();
$month = $today[mon];
$mday = $today[mday];
$year = $today[year];
$hours = $today[hours];
$minutes = $today[minutes];
$errortime = "$month/$mday/$year at $hours:$minutes";

# Create the body of the email message
$message .= "404 Error Report A 404 error was encountered by $REMOTE_ADDR";
$message .= " on $errortime. ";
$message .= "The URI which generated the error is: $docroot$REQUEST_URI ";
$message .= "The referring page was: $HTTP_REFERER ";

# メールメッセージを送信します。これは、mail() がシステム上で動作することを前提としています。
mail("$emailaddress", "404 エラー レポート", $message, "From: $emailaddress");

戻る;
}


# 関数の宣言が完了しました。ここからメイン機能が始まります。

# ユーザーのブラウザに 404 エラーを送信します
print_details();

# 電子メールレポートを送信する必要があるかどうかを確認してください。もしそうなら、そうしてください。
if ($reportlevel != 0)
if ($reportlevel == 1) {
if (eregi($domain,$HTTP_REFERER))
send_email();
else
send_email();

#すべて完了しました!
終了;

?>


www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/532620.html技術記事 ? # 404.php、2000 年 8 月 10 日。 # 404 エラーをトラップし、Web マスターに通知をメールで送信します。 # PHP 3.0 以降、およびシステム上のメール機能が必要です。 # # Copyright 2000 shaun@shat.net u...
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

CakePHP プロジェクトの構成 CakePHP プロジェクトの構成 Sep 10, 2024 pm 05:25 PM

この章では、CakePHP の環境変数、一般設定、データベース設定、電子メール設定について理解します。

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Dec 24, 2024 pm 04:42 PM

PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

CakePHP の日付と時刻 CakePHP の日付と時刻 Sep 10, 2024 pm 05:27 PM

Cakephp4 で日付と時刻を操作するには、利用可能な FrozenTime クラスを利用します。

CakePHP ファイルのアップロード CakePHP ファイルのアップロード Sep 10, 2024 pm 05:27 PM

ファイルのアップロードを行うには、フォーム ヘルパーを使用します。ここではファイルアップロードの例を示します。

CakePHP ルーティング CakePHP ルーティング Sep 10, 2024 pm 05:25 PM

この章では、ルーティングに関連する次のトピックを学習します。

CakePHP について話し合う CakePHP について話し合う Sep 10, 2024 pm 05:28 PM

CakePHP は、PHP 用のオープンソース フレームワークです。これは、アプリケーションの開発、展開、保守をより簡単にすることを目的としています。 CakePHP は、強力かつ理解しやすい MVC のようなアーキテクチャに基づいています。モデル、ビュー、コントローラー

PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 Dec 20, 2024 am 11:31 AM

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

CakePHP バリデータの作成 CakePHP バリデータの作成 Sep 10, 2024 pm 05:26 PM

Validator は、コントローラーに次の 2 行を追加することで作成できます。

See all articles