Random Signature

A place to discuss anything that doesn't fit in to another forum category
User avatar
EmberCelica
Engineer
Engineer
CPU: i7 6700k
RAM: 16GB DDR4
Motherboard: [Unknown]
GPU: AMD RX480
Cooling: Fan Cooling
Location: Always behind you
Posts: 188
Joined: Sat Feb 28, 2015 11:20 pm

Random Signature

Sat Jul 25, 2015 1:44 pm

So for a while now i have been thinking about how to go about making a signature that changes like pri's but customizable in the sense of choosing the images and etc. After searching around on the web i managed to do it and thought that i would share it.

So first thing first is to find your pictures, you can have any number but make sure they are all the same file type.(It wont work otherwise. you can always safely change the file extention of a static image such as jpg or png)

Afterwards write this code into notepad:

Code: Select all

<?php 
header("Content-type: image/jpeg"); 

$display = rand(1, 8); 

if ($display == 1) { readfile("1.jpeg"); } 
if ($display == 2) { readfile("2.jpeg"); } 
if ($display == 3) { readfile("3.jpeg"); } 
if ($display == 4) { readfile("4.jpeg"); } 
if ($display == 5) { readfile("5.jpeg"); } 
if ($display == 6) { readfile("6.jpeg"); } 
if ($display == 7) { readfile("7.jpeg"); } 
if ($display == 8) { readfile("8.jpeg"); } 
?>
Now make sure that you have the same number of lines as you do images, you can just copy-paste some of it over to make more lines. Secondly change the 8 in "$display = rand(1, 8); " to be whatever the number of images you have are. Lastly make sure that the jpeg in "header("Content-type: image/jpeg"); " is your picture's file type, and make sure to add the extentions in the file names. Replace the "#.jpeg" with your file name. Make sure to save this as a php file, you can name it anything

Next get a FTP server running. It could be free, hosted, paid, or etc but make sure you have one. I used https://www.olympe.in since it was one of the first ones i found. (If you use the olympe.in site, it sends you a conformation email which you need to click before you register and actual name and password. Following make sure to create a Site in the Site tab. Remember the username and password that you use for the site, its important.)

After you get it running download a FTP client, i use Filezilla, but use whatever you prefer and login to the FTP server. (If you used olympe.in then use the following: Host: ftp.olympe.in User: 'your websites name' Password: 'Site password' Port: 21) After logging into the FTP server make a folder (you can name it anything) in the root of your FTP server. Then inside the folder place all of your images and the php file, then let them completely transfer(this could take some time depending on your network or FTP server)

Following this come onto the forums and go to your User Control Panel and click edit signature. In there place this inside image tags.(substituting your own information):
http://(server name).olympe.in/(folder created in root)/(Script name).php
(this is case sensitive!!!!) and example might be:
If i place it in image brackets then:
Image

Admittedly this was going to be my avatar one however the problem lies therein that the avatar system doesnt support it.
But my signature worked (obviously) and is below. These will change on page reload.

Anyhow, i hope this helps!
Sincerely,
Ember

==
Edit:
1) Olympe seems to be down
2) My Signature currently is not randomized either
Last edited by EmberCelica on Tue Jul 19, 2016 5:19 am, edited 1 time in total.
Image
Image Im the engineer of engineers.
Check out my redstone info thread
User avatar
Pri
Site Admin
Site Admin
Posts: 5433
Joined: Fri Dec 14, 2007 8:59 am

Re: Random Signature

Sat Jul 25, 2015 3:17 pm

Nice guide ember :)
User avatar
EmberCelica
Engineer
Engineer
CPU: i7 6700k
RAM: 16GB DDR4
Motherboard: [Unknown]
GPU: AMD RX480
Cooling: Fan Cooling
Location: Always behind you
Posts: 188
Joined: Sat Feb 28, 2015 11:20 pm

Re: Random Signature

Sat Jul 25, 2015 4:54 pm

Thank you pri :) took me a little bit, but it works well and its more-or-less dynamic in a way. Anywho, I just thought that i would give this guide for those that wanted it as much as i did but couldnt find anything, or didnt know how.
Image
Image Im the engineer of engineers.
Check out my redstone info thread
User avatar
Pri
Site Admin
Site Admin
Posts: 5433
Joined: Fri Dec 14, 2007 8:59 am

Re: Random Signature

Sat Jul 25, 2015 6:14 pm

This is the code that drives my signature, this one differs in that you don't need to edit it each time you add a new image, you just put more in the folder and it reads the folder contents to create its list of files. It also has cache control to stop browsers caching the image, this is good when you want to change the file extension from .php to .png to support web services that won't allow a .php extension.

I've added comments so you can see what each thing is doing.

Code: Select all

<?php
Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
Header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
Header("Pragma: no-cache");
Header("Content-Type: image/png");
// Content header with mime type (image/png) and disable image cache in the browser

$dir = "sigs" ; // Folder name where the signatures are stored

srand((double)microtime()*1000000); // Random number seed
$i = 0; // Incrementor to 0 for a clean run
$dirHandle = opendir($dir); // Open the folder with the signatures
while(($im = readdir($dirHandle))) // Load in the image names
{
if($im != ".." && $im != ".") // Ignore the two hidden directories in the folder (.. and .)
{
$image[$i] = $im; // Add the image name chosen by the counter to array
$i++; // Incerement the image counter
}
}
closedir($dirHandle); // Close the directory we were reading images from
$n = rand(0,(count($image)-1)); // Generate a number between 0 and array max

