Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

validate php url parameter list

Posted on 2014-02-02
2
427 Views
Last Modified: 2014-02-02
Hi,
I need help determining if the list of parameters being passed in a url are valid

I have a list of valid parameters
define("validParms","item1,item2,item3");

I want a test to check the parameters being passed in a url
dosomething.php?item1=abc&item2=data
are legitimate.

ie
I want this to cause an error because it has an 'illegal' param
dosomething.php?item1=data&item2=data&noParam=data
0
Comment
Question by:joomla
2 Comments
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 100 total points
ID: 39828631
So you want to throw an error if the query string (the $_GET array) contains a value that you are not expecting?

Try this:

<?php

$validParms = array("item1", "item2", "item3");
$invalidParms = array_diff(array_keys($_GET), $validParms);

if(count($invalidParms) > 0)
{
  echo "The following parameters are invalid:\n";
  print_r($invalidParms);
  die();
}


?>
0
 

Author Closing Comment

by:joomla
ID: 39828641
perfect
great example
thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question