homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

looking for simple if-else script

Msg#: 4374967 posted 7:53 pm on Oct 15, 2011 (gmt 0)

I may be in over my head here. That said, I'd like to write a simple script (or tailor an existing one) that calls either one or another snippet of HTML, depending on which of two subdirectories the requested URL falls within.

For example, if the requested page is in my www.site.com/bluewidgets directory, then a picture of a blue widget would appear at the top. But if the requested page is in my www.site.com/redwidgets directory, then an image of a red widget would appear at the top instead.

My site is on an Apache server -- no PHP, but an early version of Perl was installed in my cgi-bin directory back in 1997.

Can a simple if-else script accomplish what I need? If so, can someone here link to a basic tutorial or a template. I can't seem to find anything on point. If not, I suppose I'll need to create two different server-side includes and add one or another tag to each and every HTML file. I could do that, of course, but it would be a hassle given the large number of files on my site. I'd prefer a simpler, more elegant solution.

I hope I've made all this clear enough.



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4374967 posted 8:25 pm on Oct 15, 2011 (gmt 0)

I guess that you have static html pages?
I hope your server has been updated since 1997, but you should probably check that. The easiest (and most efficient) way to handle that is probably SSI (Server Side Includes).

How you enable SSI to parse your pages before sending the output to the client depends on the version of apache you are running.
The SSI could look like this:
<!--#if expr="$REQUEST_URI = /bluewidgets/" -->
<img src="/blue.gif" />
<!--#elif expr="$REQUEST_URI = /redwidgets/" -->
<img src="/red.gif" />
<!--#endif -->

Look at the Apache Website for how to enable and test it: For Apache2 [httpd.apache.org] or Apache 1.3 [httpd.apache.org]. But if you're still on Apache 1.3, you really should be thinking about moving.


Msg#: 4374967 posted 9:29 pm on Oct 15, 2011 (gmt 0)


Wow, I can't believe how easy that was. I just created a test page and uploaded it into the two different directories, and then created an SSI that states the argument in the form you indicated (and per the Apache2 documentation). It worked the first time! I nearly fell off my chair.

Thank you, thank you, thank you. WebmasterWorld and its able members and moderators are a true godsend.

P.S. Yes, static HTML only, and my ISP has always kept Apache up-to-date.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved