$ _POST Question in PHP

public function doLogin($username,$password) {

      

I am getting username and password as arguments and am not using POST method on my form which is in flex using remote object.

Now how can I get it in PHP without using a formal way.

if (isset($_POST['username']) && isset($_POST['password']))
        {
        $username= $_POST['username'];
        $password= $_POST['password'];

      

I did the test and the code below works and now I need a better way of getting that is also safe.

if($username == "rishi" && $password == "indian" ) 
            {
                return 'yes';

            }
            else {
                return 'no';
            }

      

0


a source to share


2 answers


You can use phpinfo()

to find out where your parameters are going. It seems like register_globals might be allowed, which is not practical.



+3


a source


As far as I can tell from your question, your problem is this:

Your page came in from Adobe Flash and apparently not with a POST request as the code you are expecting. How can you get the username and password that were transferred?

If the request is not a POST, it is most likely a GET. Then you can just get the username and password from the $ _GET array like this:



if ($_GET["username"] == "monkey" && $_GET["password"] == "bar") {
    echo "Success!";
}
else {
    echo "Not allowed";
}

      

You don't have to actually code it; it's just to illustrate how to get arguments from the $ _GET array. However, without further information on what exactly you are trying to achieve, I cannot give you any further advice.

Note. If you want your code to work with both GET and POST requests, you can also read the parameters from the $ _REQUEST array. Please note, however, as the cookies also end up in this array and may give unexpected results if they have the same name.

+1


a source







All Articles