Passing values in the url in php

A demonstration on how to pass values in the URL and how to read them in a secure way

// example URL:
// init the variables
$id = 0;
$name = '';
if (isset($_GET['id'])) $id = (int) $_GET['id'];
if (isset($_GET['name']))
	if (preg_match('/^[a-z]+$/i',$_GET['name'])) $name = $_GET['name'];


An integer and a string are used, so to show how to handle them securely.


Add your comment