readfile($dir."/".$image[$n]) // Read in the signature image chosen and output it.
?> 
If you rename this to .png in your webserver you need to also add a .htaccess file (if hosting with Apache) to the same folder with the following text:

Code: Select all

AddType application/x-httpd-php .php .png
That will allow the webserver to interpret the .pngs within that folder as .php and execute them as such.
User avatar
EmberCelica
Engineer
Engineer
CPU: i7 6700k
RAM: 16GB DDR4
Motherboard: [Unknown]
GPU: AMD RX480
Cooling: Fan Cooling
Location: Always behind you
Posts: 188
Joined: Sat Feb 28, 2015 11:20 pm

Re: Random Signature

Sat Jul 25, 2015 11:18 pm

So this would also allow for a random avatar, would it not?
Image
Image Im the engineer of engineers.
Check out my redstone info thread
User avatar
Pri
Site Admin
Site Admin
Posts: 5433
Joined: Fri Dec 14, 2007 8:59 am

Re: Random Signature

Sun Jul 26, 2015 10:01 am

It would indeed. And if you use sessions you can get the avatar and signature to match up at the same time for the person viewing them.
User avatar
EmberCelica
Engineer
Engineer
CPU: i7 6700k
RAM: 16GB DDR4
Motherboard: [Unknown]
GPU: AMD RX480
Cooling: Fan Cooling
Location: Always behind you
Posts: 188
Joined: Sat Feb 28, 2015 11:20 pm

Re: Random Signature

Sun Jul 26, 2015 6:42 pm

Wow that is cool. I have a question tho, i was trying to make that code work earlier but it wouldnt show the pictures. I have a feeling its a directory problem.
So lets say that the path for the PHP file is
ROOT/Profile
Would i have to create a new sub-directory to the php folder for the pictures. Ex:
ROOT/Profile/Pictures
Also how complicated are sessions, I know i am a skiddie but still i was just wondering since that would be pretty cool. Also it might help me learn a bit more of coding lol.
Image
Image Im the engineer of engineers.
Check out my redstone info thread
User avatar
Pri
Site Admin
Site Admin
Posts: 5433
Joined: Fri Dec 14, 2007 8:59 am

Re: Random Signature

Sun Jul 26, 2015 8:00 pm

Yes, in my code example it goes like this

ROOT/signature.php
ROOT/sigs/Picture1.png

The signature.php will then look in the folder called sigs for all the image files.

Sessions are easy to create and use but I speak from experience. Essentially at the top of your code (the very top but after <?PHP ) you'd have a line such as: session_start();

That will begin the session, then you store a token in the session. In webbrowsers the session is treated like a cookie with a temporary time out, the difference is the server (your server) also keeps a file with the same session data as the client. Using this you can keep a short temporary record of the user and all their interactions with your site.

So once you've setup the session you'd send them something like so: $_SESSION["picture"] = "<PICTUREURL>"; that will set the picture into the session. Now to match them up what you'd do is load in that same session to check if a picture is already present for this users session like so:

Code: Select all

if(@$_SESSION['picture'] == "") { 
 // No image found, pick one at random and send them it, also send the url in a session using:
 $_SESSION["picture"] = "<PICTUREURL>";
} else { 
 // Image found in the session info, load in the image specified and output it
}
By using == "" I'm checking that their session token called picture isn't blank. You'd use this code on both your avatar.php and signature.php and have them both check the same session name (picture) to match up the signature and avatar. And of course you'd have it set so if the picture is blank, it sends them the random url it pics so when the avatar loads or the signature loads (whichever comes second) it matches. You'd then store your avatars and signatures using the same filenames in different folders, one called avatars and one called signatures or sigs.

It's kind of complicated here is a guide about sessions that you can learn with using normal text before doing the image tests: http://www.w3schools.com/php/php_sessions.asp
User avatar
EmberCelica
Engineer
Engineer
CPU: i7 6700k
RAM: 16GB DDR4
Motherboard: [Unknown]
GPU: AMD RX480
Cooling: Fan Cooling
Location: Always behind you
Posts: 188
Joined: Sat Feb 28, 2015 11:20 pm

Re: Random Signature

Mon Jul 27, 2015 6:51 am

Aaah i see and understand somewhat now. Thank you so much with the help and the better code!
Image
Image Im the engineer of engineers.
Check out my redstone info thread
User avatar
freakboy31
Supporter
Supporter
CPU: i7-7700HQ
RAM: 16GB
Motherboard: -
GPU: GTX 1050Ti 4GB
Display: -
Cooling: -
Location: Pacific Ring of Fire
Posts: 2095
Joined: Thu Oct 27, 2011 2:58 pm

Re: Random Signature

Tue Jul 28, 2015 4:30 pm

Thanks Ember for good guide. I try to make one for my avatar if i have time
I'm SUPPORTER and was the first Asian and youngest staff member at age 13.
Image
freakboy31
Epic Crafter since Nov 2013 / Server moderator from Jun. 2012 - Oct. 2017

Populus Magnus nation

Return to “General Chat”

Who is online

Users browsing this forum: No registered users and 12 guests