Jump to content

modify $_POST


adv

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.