Well for one thing, when possible don't use the EREGI
or REGEXP functions cause they are slower then simple
string functions.

Second, your script will never get to the bottom two
lines, because if those characters do exist, you've
already exited, and if they don't, the those two lines
don't apply anyway.

If you really want to kill the backtick operator
(which I'm not even sure why as the string that
had that in it, would have to be passed through the
eval() function before it would be an exploit), then
just put:

$string = str_replace('`','',$string);

At the top of your script.


On Tue, 2003-07-29 at 06:17, [EMAIL PROTECTED] wrote:
> Hi to all, any one can tell me, what is the correct way to write secure
> applications in php and how is the best way to remove or prevent the
> backtip operator.
> 
> I think what my code is very insecure.
> What is the correct way to do this ???
> 
> $Myusername = isset($HTTP_POST_VARS['username']) ? trim(htmlspecialchars
> ($HTTP_POST_VARS['username'])) : '';
> 
> $Myusername = substr(str_replace("\'", "'", $Myusername), 0, 25);
> 
> 
>    if ($Myusername ==""){
>       exit;
>    }
>    elseif (eregi(";", $Myusername) ){
>       echo "Hacking attempt";
>       exit;
>    }
>    elseif (eregi("`", $Myusername) ){
>       echo "Hacking attempt";
>       exit;
>    }
> 
>    $Myusername= str_replace("\'", "''", $Myusername) ;
>    $Myusername= str_replace("`", "", $Myusername) ;
> 
> 
> Un saludo, Danny
-- 
Adam Voigt ([EMAIL PROTECTED])
Linux/Unix Network Administrator
The Cryptocomm Group


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to