简体   繁体   English

php处理分页$ _GET请求超出限制

[英]php handling pagination $_GET requests past limit

I have a template page that paginates through results with a $_GET request. 我有一个模板页面,该页面通过$_GET请求对结果进行分页。

How should I handle any $_GET errors where a user vists a page that would exceed the total number of avaliable results? 如果用户访问的页面超过了可用结果的总数,该如何处理$_GET错误?

I've thought of the following solutions but I'm not sure which is the ideal choice: 我想到了以下解决方案,但不确定哪一个是理想的选择:

  • 404 - display 404 error message 404-显示404错误消息
  • 301/2 redirect back to the last available page of results 301/2重定向回结果的最后一个可用页面
  • Alter the data request to show the last available batch of results (not a redirect) 更改数据请求以显示最后可用的结果批次(而非重定向)
  • 301/2 redirect back to the first page 301/2重定向回到第一页
  • Just display an 'no results' message (not a redirect) 只需显示“无结果”消息(而不是重定向)

I'll need to take into considering that the total number of results may increase or decrease over time. 我需要考虑的是,结果总数可能会随时间增加或减少。 Meaning my-page.php?p=3 may or may not display results. 含义my-page.php?p=3可能会或可能不会显示结果。

I'm also wonder if I need to consider the possibility of a user or bot spaming my template with $_GET for any page number my-page.php?p=9999999 , or am I overthinking this ? 我也想知道是否我需要考虑用户或漫游器是否将$_GET模板散布到任何页面编号my-page.php?p=9999999 ,还是我对此是否考虑过度?

Thanks 谢谢

Bots are going to bot. 机器人将成为机器人。 Treat all user input as hostile by default and if the query turns out to be valid treat it as a bonus. 默认情况下,将所有用户输入视为敌对行为,如果查询结果有效,则将其视为奖励。 If someone requests such a high offset, you won't get any results, so it's not a 404, just a "previous page" link on an otherwise empty list. 如果有人要求这么高的偏移量,您将不会得到任何结果,因此它不是404,而只是一个否则为空的列表上的“上一页”链接。

Don't get all clever by trying to redirect. 不要通过尝试重定向来获得全部聪明。 Stick with the "garbage in, garbage out" principle. 坚持“垃圾进,垃圾出”的原则。

See how it works on other sites for comparison purposes. 查看它如何在其他站点上工作以进行比较。 Most just show an empty list with a previous page button that goes to page-1. 大多数只显示一个空列表,并带有转到第1页的上一页按钮。 It's not your fault they put in some wonky number, or page=ham+sandwich . 他们输入一些不可思议的数字或page=ham+sandwich并不是您的错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM