Last Updated: September 09, 2019
·
606
· cleggypdc

Quick existance + length check on variables in PHP

Checking both the existance of a variable (no matter what depth in an object or array) and its length can be done in 1 line. Great for checking password lengths on a form for example:

<?php
     //password length check
     if(!isset($_POST['password']{5}) || !isset($_POST['password']{11}))
     {
         echo 'Password must be between 6 - 12 characters';
     }
?>

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside