Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-21 Thread Jim Lucas
Dotan Cohen wrote: >> If you look a little closer, you will see that I am not using addslashes(). >> Rather, I am using addcslashes(). This allows to specify the characters >> that I want escaped, instead of the default assumed characters from >> addslashes(). >> > > I do not know which characte

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-21 Thread Dotan Cohen
> Thinking a little deeper here, you say you are concerned about the character > type, yet you say that it is all assumed UTF-8.  Is everything going to be > UTF-8 > or something else? > > If it is all going to be UTF-8, then the addcslashes() variation above will > work. > It _should_ all be UT

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-21 Thread Dotan Cohen
> If you look a little closer, you will see that I am not using addslashes(). >  Rather, I am using addcslashes().  This allows to specify the characters > that I want escaped, instead of the default assumed characters from > addslashes(). > I do not know which characters to escape. -- Dotan Coh

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-21 Thread Jim Lucas
Jim Lucas wrote: > Dotan Cohen wrote: >>> So, actually taking a minute to read up on addcslashes(), it is a >>> rather handy >>> little function. >>> >>> Taking the list of characters that mysql_real_escape_string() says it >>> escapes: >>> >>> http://us3.php.net/mysql_real_escape_string >>> >>> Wh

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-21 Thread Jim Lucas
Dotan Cohen wrote: So, actually taking a minute to read up on addcslashes(), it is a rather handy little function. Taking the list of characters that mysql_real_escape_string() says it escapes: http://us3.php.net/mysql_real_escape_string Which it lists: \x00, \n, \r, \, ', " and \x1a \0 = \x

