• 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!

[PHP] Invalid offset/Hide warning

Shadowman321

Member
Joined
Mar 27, 2010
Messages
205
Reaction score
22
Notice: Uninitialized string offset: 3 in /var/www/ajax/check_name.php on line 67 Notice: Uninitialized string offset: -1 in /var/www/ajax/check_name.php on line 73

Lines 66-76:
Code:
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;

Everything works fine, but theres an error. I tried to hide this by adding ^ E_NOTICE in error reporting, but it doesn't work. And i have no idea whats wrong with that.
 
Is this line 73?
PHP:
if($name[$i-1] == ' ' && $name[$i+1] == ' ')

If so try this:
PHP:
if($i >= 1 && $name[$i-1] == ' ' && $name[$i+1] == ' ')

Edit:
Adjusted the title.
 
Is this line 73?
PHP:
if($name[$i-1] == ' ' && $name[$i+1] == ' ')

If so try this:
PHP:
if($i >= 1 && $name[$i-1] == ' ' && $name[$i+1] == ' ')

Edit:
Adjusted the title.
It work. But still error in 67 line.
Notice: Uninitialized string offset: 4 in /var/www/ajax/check_name.php on line 67
if($name[$i] == $name[($i+1)] && $name[$i] == $name[($i+2)])

@up2
php.net manual:
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

But i tried even: "error_reporting(0);" ...
 
Try adding the error reporting into index.php just below <?PHP

PHP:
error_reporting( E_ALL ); 
ini_set( 'display_errors', 1 );

Just put 0 to disable it.
 
Try adding the error reporting into index.php just below <?PHP

PHP:
error_reporting( E_ALL ); 
ini_set( 'display_errors', 1 );

Just put 0 to disable it.

Changed display_errors in php.ini and error is gone.
I really don't wanted to change it and restart apache every time when i want to check errors. But if everyone say its best way, so i will stay with it.
Anyway, thanks for help.
 
Back
Top