Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 570 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Avatar Rotator

#1
PHP Avatar Rotator


Ive you havent noticed, my avatar rotates on each page.
Heres a bunch of code that you can use to get the same effect.

Before I start theres a few things I need to point out.
  • I didnt create the code (

    [To see links please register here]

    )

  • You will need a web server
  • This rotator is used by MyBB's MattR :smile:

Ok so heres how to do it.


- - - - - - - - - - - - - - - - - - -

- First things first you need to create a new textdocument.

- Once opened paste the following code into it.

PHP Code:
<?php
/*******************************************************************************
*    PHP AVATAR ROTATOR
*       VERSION 2
*******************************************************************************/

$path "/avatars/";    // Path to your avatar folder relative to the root directory of your site

/******************************************************************************
*       DO NOT EDIT BELOW THIS LINE!
******************************************************************************/

$dir $_SERVER['DOCUMENT_ROOT'].$path;
$avatars = array();

// Open avatar directory and read its contents into an array
if (is_dir($dir)) {
    if (
$dh opendir($dir)) {
        while ((
$file readdir($dh)) !== false) {
            if (
filetype($dir.$file) == "file" && getimagesize($dir.$file)) {
                
array_push($avatars$file);
            }
        }
        
closedir($dh);
    }
}

// Create random avatar
$img $dir.$avatars[rand(0count($avatars)-1)];
$info getimagesize($img);

if (
$info[2] == 2)
    
header('Content-Type: image/jpeg');

elseif (
$info[2] == 3)
    
header('Content-Type: image/png');

else
    
header('Content-Type: image/gif');

readfile($img);
?>
Nothing needs changing in it and it should be ready to go.

- Just save it as avatar.php, making sure after you have saved it that it is an actual PHP file and not avatar.php.txt :smile:

- After you have create the php file, create a new folder called avatars

- In this folder you will have all the avatars you want to rotate.
You really want to have all image dimensions exactly 100px x 100px. Alot of sites dont allow any bigger than that and some resize them but some do not. And if they do and your image isnt 1:1 then the image will be squashed to 100px x 100px. So its in your interests to resize it :smile:


- After that upload everything we have just created to the ROOT of your webserver.

- After everything is uploaded then you want to check it by typing in this link. Obviously changinging "yoursite.com" to your web url.

[To see links please register here]



- Hit refresh a few times and the avatar should change each time.

- Now all you have to do is go to your UserCP, along the left handside click change avatar. Then where it give you the option to upload the avatar by url, paste that url in :smile:

- Hit save and thats it.

Good luck :smile:
Reply

#2
Here is some slightly more efficient code I wrote real quick.

PHP Code:
<?php
$imgdir 
"images";

$images scandir($img_path);
$imgpath $imgdir DIRECTORY_SEPARATOR $images[mt_rand(2,count($images))];

header("Content-type: " image_type_to_mime_type(exif_imagetype($image)));
readfile($imagepath);
?>

It eliminates unnecessary loops and tests, uses a more efficient rand function, as well as supports many more image types. You can break this by having something other than an image file in your directory. If the user's browser doesn't support the image it will simply not display.

A more documented copy of the previous code follows:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through