• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Jak zablokować tworzenie postaci z apostrofem?

Status
Not open for further replies.

GarQet

Own3d!
Joined
Feb 10, 2009
Messages
1,381
Solutions
14
Reaction score
81
Siemaneczko, mam mały problem...
Próbowałem zablokować możliwość tworzenia nazw, nicków z apostrofami, tz.:
Wyedytowałem trochę check_name.php, oto i on:
PHP:
<?PHP
echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?>';
$config_ini = parse_ini_file('../config/config.ini');
include('../config/config.php');
$name = strtolower(stripslashes(trim($_REQUEST['name'])));
if(empty($name))
{
	echo '<font color="red">Please enter new character name.</font>';
	exit;
}

//first word can't be:
$first_words_blocked = array('gm ','cm ', 'god ','tutor ', "'", '-');
//names blocked:
$names_blocked = array('gm','cm', 'god', 'tutor');
//name can't contain:
$words_blocked = array('gamemaster', 'game master', 'game-master', "game'master", '  ', '--', "''","' ", " '", '- ', ' -', "-'", "'-", 'fuck', 'sux', 'suck', 'noob', 'tutor');
$temp = strspn("$name", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ");
if($temp != strlen($name))
{
	echo '<font color="red">Name contains illegal letters. Use only: <b>qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM </b></font>';
	exit;
}
if(strlen($name) > 25)
{
	echo '<font color="red">Too long name. Max. lenght <b>25</b> letters.</font>';
	exit;
}

$lol   = "'";
if(strpos($name, $lol) !== false)
{
	echo '<font color="red">Name contains illegal letters. Use only: <b>qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM </b></font>';
	exit;
}

foreach($names_blocked as $word)
	if($word == $name)
	{
		echo '<font color="red">Blocked names:<b> '.$names_blocked[0];
		if(count($names_blocked) > 1)
			foreach($names_blocked as $word)
				if($word != $names_blocked[0])
					echo ','.$word;
		echo '</b></font>';
		exit;
	}
foreach($config['site']['monsters'] as $word)
	if($word == $name)
	{
		echo '<font color="red"><b>You can not use monster name.</b></font>';
		exit;
	}
foreach($config['site']['npc'] as $word)
	if($word == $name)
	{
		echo '<font color="red"><b>You can not use NPC name.</b></font>';
		exit;
	}	
foreach($first_words_blocked as $word)
	if($word == substr($name, 0, strlen($word)))
	{
		echo '<font color="red">First letters in name can\'t be:<b> '.$first_words_blocked[0];
		if(count($first_words_blocked) > 1)
			foreach($first_words_blocked as $word)
				if($word != $first_words_blocked[0])
					echo ','.$word;
		echo '</b></font>';
		exit;
	}
if(substr($name, -1) == "'" || substr($name, -1) == "-")
{
	echo '<font color="red">Last letter can\'t be <b>\'</b> and <b>-</b></font>';
	exit;
}
foreach($words_blocked as $word)
	if (!(strpos($name, $word) === false))
	{
		echo '<font color="red">Name can\'t cointain words:<b> '.$words_blocked[0];
		if(count($words_blocked) > 1)
			foreach($words_blocked as $word)
				if($word != $words_blocked[0])
					echo ','.$word;
		echo '</b></font>';
		exit;
	}
for($i = 0; $i < strlen($name); $i++)
	if($name[$i] == $name[($i+1)] && $name[$i] == $name[($i+2)])
	{
		echo '<font color="red">Name can\'t contain 3 same letters one by one.</font><br /><font color="green"><u>Good:</u> M<b>oo</b>nster</font><font color="red"><br />Wrong: M<b>ooo</b>nster</font>';
		exit;
	}
for($i = 0; $i < strlen($name); $i++)
	if($name[$i-1] == ' ' && $name[$i+1] == ' ')
	{
		echo '<font color="red">Use normal name format.</font><br /><font color="green"><u>Good:</u> <b>Gesior</b></font><font color="red"><br />Wrong: <b>G e s ior</b></font>';
		exit;
	}
if(substr($name, 1, 1) == ' ')
{
	echo '<font color="red">Use normal name format.</font><br /><font color="green"><u>Good:</u> <b>Gesior</b></font><font color="red"><br />Wrong: <b>G esior</b></font>';
	exit;
}
if(substr($name, -2, 1) == " ")
{
	echo '<font color="red">Use normal name format.</font><br /><font color="green"><u>Good:</u> <b>Gesior</b></font><font color="red"><br />Wrong: <b>Gesio r</b></font>';
	exit;
}
else
		//connect to DB
		$server_config = parse_ini_file($config_ini['server_path'].'config.lua');
		if(isset($server_config['mysqlHost']))
		{
			//new (0.2.6+) ots config.lua file
			$mysqlhost = $server_config['mysqlHost'];
			$mysqluser = $server_config['mysqlUser'];
			$mysqlpass = $server_config['mysqlPass'];
			$mysqldatabase = $server_config['mysqlDatabase'];
			$sqlitefile = $server_config['sqliteDatabase'];
		}
		elseif(isset($server_config['sqlHost']))
		{
			//old (0.2.4) ots config.lua file
			$mysqlhost = $server_config['sqlHost'];
			$mysqluser = $server_config['sqlUser'];
			$mysqlpass = $server_config['sqlPass'];
			$mysqldatabase = $server_config['sqlDatabase'];
			$sqlitefile = $server_config['sqliteDatabase'];
		}
		// loads #####POT mainfile#####
		include('../pot/OTS.php');
		// PDO and POT connects to database
		$ots = POT::getInstance();
		if($server_config['sqlType'] == "mysql")
			$ots->connect(POT::DB_MYSQL, array('host' => $mysqlhost, 'user' => $mysqluser, 'password' => $mysqlpass, 'database' => $mysqldatabase) );
		elseif($server_config['sqlType'] == "sqlite")
			$ots->connect(POT::DB_SQLITE, array('database' => $config_ini['server_path'].$sqlitefile));
		$name_db = new OTS_Player();
		$name_db->find($name);
		if($name_db->isLoaded())
			echo '<font color="red"><b>Player with this name already exist.</b></font>';
		else
			echo '<font color="green">Good. Your name will be:<br />"<b>'.ucwords($name).'</b>"</font>';

?>
Nie wiem czemu ale o dziwo dalej można tworzyć postacie z apostr., a wydawało mi się, że już to zablokowałem :blink:.
Proszę o jakąś wskazówkę, lub fixa, aby nie dało się tworzyć postaci z apostrofami.
 
Po 1. przeczytaj co robi ta funkcja: PHP: stripslashes - Manual
..a następnie użyj tej: PHP: strpos - Manual

Jakbyś się przyjrzał temu kodu co go wstawiłem to byś zauważył, że użyłem funkcji STRPOS...
PHP:
$lol   = "'";
if(strpos($name, $lol) !== false)
{
    echo '<font color="red">Name contains illegal letters. Use only: <b>qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM </b></font>';
    exit;
}

Jakieś pomysły?
 
PHP:
if(substr_count($name, "'") > 0)
{
     echo 'BLABLA';
     exit;
}
 
PHP:
if (!preg_match("/^[a-zA-Z ]+$/D", $name)) {
 die("trolloloooo");
}
-.- ewentualnie dodaj sobie jeszcze myślniki do wyrażenia
 
PHP:
if (!preg_match("/^[a-zA-Z ]+$/D", $name)) {
 die("trolloloooo");
}
-.- ewentualnie dodaj sobie jeszcze myślniki do wyrażenia

To też nie działa...
Może wgl. mi nie działa check_name.php?
Sprawdzałem ścieżki w accountmanagment.php ale wszystko (na moje oko) się zgadza.
Cały czas googluje ale zerowy efekt :blink:.
 
zarty sobie robisz -.- moze w config-and-functions.php byś zedytował też te funkcje -.-
 
PHP:
	$s = isset($_POST['name']) ? trim($_POST['name']) : '';

	if(empty($s))
		$e['name'] = 'Please enter a name for your character!';
	elseif(strlen($s) < 2 || strlen($s) > 29)
		$e['name'] = 'A name must have at least 2 but no more than 29 letters!';
	elseif(preg_match('/[^a-zA-Z ]/', $s))
		$e['name'] = 'This name contains invalid letters. Please use only A-Z, a-z and space!';
	elseif(!ctype_upper($s[0]))
		$e['name'] = 'The first letter of a name has to be a capital letter!';
	elseif(strpos($s, '  ') !== false)
		$e['name'] = 'This name contains more than one space between words. Please use only one space between words!';
	else {
		foreach(explode(' ', $s) as $k =>$v) {
			$words[$k] = str_split($v);
			$len = strlen($v);
			if($len == 1) {
				$e['name'] = 'This name contains a word with only one letter. Please use more than one letter for each word!';
				break;
			}
			elseif($len > 14) {
				$e['name'] = 'This name contains a word that is too long. Please use no more than 14 letters for each word!';
				break;
			}
		}
		if(!isset($e['name'])) {
			$total=0;
			foreach($words as $k =>$p) {
				if(isset($e['name']))
					break;
				$total++;
				if($total > 3) {
					$e['name'] = 'This name contains more than 3 words. Please choose another name!';
					break;
				}
				$len=0;
				foreach($p as $i =>$j) {
					$len++;
					if($i != 0 && ctype_upper($j)) {
						$e['name'] = 'In names capital letters are only allowed at the beginning of a word!';
						break;
					}
					elseif($i == $len-1) {
						$ff=null;
						for($h=0;$h<strlen($v); $h++) {
							if(in_array(strtolower($v[$h]), array('a','e','i','o','u')) !== false) {
								$ff=true;
								break;
							}
						}
						if(!$ff) {
							$e['name'] = 'This name contains a word without vowels. Please choose another name!';
							break;
						}
					}
				}
			}
			if(!isset($e['name'])) {
				$s = strtolower($s);
				for($i = 0; $i < strlen($s); $i++)
					if($s[$i] == $s[($i+1)] && $s[$i] == $s[($i+2)]) {
						$e['name'] = 'This character name is already used. Please select another one!';
						break;
					}
				if(!isset($e['name'])) {
					foreach(array('aa ', 'ee', 'ii', 'oo', 'uu', 'gm','cm', 'aff ', 'god ', 'abc', 'tutor', 'game', 'admin', 'the ') as $v)
						if($v == substr($s, 0, strlen($v))) {
							$e['name'] = 'This character name is already used. Please select another one!';
							break;
						}
					if(!isset($e['name'])) {
						foreach(array('game', 'customer', 'support', 'fuck', 'haha', 'sux', ' abc', 'suck', 'noob', 'tutor', 'admin', 'account', 'gay', 'password', 'manager') as $v)
							if(strpos($s, $v) !== false) {
								$e['name'] = 'This character name is already used. Please select another one!';
								break;
							}
						if(!isset($e['name'])) {
							if(!isset($con)) {
								$con = mysql_pconnect($config['server']['sqlHost'], $config['server']['sqlUser'], $config['server']['sqlPass']) or die('MySQL connection error.');
								mysql_select_db($config['server']['sqlDatabase']);
							}
							if(mysql_num_rows(mysql_query('SELECT id FROM players WHERE name=\''.mysql_escape_string($s).'\' LIMIT 1')) != 0)
								$e['name'] = 'This character name is already used. Please select another one!';
						}
					}
				}
			}
		}
	}
jellyjelly^_^:p?
 
PHP:
	$s = isset($_POST['name']) ? trim($_POST['name']) : '';

	if(empty($s))
		$e['name'] = 'Please enter a name for your character!';
	elseif(strlen($s) < 2 || strlen($s) > 29)
		$e['name'] = 'A name must have at least 2 but no more than 29 letters!';
	elseif(preg_match('/[^a-zA-Z ]/', $s))
		$e['name'] = 'This name contains invalid letters. Please use only A-Z, a-z and space!';
	elseif(!ctype_upper($s[0]))
		$e['name'] = 'The first letter of a name has to be a capital letter!';
	elseif(strpos($s, '  ') !== false)
		$e['name'] = 'This name contains more than one space between words. Please use only one space between words!';
	else {
		foreach(explode(' ', $s) as $k =>$v) {
			$words[$k] = str_split($v);
			$len = strlen($v);
			if($len == 1) {
				$e['name'] = 'This name contains a word with only one letter. Please use more than one letter for each word!';
				break;
			}
			elseif($len > 14) {
				$e['name'] = 'This name contains a word that is too long. Please use no more than 14 letters for each word!';
				break;
			}
		}
		if(!isset($e['name'])) {
			$total=0;
			foreach($words as $k =>$p) {
				if(isset($e['name']))
					break;
				$total++;
				if($total > 3) {
					$e['name'] = 'This name contains more than 3 words. Please choose another name!';
					break;
				}
				$len=0;
				foreach($p as $i =>$j) {
					$len++;
					if($i != 0 && ctype_upper($j)) {
						$e['name'] = 'In names capital letters are only allowed at the beginning of a word!';
						break;
					}
					elseif($i == $len-1) {
						$ff=null;
						for($h=0;$h<strlen($v); $h++) {
							if(in_array(strtolower($v[$h]), array('a','e','i','o','u')) !== false) {
								$ff=true;
								break;
							}
						}
						if(!$ff) {
							$e['name'] = 'This name contains a word without vowels. Please choose another name!';
							break;
						}
					}
				}
			}
			if(!isset($e['name'])) {
				$s = strtolower($s);
				for($i = 0; $i < strlen($s); $i++)
					if($s[$i] == $s[($i+1)] && $s[$i] == $s[($i+2)]) {
						$e['name'] = 'This character name is already used. Please select another one!';
						break;
					}
				if(!isset($e['name'])) {
					foreach(array('aa ', 'ee', 'ii', 'oo', 'uu', 'gm','cm', 'aff ', 'god ', 'abc', 'tutor', 'game', 'admin', 'the ') as $v)
						if($v == substr($s, 0, strlen($v))) {
							$e['name'] = 'This character name is already used. Please select another one!';
							break;
						}
					if(!isset($e['name'])) {
						foreach(array('game', 'customer', 'support', 'fuck', 'haha', 'sux', ' abc', 'suck', 'noob', 'tutor', 'admin', 'account', 'gay', 'password', 'manager') as $v)
							if(strpos($s, $v) !== false) {
								$e['name'] = 'This character name is already used. Please select another one!';
								break;
							}
						if(!isset($e['name'])) {
							if(!isset($con)) {
								$con = mysql_pconnect($config['server']['sqlHost'], $config['server']['sqlUser'], $config['server']['sqlPass']) or die('MySQL connection error.');
								mysql_select_db($config['server']['sqlDatabase']);
							}
							if(mysql_num_rows(mysql_query('SELECT id FROM players WHERE name=\''.mysql_escape_string($s).'\' LIMIT 1')) != 0)
								$e['name'] = 'This character name is already used. Please select another one!';
						}
					}
				}
			}
		}
	}
jellyjelly^_^:p?

ok thx baby!
 
Status
Not open for further replies.
Back
Top