?
Solved

validate php url parameter list

Posted on 2014-02-02
2
Medium Priority
?
431 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
[X]
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
2 Comments
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

719 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