Jump to content

Coloring usernames in table based off IP Address?


Lukeidiot

Recommended Posts

Run the following code with NO modifications.  When you are sure that it works correctly, then you start modifying it.  When it quits working, you will know that what you have tried is wrong.

 

 

 
<?php
include("colors.php");
function randomColor($colors) {
$color = array_rand($colors,1);
return (strpos($color,'*') === false) ? substr($colors[$color],1) : randomColor($colors);
}
 
// $sql = mysql_query("SELECT * FROM ph_referers WHERE owner = '$_SESSION[username]' ORDER BY id DESC");
// while($row = mysql_fetch_assoc($sql)){
 
// $ipaddress = $row['ipaddress'];
$ipaddress = array('User1' => '127.0.0.1','User2' => '127.0.0.1','User3' => '44.43.44.44', 'User4' => '54.45.45.45'); 
$usedColors = array();
foreach($ipaddress as $user => $address) {
if(array_key_exists($address,$usedColors)) {
$color = $usedColors[$address];
} else {
$color = randomColor($colors);
$usedColors[$address] = $color;
}
echo  '<font color="#' . $color . '">' . $address . '</font><br />';
}
 
//echo "$new - $row[username]:$color<br>"; 
 
//}
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.