You're not passing the connection resource to mysql_real_escape_string() (but you seemingly do so with mysql_select_db()). The connection resource amongst other things stores the connection charset setting which might affect the behavior of real_escape_string().
Either don't pass the resource anywhere or (preferably) pass it always but don't make it even worse than not passing the resource by mixing both.
Benim kitapta, "Güvenlik", aynı zamanda kod "anlaşılabilir", okunabilir ve "düz-ileri" şeyler yapar mı kapsar. Örnekte en az bir SELECT sorgusu bir dize olarak kimliği tedavi zaman tüm !numeric -> die
şube var neden bana açıklamak zorunda olurdu. Benim karşı argüman (örnek olarak duruyor; yanlış olabilir sizin context) "Neden rahatsız SEÇİMİ sadece sayısal olmayan bir kimliği için herhangi bir kayıt döndürmez? Olur" kod azaltır
if ( isset($_GET['post']) ) {
$query = sprintf(
"SELECT x,y,z FROM foo WHERE id='%s'",
mysql_real_escape_string($_GET['post'], $mysqlconn)
);
...
}
Bu automagically is_numeric () (diğer cevaplar açıklandığı gibi) beklendiği gibi davranmasına değil çünkü içine çalışabilir sorun ortadan kaldırır.
edit: And there's something to be said about using die()
to often/to early in production code. It's fine for test/example code but in a live system you almost always want to give control back to the surrounding code instead of just exiting (so your application can handle the error gracefully). During the development phase you might want to bail out early or put more tests in. In that case take a look at http://docs.php.net/assert.
Your example might qualify for an assertion. It won't break if the assertion is deactivated but it might give a developer more information about why it's not working as intended (by this other developer) when a non-numeric argument is passed. But you have to be careful about separating necessary tests from assertions; they are not silver bullets.
If you feel is_numeric() to be an essential test your function(?) might return false, throw an exception or something to signal the condition. But to me an early die() is the easy way out, a bit like a clueless opossum, "I have no idea what to do now. If i play dead maybe no one will notice" ;-)
Kime ipucu hazırlanan tablolarda: http://docs.php.net/pdo.prepared-statements