Multiple names

Hi all…here goes.

I’m a complete novice to PHP so I hope i’ve posted this question in the correct catagory.

I run a website along with a few mates. We play online gaming. Anyway on one of our pages we have a PHP script called BF2LIVE.http://www.nsiclan.co.uk/bf2live/demo.php. If you look at the site you’ll see I’ve inserted a line at the bottom to show the word ‘cheat’ which is highlighted in green. I have a list of reported players who cheat on the game we play. I can put a single player in the script so the name changes to green when he’s on our server but i dont know how to get a complete list in the script.

Here’s what i mean:

//Cheats name will show light green.

$cheat = ‘oBy! GretzMan-’;

$cheatcolor = ‘#00FF00’;

if($row[‘name’] == $cheat) $namecolor=$cheatcolor;

These are the lines I’ve added and the player ‘oBy! GretzMan-’ lights up green when playing on our server. Is there a way to add multiple players.

Thanks in advance.

:)

Ok, let’s start with the basics. Right now, you are trying to compare two strings together. Computers are usually stupid. It won’t guess you’re trying to compare the tokens in your string. To do this, you need to use a list of strings instead of the single string. In PHP, a single container is used for everything and is called an array.

So, instead of having a string with all the player names, you need to have an array with all the player names:
[php]
$cheat = array( ‘oBy!’, ‘GretzMan-’ );
[/php]

Now, you can’t compare a player name with an array. Instead, you want to verify if the player name is in the array.

[php]
if( in_array( $row[‘name’], $cheat ) )
$namecolor = $cheatcolor;
[/php]

This should be enough.

Just a little note, I wouldn’t use green as a color. To most people, green is a synonym to good, and I don’t think that’s the feeling they should have about the cheaters ;)

Thankyou for your reply

I entered two of the names and inserted the code you provided but got an error.Parse error: syntax error, unexpected T_VARIABLE
Is there something i’m not doing?

PS i’ve changed the color.

$cheat = array( ‘=AC=dwu’, ‘[EVDI] Taffy1979’ );

if(in_array($row[‘name’], $cheat )) $namecolor = $cheatcolor

Just thought I’d thankyou for your help. I managed to sort it. I put the code in the wrong area. Works a treat.thankyou :D

Sponsor our Newsletter | Privacy Policy | Terms of Service