mysql_real_escape_string HELP!!

Started on the old forum in May 2012 · view the original in the archive · old links redirect here

23 replies · 1,441 views · started 14 years ago · 1 min read

10 participants
icedroplet1987 Senior · 258 posts #1

Hey friends, i will like to know if i parse all data thru

mysql_real_escape_string

then will it protect my site from sql injection?? and its dark-sides?? any harm using it??

likewise this for all get , post, server etc

$msg = mysql_real_escape_string( $_GET['msg'] );

please leave your valuable comments @ all:)

eynesilli Junior · 22 posts #4

how-to here?

if($message!=""){
if(isspam($message))$spam=" reported='1',";
else $spam="";
$res=mysql_query("INSERT INTO inbox SET text='".$message."', byid='".getuid_sid($sid)."', toid='".$who."',$spam timesent='".time()."'");
wap-ruler Developer · 143 posts #5

rep

eynesilli wrote: if($message!=""){ if(isspam($message))$spam=" reported='1',"; else $spam=""; $res=mysql_query("INSERT INTO inbox SET text='".$message."', byid='".getuid_sid($sid)."', toid='".$who."',$spam timesent='".time()."'");

What do u mean by how to plz describe.

ImPoSsIbLe iS nOthInG aS ImPoSsible ItSelF SaYs "I M POSSIBLE"

something else Fellow · 2,296 posts #6

icedroplet1987 wrote: Hey friends, i will like to know if i parse all data thru

mysql_real_escape_string

then will it protect my site from sql injection?? and its dark-sides?? any harm using it??

likewise this for all get , post, server etc

$msg = mysql_real_escape_string( $_GET['msg'] );

please leave your valuable comments @ all:)

not always but depends on how your mysql query's are scripted mysql_real_escape_string() backslashes things such as ' and " however an injection can be as simple as:

OR 1

(no quotes ^ )

eynesilli wrote: if($message!=""){ if(isspam($message))$spam=" reported='1',"; else $spam=""; $res=mysql_query("INSERT INTO inbox SET text='".$message."', byid='".getuid_sid($sid)."', toid='".$who."',$spam timesent='".time()."'");

use:

$message = mysql_real_escape_string($message);

analyzer Developer · 104 posts #7

mysql_real_escape_string() will not be enough brother.

It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

metulj Super moderator Principal · 1,726 posts #8

icedroplet1987 wrote: Hey friends, i will like to know if i parse all data thru mysql_real_escape_string then will it protect my site from sql injection?? and its dark-sides?? any harm using it?? likewise this for all get , post, server etc

$msg = mysql_real_escape_string( $_GET['msg'] );

please leave your valuable comments @ all:)

analyzer wrote: mysql_real_escape_string() will not be enough brother.

i dont see why that wouldnt be enough...?? you mind to explain ?

other than that... i do prefer this

$msg = mysql_real_escape_string(strip_tags(htmlspecialchars($_GET['msg'])));

just to ''sleep better'' 😊

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

eynesilli Junior · 22 posts #9

something else wrote: not always but depends on how your mysql query's are scripted mysql_real_escape_string() backslashes things such as ' and " however an injection can be as simple as:

OR 1

(no quotes ^ )

use:

$message = mysql_real_escape_string($message);

Thanks, but still did not understand anything:(

icedroplet1987 Senior · 258 posts #10

thnx methulj brother.. please also tell, anything wrong in using this?? as i am sure it will protect injection but any harm of it??

other question, i can i make sessions do not expire.. means if user switch off broser n then switch on then also he should be logged in .. just like vbulletin remember me option.. i saw a lavalair site with sessions showing n secured too.. how is it possible n his sessions doesnt expire untill you logout or remove chache.. please enlight this question too @ all..

metulj Super moderator Principal · 1,726 posts #11

icedroplet1987 wrote: thnx methulj brother.. please also tell, anything wrong in using this?? as i am sure it will protect injection but any harm of it??

other question, i can i make sessions do not expire.. means if user switch off broser n then switch on then also he should be logged in .. just like vbulletin remember me option.. i saw a lavalair site with sessions showing n secured too.. how is it possible n his sessions doesnt expire untill you logout or remove chache.. please enlight this question too @ all..

i wouldnt use ednless session... if browser and/or IP has been changed, i believe it is correct that session is ended i might be wrong, but i think that way session is also a bit more secured

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

icedroplet1987 Senior · 258 posts #12

but as i said, i saw site with sessions arent hidden n even not destroying (endless) n perfectly secured thats why i asked so.. if you know you or anybody else on this forum knows it then please share the information on this or codes too.

Added after 10 minutes:

metulj wrote: i dont see why that wouldnt be enough...?? you mind to explain ?

other than that... i do prefer this

$msg = mysql_real_escape_string(strip_tags(htmlspecialchars($_GET['msg'])));

just to ''sleep better'' 😊

and bro, should i parse even $_session , $_server from it.. // i mean all requests??

shushant Developer · 207 posts #13

icedroplet1987 wrote: but as i said, i saw site with sessions arent hidden n even not destroying (endless) n perfectly secured thats why i asked so.. if you know you or anybody else on this forum knows it then please share the information on this or codes too.

Added after 10 minutes:

and bro, should i parse even $_session , $_server from it.. // i mean all requests??

function clean($do = null){
return isset($do) ? mysql_real_escape_string(strip_tags(htmlspecialchars(trim($do)))) : null;
}

useage

echo clean($_POST['var']);//For Post
echo clean($_GET['var']);//FOR get
echo clean($_SERVER['var']);//FOR server
StunningNick Junior · 40 posts #14

icedroplet1987 wrote: Hey friends, i will like to know if i parse all data thru

mysql_real_escape_string

then will it protect my site from sql injection?? and its dark-sides?? any harm using it??

likewise this for all get , post, server etc

$msg = mysql_real_escape_string( $_GET['msg'] );

please leave your valuable comments @ all:)

you may find this link helpful

note : below link contains useful info + free some kinda malware so beware 😛 http://www.itshacked.com/350/bypassing-php-security-mysql_escape_string-while-sql-injection-attacks-is-possible.html

Exploiting hard filtered SQL Injections

also if you don't provide proper charset type, mysql_real_escape_string can't help you, cause default charset is set to UTF-8 according to php bugs report it is fixed way back in 2006 but i still found it working on some sites but not all .

Don't think i am bad , i used to be too good one time...

GumSlone Administrator Principal · 1,690 posts #16

if you put everything into single quotes and mysql_real_escape string then there cant be done much wrong. like

$sql = "select from users where username = '".mysql_real_escape_string($username)."' ";

same with inserts and updates

or use intval() for integer values

$sql = "select from users where id = '".intval($id)."' ";

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

icedroplet1987 Senior · 258 posts #17

GumSlone wrote: if you put everything into single quotes and mysql_real_escape string then there cant be done much wrong. like

$sql = "select from users where username = '".mysql_real_escape_string($username)."' ";

same with inserts and updates

or use intval() for integer values

$sql = "select from users where id = '".intval($id)."' ";

you mean to say that i have to use it in each single mysql call too????

i am already tired of implementing it with get, post etc..

do i have to do in sql queries too?

GumSlone Administrator Principal · 1,690 posts #18

icedroplet1987 wrote: you mean to say that i have to use it in each single mysql call too????

i am already tired of implementing it with get, post etc..

do i have to do in sql queries too?

you have to do it like in my example

$q = mysql_query("select from users where username = '".mysql_real_escape_string($_GET['username'])."' "); 

or

mysql_query("UPDATE users SET age='".intval($_REQUEST['age'])."', user_infos='".mysql_real_escape_string($_REQUEST['user_infos'])."', user_location='".mysql_real_escape_string($_REQUEST['location'])."' WHERE username = '".mysql_real_escape_string($username)."' ");

or

$age = intval($_REQUEST['age']);
$user_infos = mysql_real_escape_string($_REQUEST['user_infos']);
$location = mysql_real_escape_string($_REQUEST['location']);
$username = mysql_real_escape_string($username);
mysql_query("UPDATE users SET age='".$age."', user_infos='".$user_infos."', user_location='".$location."' WHERE username = '".$username."' ");

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

icedroplet1987 Senior · 258 posts #19

GumSlone wrote: you have to do it like in my example

$q = mysql_query("select from users where username = '".mysql_real_escape_string($_GET['username'])."' "); 

or

mysql_query("UPDATE users SET age='".intval($_REQUEST['age'])."', user_infos='".mysql_real_escape_string($_REQUEST['user_infos'])."', user_location='".mysql_real_escape_string($_REQUEST['location'])."' WHERE username = '".mysql_real_escape_string($username)."' ");

or

$age = intval($_REQUEST['age']);
$user_infos = mysql_real_escape_string($_REQUEST['user_infos']);
$location = mysql_real_escape_string($_REQUEST['location']);
$username = mysql_real_escape_string($username);
mysql_query("UPDATE users SET age='".$age."', user_infos='".$user_infos."', user_location='".$location."' WHERE username = '".$username."' ");

i did as the last method.. same which methulj told.. willl it be ok?

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close