Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2007, 05:07 AM   #1 (permalink)
New Member
 
Join Date: Mar 2007
Posts: 11
Default Run CGI script when site is visited.

I have CGI stuff working, but I want to run a script as soon as the main site is visited (i.e. when this appears in the address bar: http://www.[whatever].com/ ). Currently, I simply redirect to http://www.[whatever].com/cgi-bin/script.cgi with JavaScript, but that's really annoying. I'm certain there's a better way to do it, but I don't know how.

Thanks in advance for any input.
misho is offline   Reply With Quote
Old 03-16-2007, 07:50 AM   #2 (permalink)
Super Noob
 
zkiller's Avatar
 
Join Date: Aug 2004
Location: position:relative
Posts: 1,560
Send a message via AIM to zkiller Send a message via Yahoo to zkiller
Default

it depends on whether your host allows you to run cgi scripts from anywhere within your site. if they do, you could simply have your script in the root directory like this... yourdomian.com/index.cgi

if not, redirecting your users is the only way, be it via a link, script or meta redirect makes no real difference.
__________________
Stefan, the Post Master

Track Devil - May the boost be with you!
zkiller is offline   Reply With Quote
Old 03-16-2007, 06:49 PM   #3 (permalink)
New Member
 
Join Date: Mar 2007
Posts: 11
Default

Since I'm my host, I guess I'll have to figure out how to do that. Thanks.
__________________
- Misho
misho is offline   Reply With Quote
Old 03-17-2007, 12:14 PM   #4 (permalink)
Silver Member
 
DLPerry's Avatar
 
Join Date: Jan 2006
Location: Texas
Posts: 154
Send a message via ICQ to DLPerry Send a message via AIM to DLPerry Send a message via MSN to DLPerry Send a message via Yahoo to DLPerry
Default

My fav programmer has a couple of articles that offer ways to run a cgi script on page load -

http://www.bontragercgi.com/Running_...Page_Load.html

http://www.bontragercgi.com/OnLoad_A...GI_Script.html
DLPerry is offline   Reply With Quote
Old 03-18-2007, 02:13 AM   #5 (permalink)
New Member
 
Join Date: Mar 2007
Posts: 11
Default

Alright, in case anyone is running Apache, this is how you enable running CGI scripts anywhere you want to (this is for apache-2.0.54, so it might be somewhat different for the 2.2 releases):

1. find httpd.conf which might be in /etc/apache/something or something else under Windows. Searching for the file should be easy enough, how many files called httpd.conf could you possibly have?

2. open httpd.conf in a text editor.

3. find a line that says something like: Options Indexes FollowSymLinks
This should be inside the <Directory "/path/to/webroot/htdocs"> section. This is important, since pretty much any <directory "/p/a/t/h/"> section could have such a line.
Append ExecCGI to the line: Options Indexes FollowSymLinks ExecCGI
NOTE: Windows probably won't have a FollowSymLinks option, since there are no symlinks in Windows.

4. Find a line that says something like: DirectoryIndex index.html
This line should be outside all sections (i.e. not between <something> and </something>). It tells the webserver to automatically open index.html when you navigate to a directory. So, when you go to www.foo.com, it will open www.foo.com/index.html.
Append index.cgi (or whatever you want as long as it ends in .cgi) to that line: DirectoryIndex index.html index.cgi
Now, it will look for index.html and index.cgi.

5. Now, add a line (outside all sections) that says: AddHandler cgi-script .cgi
Chances are that there is already such a line but it has been commented out. Try searching for it and removing the # from the beginning of the line.
This line tells Apache that when it comes across a file that ends in .cgi, it should execute it rather than displaying its contents.

Now, restart apache and make an index.cgi file in some directory and try to open it
__________________
- Misho
misho is offline   Reply With Quote
Old 03-18-2007, 05:50 PM   #6 (permalink)
Super Noob
 
zkiller's Avatar
 
Join Date: Aug 2004
Location: position:relative
Posts: 1,560
Send a message via AIM to zkiller Send a message via Yahoo to zkiller
Default

glad to see you figured it out on your own.
__________________
Stefan, the Post Master

Track Devil - May the boost be with you!
zkiller is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:26 AM.


Computer Forum - Internet Business - Webpage Design

 
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.