PHP string comparing with ===
NickName:Antonio Ask DateTime:2011-09-18T10:52:38

PHP string comparing with ===

I'm making a login script for my site.

It sends a POST (using curl) to another server with the user pass etc.
If the info is wrong it returns Bad login

But when I check the reply even if it's wrong it will say the login is successful.

if ($result === "Bad login"){
    $password_status = 'Wrong password.';
    $error = true;
}

i have also tried strcmp as well with no success.

Copyright Notice:Content Author:「Antonio」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7459198/php-string-comparing-with

Answers
drew010 2011-09-18T02:56:27

Yes, try var_dump($result) because it may contain other characters.\n\nMaybe try:\n\n<?php\nif (strpos(strtolower($result), 'bad login') !== false) {\n $error = true;\n}\n",


More about “PHP string comparing with ===” related questions

PHP - Comparing double to a string is weird?

I'm seeing some weird behavior in php when comparing a double to a string and was hoping someone could explain to me what is going on. If I declare $num = 0.333; and then test $num == '0.333', t...

Show Detail

PHP function for comparing two variable?

Is there any PHP function for comparing two string variable with the third parameter are comparison operators and return boolean. Example: $string1 = "Foo"; $string2 = "Bar"; $result =

Show Detail

string comparing

i actually i post data in php through post method and if the data is currectly send in php and i get the response and convert into String format. The problem is that i get the response and i check...

Show Detail

Is comparing MySQL dates string formats in PHP correct?

I have been comparing mysql dates in php by doing this: &lt;?php strtotime('2007-12-12 10:00:01') &gt; strtotime('2007-12-12 10:00:00') I just found out that if you compare 2 dates (format Y-m-d...

Show Detail

Comparing two unicode strings in PHP

I am stuck in comparing two unicode strings in PHP which both contain the special char 'ö'. One string comes from $_GET, the other one is a filesystem's folder name (scandir()). Both strings seem t...

Show Detail

Subclipse: Problem comparing php files

Is anyone else having problems comparing php files in subclipse? Whenever I attempt to compare my working file with the one in the repository, I get a blank screen or it hangs with the message "

Show Detail

PHP comparing String to a Char

I'm having troubles looking at comparing a string with a char. I have a dropdown menu with two options 1. Coach 2. Athlete. When submitted, values "C" or "A" are stored in my database under "type"....

Show Detail

PHP comparing UNIX timestamps

I've having an issue comparing two unix timestamps in php. $time_now = mktime(); if($auction-&gt;time_end &gt; $time_now){ //true } else{ //false } $auction->time_end is 1362579127 and set ..

Show Detail

comparing string with accents in php

I'm having problems when comparing two strings which contains accents. This is my case: The first string is: Master The second string is: Máster Diseño Producción Then, I need to remove the word

Show Detail

Comparing value from object with string in PHP

I'm comparing a string within an object to a string from a standard variable and even though they "look" the same when echoing them out, the if statement never finds that they match. Also, both val...

Show Detail