Tuesday 2 June 2015

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

<?php
// example URL: http://www.example.com/products.php?id=1&name=foo
// 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'];
}
?>

Usage

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

0 comments:

Post a Comment