Sanitize $_GET parameters to avoid XSS and other attacks

前端 未结 3 650
孤独总比滥情好
孤独总比滥情好 2020-12-14 10:49

I have a website in php that does include() to embed the content into a template. The page to load is given in a get parameter, I add \".php\" to the end of the parameter an

3条回答
  •  一个人的身影
    2020-12-14 11:07

    $page = preg_replace('/[^-a-zA-Z0-9_]/', '', $_GET['page']);
    

    Is probably the quickest way to sanitize this, this will take anything and make sure that it only contains letters, numbers, underscores or dashes.

提交回复
热议问题