Solved

validate php url parameter list

Posted on 2014-02-02
2
428 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 35

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

713 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