Forum Moderators: coopster

Message Too Old, No Replies

script redirecting to 404?

         

jake66

6:18 am on May 11, 2006 (gmt 0)

10+ Year Member



i would like to modify an existing script to redirect to a 404 response code (or page) if the category count has exceeded the allowed number of pages.

this is what currently exists:
max # of results per pages (10)
max # of pages (unlimited)

but let's say there's only 50 results. naturally, there shouldn't be anything showing past page 5.. so if someone tries to enter /myscript.php?page=6 they would get a 404 response/error

i have tried searching php.net extensively, but i cannot put it into few words what i need to do, therefore i'm not finding the correct tutorials or examples.
can anyone help me out?

dreamcatcher

6:40 am on May 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something simple maybe like:

if ($pageno>$maxpages)
{
header('HTTP/1.0 404 Not Found');
}

dc

siMKin

6:45 am on May 11, 2006 (gmt 0)

10+ Year Member



why would you want to give a 404 response in these cases?

jake66

2:07 pm on May 11, 2006 (gmt 0)

10+ Year Member



dreamcatcher, i don't have a max. number of pages - just results.. this is what i'm struggling with.

why would you want to give a 404 response in these cases?

it doesn't make sense to serve a 200/ok response for something that doesn't exist

siMKin

2:43 pm on May 11, 2006 (gmt 0)

10+ Year Member



the page does exist; there's just no data in the database to be displayed, given the arguments.
You have to keep in mind that the file your request is myscript.php, and that file exists. Apart from that, you give some arguments with which the page should be loaded and based on which certain content is going to be displayed. If those arguments are invalid, then that is what you should display.

I think it would be very unwise to generate a 404 header.
a) It's confusing for visitors
b) you might find your page removed from search engines.
c) See above: it's simply not true

jake66

3:42 pm on May 11, 2006 (gmt 0)

10+ Year Member



i think you're misunderstanding me.

look at it in this scenario:
- 50 products in database that show on this file
- i sell 10, which means i lost a page.
- search bots are still hitting that last page, and getting a 200/ok response.. note that this is replicating the last REAL page (page 4)
- i get slapped with a duplicate content penalty; and users will be confused when they hit page 5, then click to page 4.. they're getting the same content on two different pages

i don't want to 404 pages 1-4, any page after that needs to be 404'd to prevent this duplicate content penalty and confusing visitors

jatar_k

3:51 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so when you select the records you could count them and then dreamcatcher's answer would work

or when you select use an offset and a limit and if it returns no records serve up a 404

jake66

9:46 pm on May 11, 2006 (gmt 0)

10+ Year Member



jatar_k, do you know of a tutorial i can view on this subject? i cannot figure out few enough words to do a legitimate search on php.net

also, i do not have a max pageno, which is why i'm having such difficulties.
thank you all for your help thus far :)

jatar_k

9:50 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



how do you grab the results for any given page?

you get a pagenum in the GET
then, as you said, you have a results per page

what does your query look like for getting the 10 results for any given page?

jake66

12:29 am on May 12, 2006 (gmt 0)

10+ Year Member



here's my query:
 $products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, p. manufacturers_id, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
$products_new_split = new splitPageResults($products_new_query_raw, MAX_DISPLAY_PRODUCTS_NEW);

MAX_DISPLAY_PRODUCTS_NEW is defined in the database as configuration.

jatar_k

2:57 pm on May 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so you don't do any limiting, you just grab the whole thing every time

you should be able to do a mysql_num_rows and figure out if that page is within range and return a 404 if not

jake66

2:32 am on May 24, 2006 (gmt 0)

10+ Year Member



so you don't do any limiting, you just grab the whole thing every time

yes, i want to display (& paginate accordingly) all results up to MAX_DISPLAY_PRODUCTS_NEW (which is defined in the database)

you should be able to do a mysql_num_rows and figure out if that page is within range and return a 404 if not

i'm stumped with the "figure out if that page is within the range" - how could i go about doing that?

MAX_DISPLAY_PRODUCTS_NEW is basically the cutoff point for which i want to be displaying the records, because they become obsolete after that point

eelixduppy

2:40 am on May 24, 2006 (gmt 0)



You can do something like this:

$num = mysql_num_rows($result);
if($_GET['page']>($num/10)){
//code to do on error
}