• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

PHP Random sig image

Question

conundrum    0

there was someone on the forum who had a random image script where it would randomly pick one of his images for his sig and show it. i think it was a CGI script but i could be wrong. any help with creating one or finding one would be gladly apreciated

-Conundrum

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0
Keldyn    1

I thought it was a PHP file ?:ermm:

Share this post


Link to post
Share on other sites
  • 0
conundrum    0

well whatever it is i thought it was cgi but i could be wrong

Share this post


Link to post
Share on other sites
  • 0
Keldyn    1

i know prasanth16 is using a php sig at the moment. perhaps you could PM him asking how ? This topic has been covered alot in the past however, doing a search here may yield some info for you ;)

Share this post


Link to post
Share on other sites
  • 0
Prasanth    0

i think keldyn is right

and here u go;)

<?

$URL1="sigs/sig1.jpg";

$URL2="sigs/sig2.jpg";

$URL3="sigs/sig3.jpg";

srand((double) microtime() * 1000000);

$random = rand(1,3);

if($random == 1)

@header ("Location: $URL1");

elseif ($random == 2)

@header ("Location: $URL2");

elseif ($random == 3)

@header ("Location: $URL3");

?>

Share this post


Link to post
Share on other sites
  • 0
Dazzla    5

The majority of people use php files, thats what I used. I warn you though, if you intend on using this, make sure you have a lot of bandwidth because these eat it up for breakfast.

Just for reference, here's the coding I had in my "sig.php":



<?

$URL1="sig/Real.jpg";

$URL2="sig/Lust.jpg";

$URL3="sig/Fate.jpg";

$URL4="sig/Love.jpg";

$URL5="sig/Hate.jpg";

$URL6="sig/Pure.jpg";

$URL7="sig/Hope.jpg";

$URL8="sig/True.jpg";

$URL9="sig/Luck.jpg";



srand((double) microtime() * 1000000);

$random = rand(1,9);



if($random == 1)

@header ("Location: $URL1");

elseif ($random == 2)

@header ("Location: $URL2");

elseif ($random == 3)

@header ("Location: $URL3");

elseif ($random == 4)

@header ("Location: $URL4");

elseif ($random == 5)

@header ("Location: $URL5");

elseif ($random == 6)

@header ("Location: $URL6");

elseif ($random == 7)

@header ("Location: $URL7");

elseif ($random == 8)

@header ("Location: $URL8");

elseif ($random == 9)

@header ("Location: $URL9");

?>[/PHP]

This was for 9 random sigs, the sigs are called "real.jpg", "Lust.jpg" etc. They are placed in a folder called "Sig".

I'm real crap at explaining this so you'd probably be better off searching in the forums, because I know there was a good thread dedicated to this.

Edit: Damn, you beat me to it... :evil:

Share this post


Link to post
Share on other sites
  • 0
conundrum    0

thank you soo much

Share this post


Link to post
Share on other sites
  • 0
Keldyn    1

I decided to make this sticky for a while, seeing as how this question gets asked alot. Cheers prasanth and Dazzla.

Share this post


Link to post
Share on other sites
  • 0
Prasanth    0

Dazzla im a lil fast:P

Share this post


Link to post
Share on other sites
  • 0
Dazzla    5
Originally posted by prasanth16

Dazzla im a lil fast:P

yeah I suppose, but mine's in nice pretty PHP tags and That extra minute was spent trying to explain it (poorly I admit :D ), so :lick:

Disclaimer: for people who lack a sense of humour, this is called sarcasm

Share this post


Link to post
Share on other sites
  • 0
Joseph Zollo    6

Here's a random image script in perl, it chooses a random file from a directory you specify.

&lt;pre&gt;

#!/usr/bin/perl

$IMAGE_DIRECTORY = "INSERT ABSOLUTE PATH TO DIRECTORY";

my $line = "";

my $file1= "";

my $x=0;

opendir (DIR,"$IMAGE_DIRECTORY");

while ($fileName = readdir(DIR)) {

        next if (-d $IMAGE_DIRECTORY . $fileName);

	next if ($fileName !~ /w/);

	$ls[$x] = $fileName;

	$x+=1;

}

closedir(DIR);

srand();

$file1 = int(rand(@ls));

print ("Pragma: no-cachen");

if ($ls[$file1] =~ /.gif$/i) {

	print ("Content-type: image/gifnn");

} elsif ($ls[$file1] =~ /.jpg$|.jpeg$/i) {

	print ("Content-type: image/jpgnn");

} else {

	exit(0);

}

open (INPUT, $IMAGE_DIRECTORY . $ls[$file1]);

