Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $_GET['variable']gets corrpupted

    Hi, while I was developing I discovered that one of the $_GET['variable']gets corrpupted. I've search the forums, to date there seems to be no answer, very frustrating.

    Here's my code

    $_GET['Mobile']gets corrpupted

    <?php

    //starting from version callsorbalance3.php will pass in password
    include ("Conf_Main.php");

    if(isset($_GET['Mobile'])){ echo"<br>\$Mobile get mobile: $Mobile";$Mobile = $_GET['Mobile'];}
    else if (isset($_POST['Mobile'])){ echo"<br>\$Mobile post mobile: $Mobile";$Mobile = $_POST['Mobile'];}
    else $Mobile="";

    if(isset($_GET['password'])){ $Mobile = $_GET['password'];}
    else if (isset($_POST['password'])){ $password = $_POST['password'];}
    else $password="";


    echo"<br>\$Mobile: $Mobile";
    echo"<br>\$password: $password";
    ?>

    When I echo the value of $Mobile in the if statement, it is correct, when it is outside, the value is wrong.

    My question is how come my mobile value becomes my password?

    Thansk a lot

    rgds

  • #2
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Quote Originally Posted by chleng
    if(isset($_GET['password'])){ $Mobile = $_GET['password'];}
    else if (isset($_POST['password'])){ $password = $_POST['password'];}
    else $password="";


    echo"<br>\$Mobile: $Mobile";
    echo"<br>\$password: $password";
    I dont think its "corruption" causing your problem. I think it's your script at the part just above.

    eg. if(isset($_GET['password'])){ $Mobile = $_GET['password'];}

    From what I can see, this is why

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    if(isset($_GET['password'])){ $Mobile = $_GET['password'];}
    I don't see anything wrong with this...

    Go like this for example:
    PHP Code:
    if (isset($_GET['mobile']))
    {
         echo 
    'Get: ' $_GET['mobile'];
    }
    if (isset(
    $_POST['mobile']))
    {
         echo 
    '<br />Post: ' $_POST['mobile'];

    If you end up with this:
    Code:
    Get: {MOBILE_VALUE}
    POST:
    Your problem is simple. isset() isn't what you want to use. It will normally work fine on a $_GET variable, but its different when it comes to $_POST. isset() function checks for the existance of the value you are searching for - NULL is a value. When you submit a form with empty fields, it will return the $_POST['FIELD'] = NULL, which will return true with an isset() function. Instead of using isset, use !empty() instead, as it will ensure that the field is not empty.
    If your output is different than above, we'll need to look deeper into the problem. Otherwise, you can only have the 'Post:' part show if $_POST is a valid field.
    The only other part I see thats incorrect is you are outputing information before the variable is set. If you use error_reporting(E_ALL) it will tell you of this uninitialized variable.

    Oh, BTW, you can either use (or create and use) a $_REQUEST variable with a merging of your $_GET and $_POST fields. If you do this, you can trim a lot off of your code by only needing to access your if statments with $_REQUEST['mobile'] for instance. Note that $_REQUEST may not be set automatically for you, and if its is not, merge it to create it:
    PHP Code:
    $_REQUEST array_merge($_GET$_POST); 
    for example. (Personally, I add $_COOKIE too, but thats me.)
    Last edited by Fou-Lu; 07-11-2005 at 07:10 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •