Filltering
Started on the old forum in January 2010 · view the original in the archive · old links redirect here
you can try something like this:
$text = preg_replace('/[^[:alnum:]\-\.\_\^]/', '', $text);
Advertise your mobile site for FREE with AdTwirl
why into if statement?
Advertise your mobile site for FREE with AdTwirl
Ok here is what I got
$text = preg_replace('/[^[:alnum:]\-\.\_\^]/', '', $username);
if($text == true)
{
die ("Unsupported character(s)");
}
Visit my site http://darkstorm.za.net
no, for what you need the filtering? password or username?
Advertise your mobile site for FREE with AdTwirl
I want to remove any special characters from username, password to help prevent mysql injection as for the email I need to allow the @ symbol
Visit my site http://darkstorm.za.net
to prevent mysql injection use: mysql_real_escape_string PHP: mysql_real_escape_string - Manual
Advertise your mobile site for FREE with AdTwirl
yes thats all
Advertise your mobile site for FREE with AdTwirl
one other way
put this in your confg.php or ini.php
function scharin($word)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
for($i=0;$i<strlen($word);$i++)
{
$ch = substr($word,$i,1);
$nol = substr_count($chars,$ch);
if($nol==0)
{
return true;
}
}
return false;
}
put this line in your register.php and you replace $login to your user name etc
if(scharin($login) == true) $error=$error.'Invalid Characters in Nick!<br/>';
and
if(strlen($login)<3) $error=$error.'Nick should be Minimum of 3 words!<br/>';
if you need more and strong filter send me pm will tell you 8)
left wap stuff
GiLL wrote: put this in your confg.php or ini.php
function scharin($word) { $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; for($i=0;$i<strlen($word);$i++) { $ch = substr($word,$i,1); $nol = substr_count($chars,$ch); if($nol==0) { return true; } } return false; }put this line in your register.php and you replace $login to your user name etc
if(scharin($login) == true) $error=$error.'Invalid Characters in Nick!<br/>';and
if(strlen($login)<3) $error=$error.'Nick should be Minimum of 3 words!<br/>';if you need more and strong filter send me pm will tell you 8)
this is not a good solution to prevent mysql injection
Advertise your mobile site for FREE with AdTwirl
It would be nice just be use 1234567890abcdefghijklmnopqrstuvwxyz nothing else
Visit my site http://darkstorm.za.net
This thread is going to help alot of people who are new to Php I personally find filtering to be a pain.
Visit my site http://darkstorm.za.net
GumSlone wrote: this is not a good solution to prevent mysql injection
yeah but at last it can stop special characters and we can use mysql_real_escape_string also bad char function or lets use
if(!get_magic_quotes_gpc())
{
$_GET = array_map('mysql_real_escape_string', $_GET);
$_POST = array_map('mysql_real_escape_string', $_POST);
$_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
else
{
$_GET = array_map('stripslashes', $_GET);
$_POST = array_map('stripslashes', $_POST);
$_COOKIE = array_map('stripslashes', $_COOKIE);
$_GET = array_map('mysql_real_escape_string', $_GET);
$_POST = array_map('mysql_real_escape_string', $_POST);
$_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
left wap stuff
Ok im using mysql_real_escape_string in XAMPP but the special characters are still going in the database
Visit my site http://darkstorm.za.net
ok, so you want to prevent mysql injection or filter special chars?
- if you want to filter special chars use the first code ive posted,
- if you want to prevent mysql injection use mysql_real_escape_string
- if you want to filter chars and prevent mysql injection use both.
- and if you only want to check username for special chars you can use this:
if (preg_match("/[^\da-zA-Z-._]+/", $username))
$error .= 'Incorrect username! Please avoid spaces and special chars.';
fershtein?
Advertise your mobile site for FREE with AdTwirl
GiLL wrote: put this in your confg.php or ini.php
function scharin($word) { $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; for($i=0;$i<strlen($word);$i++) { $ch = substr($word,$i,1); $nol = substr_count($chars,$ch); if($nol==0) { return true; } } return false; }put this line in your register.php and you replace $login to your user name etc
if(scharin($login) == true) $error=$error.'Invalid Characters in Nick!<br/>';and
if(strlen($login)<3) $error=$error.'Nick should be Minimum of 3 words!<br/>';if you need more and strong filter send me pm will tell you 8)
3 letters 🙂
just correcting 🙂