while ($line = &lt;INPUT&gt;) {

	print ($line);

}

close(INPUT);

exit(0);

&lt;/pre&gt;

You would call it as if it were a normal image..."random.cgi"

Share this post


Link to post
Share on other sites
  • 0
Mr magoo    1

HOW TO DO IT!


&lt;?

$URL1="addressofsig1";

$URL2="addressofsig2";

$URL3="addressofsig3";

$URL4="addressofsig4";

$URL5="addressofsig5";

$URL6="addressofsig6";

$URL7="addressofsig7";

$URL8="addressofsig8";

$URL9="addressofsig9";



srand((double) microtime() * 1000000);

$random = rand(1,9);



if($random == 1)

    @header ("Location: $URL1");

elseif ($random == 2)

    @header ("Location: $URL2");

elseif ($random == 3)

    @header ("Location: $URL3");

elseif ($random == 4)

    @header ("Location: $URL4");

elseif ($random == 5)

    @header ("Location: $URL5");

elseif ($random == 6)

    @header ("Location: $URL6");

elseif ($random == 7)

    @header ("Location: $URL7");

elseif ($random == 8)

    @header ("Location: $URL8");

elseif ($random == 9)

    @header ("Location: $URL9");

?&gt;



open notepad. copy paste that info above into it. where it says addressofsig1 - thats the address of your first signature file - e.g. http://www.geocities.com/neowinuser/sig1.jpg . that would be what you put in there. The second one would be were ever it is, and os and so on. if 9 is too many then remove one - dont forget to remove one of the

elseif ($random == 9)

@header ("Location: $URL9");

at the bottom.

any quezzies?!

Share this post


Link to post
Share on other sites
  • 0
Prasanth    0

mr mangoo i think when removing a sig from the spin we need to change this too

$random = rand(1,8);

mr magoo= granted - yes.

Share this post


Link to post
Share on other sites
  • 0
Prasanth    0

a lot of ppl are asking for a good php host for their sigs

http://www.tripod.co.uk

i think this one is the best;)

note tripod.com dont have support for php

Share this post


Link to post
Share on other sites
  • 0
digital.death    0

If you're going to do it in php there is an easier way:

<?php 



/* Declare variables. */

$path = "./";

$arr = array ();



/* Open Directory */

if ($dir = @opendir($path)) {

while ($file = readdir($dir))

{

if ((is_file($file)) && (eregi("(.gif|.jpg|.png)",$file))) {

/* Verify that the file is an image. */

$arr[] = $file;

}

}

closedir($dir);

}



/* print a random sig. */

header ('Location: ' . $arr[rand (0, count ($arr)-1)]);



?>[/PHP]

Just change the $path variable to whatever folder you want.

Share this post


Link to post
Share on other sites
  • 0
Deepu Sudhakar    0

Another easy way

&lt;pre&gt;&lt;?php



header("Location: [url]http://www.bla.net/blaavatars/sig[/url]".rand(1,40).".gif");





?&gt;&lt;/pre&gt;

Obviously the location has to lead to your pictures, and ure pictures have to begin with "sig" followed by a number. For example i would have sig1, sig2, and sig3. You can change the random range to whatever number of pics you have, and you can change .gif to .jpg or .png...maybe it is a little bit complicated, but at least the code is shorter :p

Share this post


Link to post
Share on other sites
  • 0
Prash    0

Perl sucks LOL!

Share this post


Link to post
Share on other sites
  • 0
IanD    0

OK, i did everthing...to make the sig..

but do i put a link to the PHP script in my sig? or what do i do?

-sMk

Share this post


Link to post
Share on other sites
  • 0
Weasel    0

The script shown throughout this thread was written by yours truly, please credit the code.

Thanks. :)

Share this post


Link to post
Share on other sites
  • 0
Vinh    0

talking about sigs, time to make some :)

Share this post


Link to post
Share on other sites
  • 0
sssqqq    0

Is there any way to make the script print random text instead? I have a list of about 15 quotes and want them to display randomly instead of proper images. However I'm not sure if a web browser would display it correctly if it was called using an tag?

Share this post


Link to post
Share on other sites
  • 0
Rusty.Metal    1

i think u used coolmon to generat a .xhtml and made the php file read it for ur old... sig a made it a layer on top or something wanna explain it for use reaterded people?

Share this post


Link to post
Share on other sites
  • 0
ctrlaltdel    0

Is it possible to rotate sigs automatically?

If so, how?

Share this post


Link to post
Share on other sites
  • 0
DerkPY    0

Yes, you can make a gif movie which changes the image every couple of seconds.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.