0

I am verifying a user (email address and password) in database and and echo the result.

if($num_rows == 1)
{
    $usertypeid = mysql_fetch_array($query_result);
    echo $usertypeid[0];
}
else
{
    echo "invalid_user";
}

When i test it on a normal browser it prints exactly what i want. When I do http request from android, it returns the string correct. But it has something garbage value at first byte I guess which is not visible though.

HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
strResult = EntityUtils.toString(httpEntity);

Then I am comparing strResult with a final string and check if it is not a failure.

if (!strResult.equals(Konstant.HTTP_RESULT_SIGNIN_FAILURE))

So, when strResult is actually "invalid_user" the condition should not pass. But it passes.

String value of HTTP Response

Final String value

If i use "endsWith()" instead of "equals()", it works fine. or If i use substring() to eliminate first byte and then use equals, it works fine.

Can anyone please help me what's happening here?

8
  • Have you tried to encode you PHP script file with UTF-8 without BOM? Commented Mar 13, 2014 at 18:27
  • @tato.rodrigo How do I do that? Commented Mar 13, 2014 at 19:27
  • What editor are you using? I use Notepad++ and it has a option to convert the file encoding under the "Format" menu. It worth give a try. Commented Mar 13, 2014 at 20:50
  • I use Notepadd++ too. And it is already UTF-8 encoding. Commented Mar 18, 2014 at 17:33
  • I don't know What is BOM? Commented Mar 19, 2014 at 6:33

1 Answer 1

1

You should encode the file as UTF-8 without BOM.

On Notepad++ you can do it by clicking the "Encoding" menu and then click the "Convert to UTF-8 (without BOM)" option.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.