RE: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-21 Thread Andrea Giammarchi
bject: Re: [PHP] Sanitizing potential MySQL strings with no database > connection > > > if(@mysql_real_escape_string($variable) === false) > > > > Perfect! The @ symbol suppresses the error and I can structure the > code according to whether or not there is a connecti

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-21 Thread John Black
Dotan Cohen wrote: So far as I understand mysql_real_escape_string() was invented because addslashes() is not adequate. Correct, addslashes() works fine for latin1 (single byte encoding) but does not work properly when used with a multibyte encoded string. That is most likely the reason why my

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-21 Thread Dotan Cohen
> So, actually taking a minute to read up on addcslashes(), it is a rather handy > little function. > > Taking the list of characters that mysql_real_escape_string() says it escapes: > > http://us3.php.net/mysql_real_escape_string > > Which it lists: \x00, \n, \r, \, ', " and \x1a > > \0  = \x0 > \

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Ray Solomon
- Original Message - From: "Ashley Sheridan" To: "Dotan Cohen" Cc: "Jim Lucas" ; "php-general." Sent: Tuesday, October 20, 2009 4:02 AM Subject: Re: [PHP] Sanitizing potential MySQL strings with no database connection On Tue, 2009

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Jim Lucas
Jim Lucas wrote: > Dotan Cohen wrote: >> 2009/10/19 Kim Madsen : >>> Dotan Cohen wrote on 2009-10-18 21:21: >>> I thought that one could not test if a database connection is established or not, this is the most relevant thing that I found while googling that: http://bugs.php.net

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Nisse Engström
On Tue, 20 Oct 2009 20:04:51 +0200, Nisse Engström wrote: > On Mon, 19 Oct 2009 15:39:40 -0700, Jim Lucas wrote: > >> /** >>* Character to escape... >>* \x0 \n \r \ ' " \x1a >> **/ >> >> $patterns = array( "\x0", "\n", "\r", "\\", "'","\"", "

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Dotan Cohen
> if(@mysql_real_escape_string($variable) === false) > Perfect! The @ symbol suppresses the error and I can structure the code according to whether or not there is a connection. Thank you! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- PHP General Mailing List (http://www.p

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Shawn McKenzie
Dotan Cohen wrote: > 2009/10/20 Andrea Giammarchi : >> even better >> >> $error_reporting = error_reporting(0); >> if(mysql_real_escape_string($variable) === false) >> { >> error_reporting($error_reporting); >> >> // create a default DB connection >> >> } else >> error_reporting($error_

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Dotan Cohen
>   If you're sure that all your data is UTF-8, and that > all user-supplied data is *actually valid* UTF-8 (and > not deliberately or accidentally malformed), then > mysql_escape_string() should be just fine [1]. > I cannot ensure that the users will not be malicious, even if it is all internal u

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Kim Madsen
Dotan Cohen wrote on 2009-10-20 20:06: if(mysql_real_escape_string($variable) === false) { // create a default DB connection } Here, the key seems to be to turn the warning level down, which I do not have privileges to do on this server. But it fact this seems to be the key that I was mis

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Dotan Cohen
2009/10/20 Andrea Giammarchi : > even better > > $error_reporting = error_reporting(0); > if(mysql_real_escape_string($variable) === false) > { >     error_reporting($error_reporting); > >     // create a default DB connection > > } else >     error_reporting($error_reporting); > unset($error_repor

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Dotan Cohen
> No, and you clearly missed the point about that function being pretty much > dead anyway. > I understand that mysql_escape_string() is depreciated. Asking about other similar functions does not seem out of line. > You mentioned also in your last email that you would make a DB connection if >

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Nisse Engström
On Mon, 19 Oct 2009 15:39:40 -0700, Jim Lucas wrote: > I have no idea if it will work, [...] Well, you're right so far... > > function clean_string($input) { > > /** >* Character to escape... >* \x0 \n \r \ ' " \x1a > **/ > > $patterns = array(

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Nisse Engström
On Tue, 20 Oct 2009 14:58:32 +0200, Dotan Cohen wrote: >> Yes, the mysql_real_escape_string() function uses the databases >> character encoding to determine how to encode the string, whereas the >> older deprecated version mysql_escape_string() required no connection >> as it always assumed Latin-

RE: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Andrea Giammarchi
To: a...@ashleysheridan.co.uk; dotanco...@gmail.com > CC: php-general@lists.php.net > Date: Tue, 20 Oct 2009 15:50:52 +0200 > Subject: RE: [PHP] Sanitizing potential MySQL strings with no database > connection > > > > If says: > > > > Returns the escaped string, o

RE: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Andrea Giammarchi
> If says: > > Returns the escaped string, or FALSE on error. > > So all you have to do, is have warnings turned off (as it generates an > E_WARNING if you have no active connection) and then look at the return > value of a call to the function: > > if(mysql_real_escape_string($variable) === fa

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Ashley Sheridan
On Tue, 2009-10-20 at 14:58 +0200, Dotan Cohen wrote: > > Yes, the mysql_real_escape_string() function uses the databases character > > encoding to determine how to encode the > > string, whereas the older deprecated version mysql_escape_string() required > > no connection as it always assumed >

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Dotan Cohen
> Yes, the mysql_real_escape_string() function uses the databases character > encoding to determine how to encode the > string, whereas the older deprecated version mysql_escape_string() required > no connection as it always assumed > Latin-1 (as far as I know) Is there such a function that alwa

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Dotan Cohen
> Your only option might be to do something "smart". You can't use the proper > mysql functions without a connection to a > database, but you refuse to connect to a database until after you perform > validation... > More accurate to say that the file in which the function is stored does not know

RE: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Ashley Sheridan
On Tue, 2009-10-20 at 08:43 -0400, Bob McConnell wrote: > From: Ashley Sheridan > > > On Tue, 2009-10-20 at 14:20 +0200, Andrea Giammarchi wrote: > >> > Your only option might be to do something "smart". You can't use > the > >> > proper mysql functions without a connection to a database, but you

RE: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Bob McConnell
From: Ashley Sheridan > On Tue, 2009-10-20 at 14:20 +0200, Andrea Giammarchi wrote: >> > Your only option might be to do something "smart". You can't use the >> > proper mysql functions without a connection to a database, but you >> > refuse to connect to a database until after you perform validat

RE: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Ashley Sheridan
On Tue, 2009-10-20 at 14:20 +0200, Andrea Giammarchi wrote: > > > Your only option might be to do something "smart". You can't use the > > proper mysql functions without a connection to a database, but you > > refuse to connect to a database until after you perform validation... > > > > You do r

RE: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Andrea Giammarchi
> Your only option might be to do something "smart". You can't use the > proper mysql functions without a connection to a database, but you > refuse to connect to a database until after you perform validation... > > You do realise you can have several db connections open at one time, so > you co

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Dotan Cohen
> Dotan, > > You are making this thing harder then it has to be. > > All you need is to replicate the escaping of the same characters that > mysql_real_escape_string() escapes.  Simply do that.  They are listed on the > functions manual page on php.net > > http://php.net/mysql_real_escape_string >

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-20 Thread Ashley Sheridan
On Tue, 2009-10-20 at 12:58 +0200, Dotan Cohen wrote: > > Dotan, > > > > You are making this thing harder then it has to be. > > > > All you need is to replicate the escaping of the same characters that > > mysql_real_escape_string() escapes. Simply do that. They are listed on the > > functions

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-19 Thread Jim Lucas
Dotan Cohen wrote: > 2009/10/19 Kim Madsen : >> Dotan Cohen wrote on 2009-10-18 21:21: >> >>> I thought that one could not test if a database connection is >>> established or not, this is the most relevant thing that I found while >>> googling that: >>> http://bugs.php.net/bug.php?id=29645 >> from

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-19 Thread Dotan Cohen
2009/10/19 Kim Madsen : > Dotan Cohen wrote on 2009-10-18 21:21: > >> I thought that one could not test if a database connection is >> established or not, this is the most relevant thing that I found while >> googling that: >> http://bugs.php.net/bug.php?id=29645 > > from http://www.php.net/manual/

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-19 Thread Kim Madsen
Dotan Cohen wrote on 2009-10-18 21:21: I thought that one could not test if a database connection is established or not, this is the most relevant thing that I found while googling that: http://bugs.php.net/bug.php?id=29645 from http://www.php.net/manual/en/function.mysql-connect.php $link =

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-18 Thread Dotan Cohen
> test if you have a db connection in the function, if not, skip MRES and > other mysql_ functions? > I thought that one could not test if a database connection is established or not, this is the most relevant thing that I found while googling that: http://bugs.php.net/bug.php?id=29645 > In my op

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-18 Thread Kim Madsen
Dotan Cohen wrote on 2009-10-18 10:52: I assumed the reason you wanted to do escape the string so that you could perform DB operations. Yes, that is my intention. However, the function is found in an include file of functions used in many different scripts, each of which connect to a different

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-18 Thread Dotan Cohen
> I assumed the reason you wanted to do escape the string so that you could > perform DB operations. Yes, that is my intention. However, the function is found in an include file of functions used in many different scripts, each of which connect to a different database or may not connect to a data

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-18 Thread Jim Lucas
Dotan Cohen wrote: How can I configure mysql_real_escape_string() to _not_ need a database connection in order to do it's work on a string. I understand that the function wants a database connection to determine which charset / encoding is in use, but in my case it will always be UTF-8. I have a

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-17 Thread Tommy Pham
- Original Message > From: Dotan Cohen > To: Tommy Pham > Cc: php-general. > Sent: Sat, October 17, 2009 10:59:52 AM > Subject: Re: [PHP] Sanitizing potential MySQL strings with no database > connection > > > I don't think so since the mysql

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-17 Thread Dotan Cohen
> I don't think so since the mysql_real_escape_string() requires a connection > handler.  Why not use bind param? > Thanks. I just googled bind param but I am still a bit unclear as to what is going on. To be clear, I have a file of functions that I use in many scripts, lets call it functions.in

Re: [PHP] Sanitizing potential MySQL strings with no database connection

2009-10-16 Thread Tommy Pham
- Original Message > From: Dotan Cohen > To: php-general. > Sent: Fri, October 16, 2009 7:13:41 PM > Subject: [PHP] Sanitizing potential MySQL strings with no database connection > > How can I configure mysql_real_escape_string() to _not_ need a > database conn

[PHP] Sanitizing potential MySQL strings with no database connection

2009-10-16 Thread Dotan Cohen
How can I configure mysql_real_escape_string() to _not_ need a database connection in order to do it's work on a string. I understand that the function wants a database connection to determine which charset / encoding is in use, but in my case it will always be UTF-8. I have a file of reusable fun