
Originally Posted by
city_coder
Do you not think as you do JS that it would be best that the JS figure it out whether 2 fields are the same first?
1. If the javascript catches that they're not the same then its quicker for the user as they dont have to submit and find out they mistyped after its been brought back from the server?
2. Less strain on the server.
Granted its easy enough to compare two strings in PHP but my thinking is speed and ease of use for the developer and the user.
anything that is processed in Javascript would need to be reprocessed in php, thus its really not all that useful. I say this because Javascript can be bypassed by a user submitting the information directly to the processing script, or the user disabling Javascript all together, thus leaving no validation which is obviously REALLY BAD.
Edit: begin
oh and not to forget that you Javascript is viewable to everyone, so the user knows exactly how to get around your sanitation in Javascript, where the PHP code is not viewable to the user, therefore the user doesn't know exactly what the sanitation is.
For this same reason, your error messages should be both intelligent and dumb at the same time. I know its an oxymoron, but what I mean by that is you should inform the user which field had an error, but make them ambiguous enough that a malicious user doesn't know your exact sanitation schema
Edit: end
to compare two strings in php use strcmp as shown below
Code:
$tring1 = "something";
$tring2 = "else";
strcmp($tring1,$tring2);
returns 0 if strings are the same
returns > 0 if first string is greater than second
returns < 0 if second string is greater than first
If you are checking password, you really are only concerned with them being equal
Code:
if(strcmp($tring1,$tring2)!=0)
{
__error__
}
else
{
__success__
}
Bookmarks