Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to CGI: Couple of questions 2

Status
Not open for further replies.

solepixel

Programmer
May 30, 2007
111
0
0
US
Hi. I am new to CGI and am just starting out trying a few things. I am a PHP/MySQL developer and am comfortable writing XHTML, XML, CSS, JavaScript, and ASP.NET VB. I know pretty much nothing of CGI and would like to learn a bit more. Here are a couple of questions I have to start out with:

In a project I'm working on, there's some code that looks like this:
Code:
if [[ -x /SOME/DIR/SOMETHING ]];then
 /SOME/DIR/SOMETHING INTR001
else
 SOMETHING INTR001
fi

what exactly is going on here? Is this if statement referencing some file, performing a command, what? what does the [[ ]] mean? why the ";"? what is the "fi" at the end?

Main reason I'm asking about this in particular, because I've looked on the server and there is no file located in /SOME/DIR/ called SOMETHING. There aren't any files on the whole server called SOMETHING. What's this code doing?


Another question I have is I tried this to perform a redirect (something more consistent than "meta refresh" or a javascript redirect:
Code:
#!/usr/bin/perl
my $URL = "/cgi-bin/main.cgi?INIT";

print "Location: $URL\n\n";
however, I get the message:

Method Not Allowed
An error has occurred.

I tried putting this file in the "CGI-BIN" and I get:

Server Error
This server has encountered an internal error which prevents it from fulfilling your request. The most likely cause is a misconfiguration. Please ask the administrator to look for messages in the server's error log.

Is this because of some setting I have somewhere on the server that restricts redirects? Also, why won't cgi files work outside of /cgi-bin/? Is that also some kind of setting? Is it possible to get CGI to work outside the CGI-BIN? Is there some other way of performing a server-side redirect on a server like this?

I am curious to learn about this stuff and hoped someone could help. Thanks.
 
Hi

solepixel said:
what exactly is going on here?
Your first code seems to be a shell script. Probably either [tt]bash[/tt] or [tt]ksh[/tt]. For more about shell scripts read the given shell's man page. Or ask in forum822.
solepixel said:
Is this if statement referencing some file, performing a command, what?
If the specified file exists and is executable, executes it by referencing it with full path, otherwise executes it just hoping it is [small]a)[/small] an alias, [small]b)[/small] a function, [small]cd)[/small] shell built-in or [small]d)[/small] an executable somewhere on the [tt]PATH[/tt].
solepixel said:
what does the [[ ]] mean? why the ";"? what is the "fi" at the end?
[tt][[ ]][/tt] - conditional expression with pattern matching
[tt];[/tt] - the [tt]if[/tt] and [tt]then[/tt] keywords should be in separate lines but the author preferred to write them on the same line
[tt]fi[/tt] - closing pair of [tt]if[/tt]
solepixel said:
Is this because of some setting I have somewhere on the server that restricts redirects?
Usually none, but may depend on the web server you use. Your [tt]perl[/tt] code works for me. Just the /cgi-bin/main.cgi directly works for you ?
solepixel said:
Also, why won't cgi files work outside of /cgi-bin/?
Usually that is the default, but may depend on the web server you use. It is mainly for security reasons.
solepixel said:
Is that also some kind of setting?
Usually there is, but may depend on the web server you use. Maybe try to post in your web server's forum.
solepixel said:
Is there some other way of performing a server-side redirect on a server like this?
Strange wording. Let us call it simply HTTP redirect, because are involved both the server and the client. Well, while you asked for, yes. You can use [tt]Refresh[/tt] as an ugly and stupid alternative.

Feherke.
 
Wow thank you so much for helping me with this information. thanks for being so detailed in your response. I will check out the UNIX and web server forums to hopefully come up with a solution to my situation.
 
that deserves at least two stars [smile]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top