aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--category.php7
-rw-r--r--include/functions_category.inc.php2
-rw-r--r--include/functions_html.inc.php18
-rw-r--r--include/section_init.inc.php6
-rw-r--r--picture.php3
5 files changed, 34 insertions, 2 deletions
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,
+ '<div style="text-align:left; margin-left:5em;margin-bottom:5em;">
+<h1 style="text-align:left; font-size:36px;">Page not found</h1><br/>'
+.$msg.'</div>',
+ 5 );
+}
?>
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
index 3a27882ba..1d5949e63 100644
--- a/include/section_init.inc.php
+++ b/include/section_init.inc.php
@@ -197,7 +197,7 @@ SELECT name, url_name, id
}
if ( empty($page['tags']) )
{
- die('Fatal: no existing tag');
+ page_not_found('Requested tag does not exist', get_root_url().'tags.php' );
}
}
else if (0 === strpos($tokens[$next_token], 'fav'))
@@ -316,6 +316,10 @@ if ('categories' == $page['section'])
if (isset($page['category']))
{
$result = get_cat_info($page['category']);
+ if (empty($result))
+ {
+ page_not_found('Requested category does not exist' );
+ }
$page = array_merge(
$page,
diff --git a/picture.php b/picture.php
index 486e303cb..ed143723f 100644
--- a/picture.php
+++ b/picture.php
@@ -42,7 +42,8 @@ if (isset($page['category']))
// displayed, and execution is stopped
if (!in_array($page['image_id'], $page['items']))
{
- die('Fatal: this picture does not belong to this section');
+ page_not_found('The requested image does not belong to this image set',
+ duplicate_index_url() );
}
// +-----------------------------------------------------------------------+