adv Posted May 22, 2008 Share Posted May 22, 2008 is there a way to modify $_POST i mean when u call the post method to defined it some other way $var = $_POST['var']; something like this $var = post($var); a function or something i`ve tried something but it doesnt work function post($value) { foreach ($_POST as $value) { return $value; } } but it doesnt work .. it returns the first value of post to all inputs.. i thought of this function posts1($value) { return $_POST["$value"]; } and another question i didn`t wanted to open new thread just for a question with $_GET method is there a way to encrypt the url like page.php?test=oki instead of "oki" to be shown something encripted .. via md5 or soemthing i`ve tried to encrypt $method = md5($_GET['test']); switch ($method) { case md5($method); // code } it works but the "oki" is still blank and another thing u have this function function test($value) { if ($value == "10") { return true; } else if ($value == "20") { return true; } } if the first condition is true does the second still verifies it? or it passes by and only verifies first ? Link to comment https://forums.phpfreaks.com/topic/106740-modify-_post/ Share on other sites More sharing options...
GingerRobot Posted May 22, 2008 Share Posted May 22, 2008 1.) Im not entirely sure what you mean. 2.) Yes you could encrypt data with md5 or similar, however -- you can't decrypt md5 so that would be a bad choice. You could look into the mcrypt extension (see: here) 3.) No. If the if statement evaluates to true, then the else if will not be tested. Link to comment https://forums.phpfreaks.com/topic/106740-modify-_post/#findComment-547172 Share on other sites More sharing options...
adv Posted May 22, 2008 Author Share Posted May 22, 2008 thanks alot ginger for the quick answer :* on 1 : i don`t want to be seen $_POST some kind of alias for it.. or to create a function on 2 i understand and on 3 but how about this <?php function test($value, $value1) { if ($value == "10") { return true; } else if ($value1 == "20") { return true; } } ?> does this evaluates the second condition? Link to comment https://forums.phpfreaks.com/topic/106740-modify-_post/#findComment-547217 Share on other sites More sharing options...
GingerRobot Posted May 22, 2008 Share Posted May 22, 2008 The second condtion will only be evaluated if the first returns false. What would be the point of continuing anyway? As for your POST question, I'm still not entirely sure what your mean. Do you mean that instead of doing $var = $_POST['var']; echo $var; You would just like to be able to do: echo $var; If so, then this is the behaviour of PHP with the register_globals setting turned on. However, it is a security issue, and should be turned off. You could take all the variables from the POST array and create variables for each with the extract function. But i wouldn't recommend it. Link to comment https://forums.phpfreaks.com/topic/106740-modify-_post/#findComment-547221 Share on other sites More sharing options...
mlin Posted May 22, 2008 Share Posted May 22, 2008 return will ALWAYS end your function and Return the value you asked it to. Without reading the entire thread...this looks like what your looking for: function get_post_vars() { foreach ($_POST as $v) { $post = $v; } return (isset($post) ? $post : false; } that way you'll go loop through the entire array and return After the loop rather than return on the 1st value. the ternary(spelling?) operators help to quickly return false if post hasn't been set at all due to an empty $_POST superglobal hope that helps but to tell you the truth I think your either overthinking it, or your sacrificing a bit of performance in order to make your code look better to yourself, but not necessarily for the next developer to help you with your app. Link to comment https://forums.phpfreaks.com/topic/106740-modify-_post/#findComment-547223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.