The Spam Club

» The Spam Club - Life, The Universe and Everything - Vox Pops - perl/cgi Q
ReplyNew TopicNew Poll
» Multiple Pages: 123

perl/cgi Q

Posted at 14:02 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
There are many scripts to change an image randomly, by date, or by a specified time period, but all of them require that you list all the images in the script. Does anyone know of a script that can take a single url and change variables in it? Specifically, the date. I want the script to take a url such as site.com/image15-10-02.gif and change it to match the current date without having to list image14-10-02.gif, image15-10-02.gif, image16-10-02.gi etc.
I can't use javascript for it because I want to use it on some msg boards, and javascript won't work.

Edited by Cypherswipe at 22:05 on October, 15th 2002
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
Posted at 14:06 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
That's easy: just make the script get the date, then glue this date together with the strings "image" and ".gif" and print out this new string in an image tag :)
-----
Now you see the violence inherent in the system!
Posted at 14:23 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 1007
Hey! By now I know how to do that in php :)
-----
NetDanzr<br />
-The quick brown fox jumps over the lazy dog-
Posted at 14:24 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
And it's the same in Perl, only the syntax is slightly different ;)
-----
Now you see the violence inherent in the system!
Posted at 14:33 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
Ok, so give me the syntax.
I'm not familiar with perl, php, javascript, or any other scripting language for that matter. :-\
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
Posted at 14:34 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
Which language should it be in?
-----
Now you see the violence inherent in the system!
Posted at 14:45 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
Perl/cgi whichever's easier, netfirms supports both.
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
Posted at 14:59 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
CGI is not a language, but an interface on servers to run scripts. CGI scripts can be written in many languages like for example Perl, C, Python and many more. So the choice is not really between CGI and Perl ;) Since I don't know what you're trying to to exactly, I'll give you some fragments:

First of all, you need to start your script with the following lines:
#!/usr/bin/perl
use CGI qw(:standard);
The first one specifies the path to Perl (ask your host), the second one loads several standard modules.

Then, to get the date, use the following:
($day) = (localtime(time))[3];
($month) = (localtime(time))[4];
($year) = (localtime(time))[5];
$bla = join('-', $day,$month,$year);
The variable $bla then contains the date in day-month-year format.

After that, you just add the file extension and print it out (if you want, in an image tag):
$bla .= ".gif";
print "<img src="http://www.site.com/$bla">";

Edited by Mr Creosote at 23:01 on October, 15th 2002
-----
Now you see the violence inherent in the system!
Posted at 15:06 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 1007
Ignore this post; the code got all messed up when displayed...

Edited by NetDanzr at 23:08 on October, 15th 2002
-----
NetDanzr<br />
-The quick brown fox jumps over the lazy dog-
Posted at 15:09 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
Alright, what I'm trying to do is have a perl script that I can use as if it were an image url (ie I want to be able to put <img src="site.com/script.cgi"> on a page, the same way most random image scripts work), and instead of having to have a list of all the images I want to be able to put a single url that will include variables for date and month into the script. Then when the site calls the script, the script will send the modified url.
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
Posted at 15:12 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
I've never seen a script being called in an image link (other than from little wannabe-hackers in certain forums). Every serious Perl/CGI script is called with either SSI include or exec command.
-----
Now you see the violence inherent in the system!
Posted at 15:20 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
I've done it with some random image scripts (both perl and php). In fact, other than my forum, that's the only way I've ever used scripts.
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
Posted at 15:22 on October 15th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
Well, it would presumably work the same way I said before, just without the image tag in the script.
-----
Now you see the violence inherent in the system!
Posted at 14:28 on October 16th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
Damn, not working. :(
I came close, but got stuck with full date including the name of the day and the name of the month and space between everything when I just want the numeric day/month with no spaces.
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
Posted at 14:34 on October 16th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
Could you be more specific?
-----
Now you see the violence inherent in the system!
Posted at 14:35 on October 16th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
This is the url I want to adjust- http://www.grimmy.com/images/2002/mgg101602.gif
It would be something like http://www.grimmy.com/images/2002/mgg$month$day02.gif
The random img script uses this line to output the adjusted url- print "Location: $basedir$files[$num]

";
Everything I've tried either gets a 500 internal server error, or makes the resulting url http://www.grimmy.com/images/2002/mggWed%2020%20Oct%202002.gif
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
Posted at 15:04 on October 16th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
Could you post the script code you tried?
-----
Now you see the violence inherent in the system!
Posted at 17:41 on October 16th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
I can post the most recent one, but I don't remember what one got me the "http://www.grimmy.com/images/2002/mggWed%2020%20Oct%202002.gif" I've tried more than a dozen variations.

# Necessary Variables
$basedir = "http://www.grimmy.com/images/2002/mgg";
@files = ("02.gif);
http://www.grimmy.com/images/2002/mgg101602.gif

# Options
$uselog = 0; # 1 = YES; 0 = NO
$logfile = "/home/mattw/public_html/image/pics/piclog";
$gif=".gif"
# Date
$day = (localtime(time))[3];
$month = (localtime(time))[4];
$year = (localtime(time))[5];
$bla = join('-', $month,$day,$year);

# Done
#######################
srand(time ^ $$);
$num = rand(@files); # Pick a Random Number

# Print Out Header With Random Filename and Base Directory
# print "Location: $basedir$files[$num]

";
#print "Location: $basedir$bla[$gif]

";
print "Location: http://www.grimmy.com/images/2002/mgg$bla.gif";

# Log Image
if ($uselog eq '1') {
open (LOG, ">>$logfile");
print LOG "$files[$num]
";
close (LOG);
}


A lot of those variables I'm not using, but I left in the script in case I decided to try them.

Edited by Cypherswipe at 01:43 on October, 16th 2002
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
Posted at 09:41 on October 17th, 2002 | Quote | Edit | Delete
Avatar
Admin
Reborn Gumby
Posts: 11140
That script already can't work because you don't tell it the path to Perl.
-----
Now you see the violence inherent in the system!
Posted at 12:14 on October 17th, 2002 | Quote | Edit | Delete
Avatar
Member
Retired Gumby
Posts: 740
It does work without the path as long as it has a .pl extension.
-----
At the end of the day, you're left with a bent fork & a pissed off rhino.
» Multiple Pages: 123
ReplyNew TopicNew Poll
Powered by Spam Board 5.2.4 © 2007 - 2011 Spam Board Team