Reputation: 15778
Here is the code....
if(!(isset($_POST["email"]) && isset($_POST["sessionKey"]) && isset($_POST["page"]) && isset($_POST["ipp"]))){
return;
}else{
$email = htmlspecialchars($_POST["email"]);
$sessionKey = htmlspecialchars($_POST["sessionKey"]);
$page = htmlspecialchars($_POST["page"]);
$ipp = htmlspecialchars($_POST["ipp"]);
}
ok, the idea is I MUST assign the parameter with the same variables. For example, if I post a parameter "test" , I must assign this to a variable .... test... ...Is there any short cut for me to doing something like this? Thank you.
Upvotes: 6
Views: 134
Reputation: 54649
Have a look at:
http://php.net/manual/en//function.extract.php
Also, isset
accepts more than one parameter, so you could use it like this:
if (isset($_POST["sessionKey"], $_POST["page"], $_POST["ipp"])) ...
See: http://www.php.net/manual/en/function.isset.php
Upvotes: 2
Reputation: 145482
To expand upon the extract
answer, you can slice out only the $_POST entries that you need with:
$vars = array_intersect_key($_POST,
array_flip(array("email", "sessionKey", "page", "ipp")));
// and then this replaces the isset() check and the extraction
if (count($vars) == 4) {
extract(array_map("htmlspecialchars", $vars));
}
Upvotes: 1
Reputation: 6570
Here's another possibility for the extraction part:
foreach (array('email','sessionKey','page','ipp') as $v) {
$$v = htmlspecialchars($_POST[$v]);
}
Upvotes: 1
Reputation: 86406
$data=array_map('htmlspecialchars',$_POST);
extract($data);
Be careful with extract this can override your existing variables with same name but you can change this behaviour by passing additional parameter to extract function.
Upvotes: 2