私がやろうとしているのは、クエリが空であるか、コード名が間違っている場合に、訪問者をエラー ページに送ることです。私の現在のスクリプトは、次の「このウェブサイトにはハッキングはありません!」をエコーしますが、これはすべて、元のクエリが送信された同じページで発生しています。
目標は、最初のページと同じフォルダー内にあるカスタム エラー ページに訪問者を送ることです。
http://www.example.com/download/file.php
http://www.example.com/download/error.php
そして私の現在のスクリプトは
<?php
$host = 'localhost';
$db_name = 'My_DB_Name';
$db_user = 'MY_User_Name';
$db_pass = '******';
$path_to_file_directory = 'download/files/';
mysql_connect( $host, $db_user, $db_pass);
mysql_select_db( $db_name ) or die(mysql_error());
$file_code = filter_input( INPUT_GET, 'urlid' );
# Query for file info
$res = mysql_query("SELECT * FROM `Files` WHERE `urlID`='".$file_code."'") or die ( mysql_error() );
# If query is empty, there is a bad code name
# This catches possible hacking attempt.
if( mysql_num_rows($res) == 0 )
{
echo 'There will be no hacking on this website! ';
exit();
}
# Save file info into an array called "$info"
$info = mysql_fetch_assoc($res);
# File path is below
$file_path = $path_to_file_directory.$info['file_name'];
# Now push the download through the browser
# There is more than 1 way to do this.
if (file_exists($file_path)) {
echo '<p>if it does not: <a href="'.$file_path.'">click here to try again</a>.</p>';
exit;
}
?>
エコーを別のものに変更する必要があることは理解していますが、エラーページへのリンクをエコー内に配置するだけでは、file.phpページでのみエコーされるため、代わりに何を使用する必要があるかわかりません
助けてください