我要做的是在查询为空或代码名称错误时将访问者发送到错误页面?我当前的脚本与以下内容相呼应:“此网站不会被黑客入侵!”,但这一切都发生在发送原始查询的同一页面上。
目标是将访问者发送到我的自定义错误页面,该页面位于第一页所在的同一文件夹内。
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;
}
?>
我知道我必须将 echo 更改为其他内容,但我不知道我必须使用什么,因为只需将指向错误页面的链接放在 echo 中只会在我的 file.php 页面上回显它
请帮忙