Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Dotan Cohen
On 25/01/2008, Jim Lucas <[EMAIL PROTECTED]> wrote: > That should be considered part of the DRY method. But spanning page > requests. > > I cannot see any reason why you shouldn't be doing this before you > insert this information into your DB. Doing it once on your insert, > instead of every sin

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Jim Lucas
Richard Lynch wrote: On Thu, January 24, 2008 12:03 pm, Dotan Cohen wrote: On 24/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: It is NOT safe from, say, XSS attack if $evilString contains an XSS snippet and you re-display it on your site. In other words, you should still filter the INPUT s

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Richard Lynch
On Thu, January 24, 2008 12:03 pm, Dotan Cohen wrote: > On 24/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: >> It is NOT safe from, say, XSS attack if $evilString contains an XSS >> snippet and you re-display it on your site. >> >> In other words, you should still filter the INPUT somewhere; Bu

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Dotan Cohen
On 24/01/2008, Eric Butera <[EMAIL PROTECTED]> wrote: > That won't save you if you're echoing into a single quote attribute. > (ie: src='') Even after I've stripped away the tags with strip_tags()? > Like htmlspecialchars(), the optional second quote_style parameter > lets you define what will be

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Eric Butera
On Jan 24, 2008 1:03 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > On 24/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: > > It is NOT safe from, say, XSS attack if $evilString contains an XSS > > snippet and you re-display it on your site. > > > > In other words, you should still filter the INPUT

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Dotan Cohen
On 24/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: > It is NOT safe from, say, XSS attack if $evilString contains an XSS > snippet and you re-display it on your site. > > In other words, you should still filter the INPUT somewhere; But you > are escaping the output to MySQL so that it is not g

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Richard Lynch
On Thu, January 24, 2008 10:01 am, Dotan Cohen wrote: > On 24/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: >> > Which basically is the same as a simple mysql_real_escape_string? >> In >> > other words, mysql_real_escape_string itself is safe from SQL >> > injection? >> >> not exactly - it assume

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Richard Lynch
On Wed, January 23, 2008 11:28 pm, Dotan Cohen wrote: > In > other words, mysql_real_escape_string itself is safe from SQL > injection? Yes. That is the entire purpose of the existence of that function in the first place. -- Some people have a "gift" link here. Know what I want? I want you to b

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Dotan Cohen
On 24/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: > > Which basically is the same as a simple mysql_real_escape_string? In > > other words, mysql_real_escape_string itself is safe from SQL > > injection? > > not exactly - it assumes you will use the value as a quoted string in a query. > > $s =

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-24 Thread Jochem Maas
Dotan Cohen schreef: On 24/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: On Wed, January 23, 2008 4:04 pm, Dotan Cohen wrote: Is the "--" here not treated as the beginning of an SQL comment? No, because it is inside the apostrophes. The purpose of mysql_real_escape_string (or using prepar

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 24/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: > On Wed, January 23, 2008 4:04 pm, Dotan Cohen wrote: > > Is the "--" here not treated as the beginning of an SQL comment? > > No, because it is inside the apostrophes. > > The purpose of mysql_real_escape_string (or using prepared statements

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Richard Lynch
On Wed, January 23, 2008 3:30 pm, Chris wrote: > >> Right now I still use mysql_escape_string and it seems to work fine, >> but it makes me nervous as everything else I use is mysqli and I >> know >> it is not 100% compatible (just haven't had anything break it yet) - >> but I hate having to have

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Richard Lynch
On Wed, January 23, 2008 3:18 pm, Dotan Cohen wrote: > I think it was here on this list that we saw an example of SQL > injection despite the use of mysql_escape_string. Some funky Asian > charset was used, no? I don't know that I'd call it funky, but yes. Without the "real" MySQL does not know w

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Richard Lynch
On Wed, January 23, 2008 4:04 pm, Dotan Cohen wrote: > Is the "--" here not treated as the beginning of an SQL comment? No, because it is inside the apostrophes. The purpose of mysql_real_escape_string (or using prepared statements) is to mark up (or separate) the DATA from the QUERY. The data a

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Jochem Maas
Chuck schreef: On Jan 22, 2008 7:01 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: I have a file of my own functions that I include in many places. One of them uses mysql_real_escape_string, however, it may be called in a context that will or will not connect to a mysql server, and worse, may alread

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread mike
On 1/23/08, Chris <[EMAIL PROTECTED]> wrote: > If you need to escape something you're going to do a query aren't you? > Or am I missing something here? true. but i typically have everything in wrapper functions, and i don't keep the actual resource variable exposed to use it (since it needs a res

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 24/01/2008, Chuck <[EMAIL PROTECTED]> wrote: > > Why not write a function that does the same thing? > mysql_real_escape_strings is a very simple function. And if your data > is properly normalized and you don't support other charsets its very > simple. > Maintenance and security seem to be two

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Chuck
On Jan 22, 2008 7:01 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > I have a file of my own functions that I include in many places. One > of them uses mysql_real_escape_string, however, it may be called in a > context that will or will not connect to a mysql server, and worse, > may already be conne

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: > Dotan Cohen schreef: > > I'm not accepting "--" at all until someone can show me a real world > > case where one would use it, without the intention of SQL injection. > > How can it be escaped, anyway? > > I might just want to put '--' in a te

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Chris <[EMAIL PROTECTED]> wrote: > > I'm not accepting "--" at all until someone can show me a real world > > case where one would use it, without the intention of SQL injection. > > How can it be escaped, anyway? > > Depends on your app. > > -- is an accepted things in emails as a m

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Jochem Maas
Dotan Cohen schreef: On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: I can read, I saw 2 functions the first time. each function cleans *and* escapes. cleaning is filtering of input. escaping is preparing for output. 2 concepts. I see your point. if the input needs to be stripped of

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Chris
Dotan Cohen wrote: On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: I can read, I saw 2 functions the first time. each function cleans *and* escapes. cleaning is filtering of input. escaping is preparing for output. 2 concepts. I see your point. if the input needs to be stripped of h

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Chris
Right now I still use mysql_escape_string and it seems to work fine, but it makes me nervous as everything else I use is mysqli and I know it is not 100% compatible (just haven't had anything break it yet) - but I hate having to have a connection handle open just to escape things. If you need

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Chris
Dotan Cohen wrote: On 23/01/2008, mike <[EMAIL PROTECTED]> wrote: It would be Real Nifty (tm) if the MySQL API had a function that let you specify the charset without a connection and did the escaping. Presumably you don't NEED a connection if you already know what charset thingie you are aimin

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: > I can read, I saw 2 functions the first time. each function cleans *and* > escapes. > > cleaning is filtering of input. > escaping is preparing for output. > > 2 concepts. I see your point. > if the input needs to be stripped of html then i

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Eric Butera <[EMAIL PROTECTED]> wrote: > There isn't a reason to go and report a bug as their stuff works fine. I would have filed a wish, not a bug. They are both filed in the bugzillas that I'm familiar with. In any case, I'm not filing as I've no account there and I'll not be fil

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, mike <[EMAIL PROTECTED]> wrote: > > > It would be Real Nifty (tm) if the MySQL API had a function that let > > > you specify the charset without a connection and did the escaping. > > > > > > Presumably you don't NEED a connection if you already know what > > > charset thingie you ar

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: > On Wed, January 23, 2008 12:47 pm, Dotan Cohen wrote: > > On 23/01/2008, Eric Butera <[EMAIL PROTECTED]> wrote: > >> On Jan 22, 2008 8:01 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > > However, I do not think that the script should throw an

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Jochem Maas
Dotan Cohen schreef: On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: you don't understand what I mean. input filtering is a seperate task to output filtering. you filter and validate all input to the script regardless of how you are going to use it. THEN you escape the filtered, validated

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Eric Butera
On Jan 23, 2008 2:37 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > On 23/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: > > Back to the original question... > > > > I suppose you could use mysql_escape_string (note the lack of "real") > > in the short term... > > I'd rather not. There is no short

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread mike
> > It would be Real Nifty (tm) if the MySQL API had a function that let > > you specify the charset without a connection and did the escaping. > > > > Presumably you don't NEED a connection if you already know what > > charset thingie you are aiming at... I concur - it would be nice to have the c

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Richard Lynch
On Wed, January 23, 2008 12:47 pm, Dotan Cohen wrote: > On 23/01/2008, Eric Butera <[EMAIL PROTECTED]> wrote: >> On Jan 22, 2008 8:01 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > However, I do not think that the script should throw an error until I > actually call mysql_clean. Merely having it in a

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: > Back to the original question... > > I suppose you could use mysql_escape_string (note the lack of "real") > in the short term... I'd rather not. There is no short term. > It would be Real Nifty (tm) if the MySQL API had a function that le

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Richard Lynch
On Wed, January 23, 2008 11:47 am, Dotan Cohen wrote: > On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: >> for each output (output to mysql, output to browser, etc) Back to the original question... I suppose you could use mysql_escape_string (note the lack of "real") in the short term... I

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Eric Butera <[EMAIL PROTECTED]> wrote: > On Jan 22, 2008 8:01 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > > I have a file of my own functions that I include in many places. One > > of them uses mysql_real_escape_string, however, it may be called in a > > context that will or will no

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Eric Butera
On Jan 22, 2008 8:01 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > I have a file of my own functions that I include in many places. One > of them uses mysql_real_escape_string, however, it may be called in a > context that will or will not connect to a mysql server, and worse, > may already be conne

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread James Ausmus
On Jan 23, 2008 10:03 AM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > On 23/01/2008, James Ausmus <[EMAIL PROTECTED]> wrote: > > Try using the mysql_ping() command to check to see if your connection > > is available: > > > > http://us2.php.net/manual/en/function.mysql-ping.php > > > > something like:

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, James Ausmus <[EMAIL PROTECTED]> wrote: > Try using the mysql_ping() command to check to see if your connection > is available: > > http://us2.php.net/manual/en/function.mysql-ping.php > > something like: > > > if ([EMAIL PROTECTED]()) //Note the @ is because, if mysql_ping cannot g

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread James Ausmus
Try using the mysql_ping() command to check to see if your connection is available: http://us2.php.net/manual/en/function.mysql-ping.php something like: HTH- James On Jan 22, 2008 6:04 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > On 23/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: > > >

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: > you don't understand what I mean. > > input filtering is a seperate task to output filtering. > you filter and validate all input to the script regardless of > how you are going to use it. THEN you escape the filtered, validated data > for eac

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Jochem Maas
Dotan Cohen schreef: On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: The file defines some of my own functions, like these: function clean_html ($dirty) { $dirty=strip_tags($dirty); $clean=htmlentities($dirty); return $clean; } function clean_mysql ($dirty) { $dirty=str_r

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Dotan Cohen
On 23/01/2008, Jochem Maas <[EMAIL PROTECTED]> wrote: > > The file defines some of my own functions, like these: > > > > function clean_html ($dirty) { > > $dirty=strip_tags($dirty); > > $clean=htmlentities($dirty); > > return $clean; > > } > > > > function clean_mysql ($dirty) { > >

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-23 Thread Jochem Maas
Dotan Cohen schreef: On 23/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: On Tue, January 22, 2008 7:01 pm, Dotan Cohen wrote: I have a file of my own functions that I include in many places. One of them uses mysql_real_escape_string, however, it may be called in a context that will or will

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-22 Thread Dotan Cohen
On 23/01/2008, Richard Lynch <[EMAIL PROTECTED]> wrote: > > > On Tue, January 22, 2008 7:01 pm, Dotan Cohen wrote: > > I have a file of my own functions that I include in many places. One > > of them uses mysql_real_escape_string, however, it may be called in a > > context that will or will not con

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-22 Thread Richard Lynch
On Tue, January 22, 2008 7:01 pm, Dotan Cohen wrote: > I have a file of my own functions that I include in many places. One > of them uses mysql_real_escape_string, however, it may be called in a > context that will or will not connect to a mysql server, and worse, > may already be connected. So

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-22 Thread Dotan Cohen
On 23/01/2008, Chris <[EMAIL PROTECTED]> wrote: > Dotan Cohen wrote: > > I have a file of my own functions that I include in many places. One > > of them uses mysql_real_escape_string, however, it may be called in a > > context that will or will not connect to a mysql server, and worse, > > may alr

Re: [PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-22 Thread Chris
Dotan Cohen wrote: I have a file of my own functions that I include in many places. One of them uses mysql_real_escape_string, however, it may be called in a context that will or will not connect to a mysql server, and worse, may already be connected. So I must avoid connecting. However, when I r

[PHP] Using mysql_real_escape_string without connecting to mysql

2008-01-22 Thread Dotan Cohen
I have a file of my own functions that I include in many places. One of them uses mysql_real_escape_string, however, it may be called in a context that will or will not connect to a mysql server, and worse, may already be connected. So I must avoid connecting. However, when I run the script without

Re: [PHP] Using mysql_real_escape_string

2006-10-10 Thread Richard Lynch
On Mon, October 9, 2006 1:53 pm, Alan Milnes wrote: > $filename="input/w2wcheck.txt"; > > echo "$filename"; > > # Open file > $fptr = fopen($filename, "r"); > > # Check if file is open > if($fptr) { > $current_line = fgets($fptr,4096); > > $retval = TRUE; > echo "open"; > > wh

Re: [PHP] Using mysql_real_escape_string

2006-10-10 Thread Alan Milnes
Thanks everyone. Alan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Using mysql_real_escape_string

2006-10-09 Thread Eric Butera
On 10/9/06, Alan Milnes <[EMAIL PROTECTED]> wrote: $query = "insert into invw2wcheck ( UNIQUEID, ASSETID , CNF ) values ( '$UNIQUEID', '$ASSETID ', '$CNF' )"; Wrap escaping functions around the values you are sticking in the DB. Escaping is only needed at the time you are usin

Re: [PHP] Using mysql_real_escape_string

2006-10-09 Thread tg-php
mysql_real_escape_string() is a function that returns the post-processed value. So you can either do it like this: $safe_value = mysql_real_escape_string($unsafe_value); then use $safe_value in your query, or put the function right into your query: $myQY = "INSERT INTO sometable (value) values

[PHP] Using mysql_real_escape_string

2006-10-09 Thread Alan Milnes
OK this should be really obvious but I just can't figure it out. I have a script that opens a file, reads it line by line and inserts the contents into a database. I know I need to use mysql_real_escape_string to properly escape the contents but I don't know where exactly to place it in the