View Full Version : $_GET['variable']gets corrpupted

07-11-2005, 01:40 PM
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


//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


07-11-2005, 01:51 PM
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 :)

07-11-2005, 07:06 PM
if(isset($_GET['password'])){ $Mobile = $_GET['password'];}
I don't see anything wrong with this...

Go like this for example:

if (isset($_GET['mobile']))
echo 'Get: ' . $_GET['mobile'];
if (isset($_POST['mobile']))
echo '<br />Post: ' . $_POST['mobile'];

If you end up with this:


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:

$_REQUEST = array_merge($_GET, $_POST);

for example. (Personally, I add $_COOKIE too, but thats me.)