Jump to content

Validate $_GET variable


clay1

Recommended Posts

Check if the value is_numeric then static cast the var to int:

 

$id = isset($_GET['id']) && is_numeric($_GET['id'])?(int) $_GET['id']:0;

 

The ternary operator (? : ) act as a shortened if / else. So if the get id has been set and it is numeric cast the id to int, else set id to 0.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.