Forum Moderators: coopster

Message Too Old, No Replies

PHP not parsing query string right

         

iJeep

10:17 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



I have a problem with a couple of my PHP scripts that every now and then they don't parse the query string right.

If I have a form with an e-mail and password feild sometimes it reads the e-mail field as "username?password=enteredpassword" instead of breaking them apart.

It doesn't do it all of the time. I cannot figure out what is going on.

Any suggestions?

coopster

10:56 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What do your <form> tag and <input> tags look like?

Timotheos

11:11 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe they're putting in special characters. If the value has a '?' or '&' then it can confuse the query string. Why that would be in an email field I do not know but you might need to use urlencode before sending the value.

iJeep

11:53 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



In the one that I can consistently get to give me problems the only special characters are "@" and "_".

Here is the form:

<form method="post" action="verify.php" style="margin:0px;padding:0px">
<table><tr><td style="text-align:right;font-weight:bold">E-Mail</td><td><input type="text" name="txtUsername" size="20"></td></tr>
<tr><td style="text-align:right;font-weight:bold">Password</td><td><input type="password" name="txtPassword" size="10"></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" value="LOG IN"></td></tr>
</table>
<br><a href="register.php">Not a member? Register Here.</a></form>

I have tried changing between post and get methods and neither makes a difference. In the GET method the query string looks normal, but is not encoded.

Timotheos

12:42 am on Jan 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So have you printed out your variables at the top of the verify page like this just to make sure?
<?php
echo "<pre>";
print_r ($_GET) . "<br>";
echo "</pre>";
?>

Your query string must look like so
verify.php?txtUsername=username&txtPassword=enteredpassword

which I can't figure out why you'd get
username?password=enteredpassword

coopster

12:48 am on Jan 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Also, how are you accessing the variables? Because your <form> and <input> tags look fine. In your PHP script, you should be accessing the variables through the $_POST array ( assuming you are on PHP >= 4.1.0 )

$txtUsername = (isset($_POST['txtUsername']))? $_POST['txtUsername'] : '';
$txtPassword = (isset($_POST['txtPassword']))? $_POST['txtPassword'] : '';

If you are on PHP < 4.1.0...

$txtUsername = (isset($HTTP_POST_VARS['txtUsername']))? $HTTP_POST_VARS['txtUsername'] : '';
$txtPassword = (isset($HTTP_POST_VARS['txtPassword']))? $HTTP_POST_VARS['txtPassword'] : '';