PATH,script,displays,fortune,every,time,only,
Quick Search for: in language:   
PATH,script,displays,fortune,every,time,only,
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Perl Stats

 Code: 48,917 lines
 Jobs: 173 postings

 

You are in:

 
Login


Latest Code Ticker for Perl
Click here to see a screenshot of this code!Very Simple Editor
By Incipient Cipher on 3/3

(Screen Shot)

credit card Validation
By Bhushan Paranjpe on 3/1


randpass
By Joel Addams on 2/27


Programming Jargon, (with search)
By Benjamin Bechard on 2/26


CGI-Fortune with Extras
By Slava Shirokov on 2/23


TKase_tags.pl
By Incipient Cipher on 2/23


Printer Friendly Page v2
By Richard Leishman on 2/20


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 

 
 

   

CGI-Fortune with Extras

Print
Email
 
VB icon
Submitted on: 2/23/2002 3:26:29 PM
By: Slava Shirokov  
Level: Advanced
User Rating: Unrated
Compatibility:5.0 (all versions), 4.0 (all versions)

Users have accessed this code 111 times.
 
 
     This script displays a new `fortune` every time it's ran, only works on systems with the fortune program installed, and in the $PATH of a webserver.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    =**************************************
    = for :CGI-Fortune with Extras
    =**************************************
    Created by: Slava Shirokov
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    =**************************************
    = Name: CGI-Fortune with Extras
    = Description:This script displays a new
    =     `fortune` every time it's ran, only work
    =     s on systems with the fortune program in
    =     stalled, and in the $PATH of a webserver
    =     .
    = By: Slava Shirokov
    =
    = Inputs:It accepts CGI variables:
    fortune.pl?o=1 is equivelent to running 'fortune -o'
    fortune.pl?s=1 is equivelent to running 'fortune -s'
    and the combination of the 2: fortune.pl?s=1&o;=1 is the same as 'fortune -o -s'
    One more variable, show-source, if set as a CGI var to a true value, will make this script display it's own source code formatted as proper HTML. (ex. fortune.pl?show-source=1 would display program listing)
    =
    = Returns:Returns either a fortune, or i
    =     t's own source code.
    =
    = Assumes:This code only runs as a CGI s
    =     cript, run it standalone only if you can
    =     visualize HTML in your head. It asumes t
    =     hat it can open 'fortune' as a pipe with
    =     out specifing a full path.
    =
    = Side Effects:For every run, a copy of 
    =     fortune will be opened by a pipe, so any
    =     rescources it takes alone, will be combi
    =     ned with the rescources needed to run th
    =     is script.
    =
    =This code is copyrighted and has    = limited warranties.Please see http://w
    =     ww.Planet-Source-Code.com/xq/ASP/txtCode
    =     Id.290/lngWId.6/qx/vb/scripts/ShowCode.h
    =     tm    =for details.    =**************************************
    
    #!/usr/bin/perl -w 
    use strict;
    use CGI;
    my $cgi = new CGI;
    my @fortune;
    my $flags = " ";
    my $amp = pack("c", "038"); #Needed to make HTML display right
    print 
    	$cgi->header(),
    	$cgi->start_html(
    		-title => "Fortune of the moment"
    	);
    if($cgi->param("o")) {
    	$flags .= " -o";
    }
    if($cgi->param("s")) {
    	$flags .= " -s";
    }
    open(FORT, "fortune $flags|") or death();
    @fortune = <FORT>;
    close(FORT);
    foreach (@fortune) {
    	s/\n/<br>\n/;
    }
    if(!$cgi->param("show-source")) {
    	print @fortune;
    }
    else {
    	open(SELF, "$0") or death();
    	@fortune = <SELF>;
    	foreach (@fortune) { #Escape everything propertly for HTML
    		s/\&/${amp}amp;/g;
    		s/\t/${amp}nbsp;${amp}nbsp;${amp}nbsp;${amp}nbsp;/g;
    		s/\</${amp}lt;/g;
    		s/\>/${amp}gt;/g;
    		s/\n/<br>\n/g;
    	}
    	print 
    		$cgi->b(
    			"$0 by Slava Shirokov mutatorr\@accessirc.net"
    		),
    		$cgi->br(),
    		$cgi->br(); 
    	print @fortune;
    }
    print
    	$cgi->end_html();
    sub death {
    	print "An error has occured.\<br\>";
    	print "I will shut down.";
    	print $cgi->end_html();
    	exit 1;
    }

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Advanced category)?
(The codewith your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
2/23/2002 5:09:11 PM:Slava Shirokov
I run this script 
at:
http://mut.mutatorr.net
just add 
/?params to play with it.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Perl Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.