| Saturday, October 11, 2008, 02:18:27 A.M. | Unix Time Converter | In Dutch @ The Cowboys | In Google Directory |
« Ping ping, ping pong | Main | Alle angsten »
I've been asked questions about the random cookies and the random thumbnails. Also the logo on top of the site randomizes from colour to tiles to black and white. How do we do it?
It's really very simple. You put an executable file (chmod 755) in your cgi-local, or anywhere else your server allows you to execute files.
The name of the file can be something like random.cgi, or random.pl, depending on your httpd.config file (I think :-)
Anyway, your randomizer should look like this:
### beginning of the script ###
#!/usr/bin/perl
$random_file = "random.dat";
open (FILE, $random_file);
@LINES=;
close(FILE);
srand;
print "Content-type: text/html; charset=CP1250\n\n";
print "@LINES[int rand(@LINES)]\n";
### end of the script ###
In the second line you see the name of the file containing whatever you want to parse at random. The script reads lines until hard breaks, so if you want to show breaks in the ouput use the html-tag <br>
The random.dat file could look like:
The wombat lives across the seas,<br>Among the far Antipodes.<br>He may exist on nuts and berries,<br>Or then again, on missionaries;<br>His distant habitat precludes<br>Conclusive knowledge of his moods.<br>But I would not engage the wombat<br>In any form of mortal combat.
Excellent day to have a rotten day.
The faster we go, the rounder we get. <br> [ © The Grateful Dead ]
You get it: this dat file contains three cookies.
To call the script in action you use a server side include. Most servers want the html-file in which you use an include to have the .shtml extension.
Put this tag (depending on your path, some servers demand a full path) where you want your cookie to show up:
<!--#exec cgi="/cgi-local/random.cgi" -->
and random.cgi will parse one cookie at random. You can wrap font and color tags around your include call, or you can hack random.cgi and add two lines of code containing the tags. In this case the last two lines would become the last four lines, something like:
print "Content-type: text/html; charset=CP1250\n\n";
print "<font face=verdana size=2>";
print "@LINES[int rand(@LINES)]\n";
print "</font>";
A randomizer for thumbnails works the same. This script could be named randompics.cgi (or .pl), calling randompics.dat
The randompics.dat can contain as much links as you like to any pictures in any directory.
As I'm using ImageFolio as web fotoalbum, my randompics.dat contains links tot the individual url's on the thumbnailpages, and looks like this:
<a href="/cgi-local/imageFolio.cgi?action=view&link=Australia_2000&image=01.jpg"><img src="/gallery/Australia_2000/tn_01.jpg" alt="Australia 2000/01" border="0"></a><br>
<a href="/cgi-local/imageFolio.cgi?action=view&link=Australia_2000&image=02.jpg"><img src="/gallery/Australia_2000/tn_02.jpg" alt="Australia 2000/02" border="0"></a><br>
And so on ...
Have fun!
Link: all cookies
Posted by Leon at January 30, 2004 11:57 AM
Hey!
Do you have secrets? ;)
pls write me
LaurienGirvenqdv683@live.com
Posted by: gabeaphibra at October 3, 2008 09:44 PM
Where?
tell me pls LaurienGirvenqdv683@live.com
Posted by: tuppiffAffelm at October 3, 2008 08:47 AM
Wonderful and informative web site. I used a lot of information; it's great!
Posted by: WonDerful at June 23, 2007 02:42 AM
Last week someone asked me how to display some links in a random sequence. The links were always the same, but the order they were to be shown in couldn't always be the same. Sure it sounds easy enough, but was it really?
Looking back over our random samples and the other things we've published about randomizing items, I realized that this isn't as easy as it seems. They didn't want anything repeated... so I started thinking about all the pain of storing the id of the items I've already shown so I didn't accidentally show them again. Then I found out that the items were coming to me in the form of an ADO recordset. Not knowing what type of cursor was being used, I didn't really want to recommend that they keep moving back and forth through the recordset since this can cause errors with certain cursor types and if the cache size of the cursor is too small it could also hurt performance noticably (probably scalability more then performance... but whatever!).
The solution... don't randomize the items in question... randomize something else which you can then use to select items in a random sequence. This has the benefit of the fact that you don't need to move the items around. As long as they are addressable in some fixed order, by generating an array of random index positions you can bypass manipulating the items directly and simply request the items in the proper sequence. This should help speed as well as make it fairly simple to implement whatever the items are stored in.
Posted by: Hip Hop Dancer at June 22, 2007 10:06 PM
Very interesting website. Keep up the outstanding work and thank you...
Posted by: Gal Sweet at June 17, 2007 03:24 AM