note 125013 added to function.intval

From: Date: Fri, 15 May 2020 15:46:09 +0000
Subject: note 125013 added to function.intval
Groups: php.notes 
Request: Send a blank email to php-notes+get-214636@lists.php.net to get a copy of this message
As a warning, do not use this function alone for input validation. Vulnerable example: <?php if(isset($_GET['id']) && intval($_GET['id']) > 0){ echo $id; } ?> The following requests would pass this filter: /page.php?id=10 /page.php?id=10oops /page.php?id=10<script>alert(1)</script> /page.php?id=1' OR '1'='1 /page.php?id[]=<script>alert(1)</script> Instead use the is_numeric() function for integer validation: <?php echo intval("10oops"); // 10 echo is_numeric("10oops"); // false ?> Secure example: <?php if(isset($_GET['id']) && is_numeric($_GET['id']) && intval($_GET['id']) > 0){ echo $id; } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 38.142.137.34 (proxied: 162.224.118.61) ---- Manual Page -- http://php.net/manual/en/function.intval.php Edit -- https://master.php.net/note/edit/125013 Del: integrated -- https://master.php.net/note/delete/125013/integrated Del: useless -- https://master.php.net/note/delete/125013/useless Del: bad code -- https://master.php.net/note/delete/125013/bad+code Del: spam -- https://master.php.net/note/delete/125013/spam Del: non-english -- https://master.php.net/note/delete/125013/non-english Del: in docs -- https://master.php.net/note/delete/125013/in+docs Del: other reasons-- https://master.php.net/note/delete/125013 Reject -- https://master.php.net/note/reject/125013 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214636) next »