Jump to content

Coloring usernames in table based off IP Address?


Go to solution Solved by jcbones,

Recommended Posts

  • Solution

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>"; 
 
//}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.