dongxuan1660 2014-11-11 19:05 采纳率: 100%
浏览 12
已采纳

php在输入无效网址后将用户移至404页面

I'm designing a website but I know if the user enters a wrong character into my url, a not found page will open for him . and I know it can be a way to hack my website. What should I do for that? for example if the user enters a ' into my url like this:

http://example.com/article.php?id=585'

He move to a not found page which I have designed it or move to the first page or the last page he was in. Thanks.

  • 写回答

3条回答 默认 最新

  • duanfei9278 2014-11-11 19:20
    关注

    You have to take 2 things into consideration:

    1. Handling non-existent files
    2. Handling non-existent article ids

    Here's how to handle each case:

    1) Create an .htaccess file and place it in your website root folder:

    RewriteEngine on
    ErrorDocument 404 /error.php # change this to your own 404 file path
    

    2) Open the articles.php file and add this to the top (right after checking if your ID exists)

    if(!valid_id($id)) {
        //if you have php 5.3- use this
        header('HTTP/1.1 404 Not Found');
    
        //if you have php 5.4+ use this
        //http_response_code(404);
    
        include('error.php'); //change this path to your own 404 file
        die();
    }
    

    Obviously, valid_id() is just a function example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测