Filltering

Started on the old forum in January 2010 · view the original in the archive · old links redirect here

23 replies · 1,091 views · started 16 years ago · 1 min read

5 participants
ripkk2tfk Developer · 224 posts #5

Ok here is what I got

$text = preg_replace('/[^[:alnum:]\-\.\_\^]/', '', $username);
if($text == true)
		{
		die ("Unsupported character(s)");
				} 
ripkk2tfk Developer · 224 posts #7

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

GiLL Senior · 356 posts #12

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

GumSlone Administrator Principal · 1,690 posts #13

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

External image (may be gone)

GiLL Senior · 356 posts #16

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

GumSlone Administrator Principal · 1,690 posts #18

ok, so you want to prevent mysql injection or filter special chars?

  1. if you want to filter special chars use the first code ive posted,
  2. if you want to prevent mysql injection use mysql_real_escape_string
  3. if you want to filter chars and prevent mysql injection use both.
  4. 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

External image (may be gone)

kei_ki7 Senior · 431 posts #20

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 🙂

Did I help you? You can help me too Your donations will help me finance my studies.

Sign in to reply.

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