
How to Build a PHP Login Form Using Sessions
First: should you use sessions or cookies? That’s the first big question I see. In most cases, you should use sessions. There are some exceptions,

How to Validate (and Sanitize) User Input In PHP Using Filter_Input() and Filter_Var()
Use filter_input(), filter_var() and these two other PHP functions to add another layer of security to your applications

Output the last row inserted in MySQLi
MySQLi makes grabbing the last inserted row easy. After running your insert query, you can do this: $id = $mysqli->insert_id; Then, you can query for

Connecting to MySQL with PDO
With MySQLi, it looks like this: $mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name); But, PDO is a bit different because it can interact 12 different

Simple input filtering in PHP
Here’s one I don’t see talked about much: $name = filter_input(INPUT_POST, ‘name’, FILTER_SANITIZE_STRING); What this does is grab the “name” element from your POST array

Prevent SQL injection attacks with prepared statements
Bit of a hot topic lately in my inbox. Here’s what an old, vulnerable query might look like: $expected_data = 1; $query = “SELECT *