diff --git a/category.php b/category.php index f91ad942c..f0a5161f7 100644 --- a/category.php +++ b/category.php @@ -39,6 +39,9 @@ if ( isset($_GET['cat']) ) { $url_params['section'] = 'categories'; $url_params['category'] = $_GET['cat']; + $result = get_cat_info($url_params['category']); + if ( !empty($result) ) + $url_params['cat_name'] = $result['name']; } elseif ( in_array($_GET['cat'], array('best_rated','most_visited','recent_pics','recent_cats') @@ -47,6 +50,10 @@ if ( isset($_GET['cat']) ) { $url_params['section'] = $_GET['cat']; } + else + { + page_not_found(''); + } } redirect ( make_index_url($url_params) ); diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index a671474ef..2aff86975 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -118,6 +118,8 @@ SELECT '.implode(',', $infos).' WHERE id = '.$id.' ;'; $row = mysql_fetch_array(pwg_query($query)); + if (empty($row)) + return null; $cat = array(); foreach ($infos as $info) diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index bc967b752..65cbc879c 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -591,4 +591,22 @@ function access_denied() redirect($login_url); } } + +/** + * exits the current script with 404 code when a page cannot be found + * @param string msg a message to display + * @param string alternate_url redirect to this url + */ +function page_not_found($msg, $alternate_url=null) +{ + header('HTTP/1.1 404 Not found'); + header('Status: 404 Not found'); + if ($alternate_url==null) + $alternate_url = make_index_url(); + redirect( $alternate_url, + '