Objectifs

Lors de la récupération de certains paramètres, cette classe permet de garantir certaines propriétés à la récupération d'un paramètre de la requête. Le but est d'augmenter la sécurité.

Améliorations possibles

Rajouter des fonctions qui appliquent des contraintes sur le contenu d'un paramètre de la requête. Par exemple une expression regulière précise.

Code source

<?php
/*
(c)2004,2005 David Sporn

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License version 2.1 as published by the Free Software Foundation.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

class RequestParserBase
{
	/**Return a single line from an arbitrary request parameter.
	 * Additionnaly, whitespaces are trimed and slashes are striped.
	 * @param name the request parameter name.
	 * @param default a default value that is returned when the request parameter does not exist.
	 * @return a string
	 */
	function getSingleLineValue($name, $default = '')
	{
		if (@isset($_REQUEST[$name]))
		{
			//we only care about the first line, so limit 
			//to 2 elements : the first line and the remaining
			$temp = explode("\n",$_REQUEST[$name],2) ; 
			return stripslashes(trim($temp[0])) ;
		}
		return $default ;
	}

	/**Return a string from an arbitrary request parameter.
	 * Additionnaly, slashes are striped.
	 * @param name the request parameter name.
	 * @param default a default value that is returned when the request parameter does not exist.
	 * @return a string
	 */
	function getStringValue($name, $default = '')
	{
		if (@isset($_REQUEST[$name]))
		{
			return stripslashes($_REQUEST[$name]) ;
		}
		return $default ;
	}

	/**Return an integer from an arbitrary request parameter.
	 * @param name the request parameter name.
	 * @param default a default value that is returned when the request parameter does not exist.
	 * @return a string
	 */
	function getIntegerValue($name, $default = 0)
	{
		if (@isset($_REQUEST[$name]))
		{
			return (integer)stripslashes(trim($_REQUEST[$name])) ;
		}
		return (integer)$default ;
	}
}
?>