Shoutbox

rotation of avatars - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: rotation of avatars (/showthread.php?tid=78051)

rotation of avatars by Jarrod on 10-08-2007 at 03:14 AM

i've seen ppls avatars they change every so often and some ppl even had a setup so you could change it,
this is done using php am i right?
can some one show/help me do it, i am willing to try and do want to learn,
but last time i tried to learn php i sorta sucked


RE: rotation of avatars by Spunky on 10-08-2007 at 03:32 AM

This is one I knocked up myself...

code:
  $path = "http://mywebsite.com/";
  if($_GET['picture']=="avatar"){
     $av[17] = "avatar17.gif";
     $av[16] = "avatar16.png";
     $av[15] = "avatar15.png";
     $av[14] = "avatar14.png";
     $av[13] = "avatar13.png";
     $av[12] = "avatar12.png";
     $av[11] = "avatar11.png";
     $av[10] = "avatar10.png";
     $av[9] = "avatar9.png";
     $av[8] = "avatar8.png";
     $av[7] = "avatar7.png";
     $av[6] = "avatar6.png";
     $av[5] = "avatar5.png";
     $av[4] = "avatar4.png";
     $av[3] = "avatar3.png";
     $av[2] = "avatar2.png";
     $av[1] = "avatar1.png";
     $av[0] = "avatar0.jpg";
     header("Location: ".$path.$av[rand(0,count($av))]);
  }else if($_GET['picture']=="signature"){
     $sig[0] = "signature0.png";

     header("Location: ".$path.$sig[rand(0,count($sig))]);
  }


RE: rotation of avatars by WDZ on 10-08-2007 at 04:19 AM

quote:
Originally posted by SpunkyLoveMuff
This is one I knocked up myself...
Bug: count($av) will return 18, but $av[18] doesn't exist. :p

You could simplify things by eliminating the hard-coded array keys and using the array_rand() function...

code:
$path = "http://mywebsite.com/";

$av = array(
    "avatar1.gif",
    "avatar2.jpg",
);

header("Location: " . $path . $av[array_rand($av)]);

RE: rotation of avatars by Jarrod on 10-08-2007 at 04:30 AM

and on the forum in the avatar text box goes the path of the php file?


RE: rotation of avatars by markee on 10-08-2007 at 04:37 AM

quote:
Originally posted by xen0h
and on the forum in the avatar text box goes the path of the php file?
Yes, that's exactly it.

Also instead of hard-coding the array you could just number the pictures and put them all into the one folder and randomly select out of them....
RE: rotation of avatars by Jarrod on 10-08-2007 at 04:43 AM

if the avatar is on for example photobucket do i put the path like this

code:
$av = array(
    "http://photobucket.com/someid/avatar1.gif",
    "avatar2.gif",
    "avatar3.gif",
    "avatar4.gif",
    "avatar5.gif",
    "avatar6.gif",


or do i change this line?
code:
$path = "http://photobucket.com/myuserid/pics";


thanx for years ago was when i learnt html and 2 years after that i tried a bit of javascript then i tried php and my brain exploded

RE: rotation of avatars by prashker on 10-08-2007 at 05:51 AM

quote:
Originally posted by traxor
Why don't you just use this script:

code:
<?php
$dir = "imgs";
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
srand( (double) microtime()*1000000 );
$key = array_rand($files);
readfile($dir . "/" . $files[$key]);
?>

Make a folder called "avatar" on your server, for example http://skarz.co.uk/avatar/ then in that folder put that code in a .php file (this is where you will link the image to, ie. http://skarz.co.uk/avatar/random.php will go in the avatar url box in the user cp). The images that you want shown should go in the "imgs" folder: http://skarz.co.uk/avatar/imgs.

I doubt it would be that hard to just make seperate folders for different people. You can't be hosting that many people :p.