Forum Moderators: coopster & phranque

Message Too Old, No Replies

Passing arguments among #exec scripts...

Is it possible?

         

Travholt

10:19 pm on Sep 16, 2001 (gmt 0)

10+ Year Member



I'm fairly green at Perl and CGI programming, and my current web host doesn't support #exec (you might remember my first thread from about a month ago -- and no, they still haven't got it working, so I'm moving to someone who does in the near future), so I have no means of actually testing this yet, but I'm going ahead and asking anyway. :-)

Here's an example to illustrate the type of thing I'd like to do: Say I make a Perl script that, by default, outputs an HTML table containing the calendar of current month. It also includes a <prev> and <next> link. This calendar is then placed on an HTML page with SSI #exec cmd or #include virtual (depending on what works; I've discovered that you can't pass arguments with #exec cgi -- see below). So, if you click <next>, it should set the correct month (currently, that would be something like $month="2001/10") and then reload the page with that month instead of the current.

I know you can pass constant values like this:

<!--#exec cmd="/cgi_bin/calendar.pl 2001/10"-->

But what I'm looking for is the ability to do something like:

<!--#exec cmd="/cgi_bin/calendar.pl $month"-->

Obviously, this won't work (although, as I said above, I can't test anything yet, but I would be VERY surprised if it did), but it illustrates the principle.

I've looked "all over" for the answer to this, and the closest I've come is this page: [oreilly.com...] (under "Counting Days Until...")

There, they say you cannot pass arguments as part of an SSI exec cgi directive, but you can use #exec cmd instead and run the script as a Perl program and supply the arguments as regular command line arguments, like I do above.

But what if you want those arguments to change according to user input? Is this at all possible, and if so, how is it done?

I'm beginning to suspect that using cookies is the only way this is possible. Moreover, that would make it possible to have several such "gadgets" on one page, all keeping their individual settings on reload. The downside to this approach is that some users have disabled cookies. So I'd rather find a way that works for all.

And before you ask why I don't just do the whole page in Perl instead of using SSI: No, I don't want to do that. I use Dreamweaver and its Templates function to publish my pages, and intend to continue doing that if it's at all possible. If I can find a way to do what I describe above, all my dreams come true. :-)

Brett_Tabke

7:45 am on Sep 17, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You can pass arguments. Just use form style. The file at:

[webmasterworld.com...]

Contains one line:

<!--#include virtual="/discussion.cgi?forum=13&discussion=640"-->

Then your cgi parses the arguments just like a form submission.

Travholt

10:55 am on Sep 17, 2001 (gmt 0)

10+ Year Member



Yes, but that's not what I'm asking -- this is: Can you pass a variable as an argument in some way?

I guess what I'm asking, is: With an SSI included script, can you pass a value along to another SSI included script?

Or do I have to use cookies?

Brett_Tabke

11:33 am on Sep 17, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Sorry, rereading I see what you want. The only way I know is to rewrite the file to disk with the updated params. I do some of that around here. Most often, I just use the following links as links to a cgi (your next/prev lead to a cgi url instead of html).

Cookies sounds like the only solution. You could also build up a set of default ssi files in a directory that cover 24-48 months out.

Travholt

11:48 am on Sep 17, 2001 (gmt 0)

10+ Year Member



> You could also build up a set of default ssi files in a directory that cover 24-48 months out.

I didn't understand this.

Brett_Tabke

12:17 pm on Sep 17, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If it is a calendar, and you know what the form parameters need to be, just pass those from an ssi

<!--#include virtual="/calendar.cgi?month=10&year=2001"-->

And so on for each month for the next many months. Then use those ssi's as your next, and last links in the calendar. (if your calendar will allow that type of modification).

Travholt

12:30 pm on Sep 17, 2001 (gmt 0)

10+ Year Member



Ah, I see now.

Well, the calendar was just an example to illustrate the principles of what I'd like to do. It's all about transferring data from one instance of an SSI-included script to another, and it's becoming more and more clear to me that cookies is the way to go.

I'll just have to notify the more paranoid users that if they don't want to turn on cookies, they'll have to make do with less functionality. :-)

bobriggs

1:17 pm on Sep 17, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>I guess what I'm asking, is: With an SSI included script, can you pass a value along to another SSI included script?

I've done this..but I'm not sure if it's exactly what you want. For example:

<!--#if expr="${HTTP_USER_AGENT} = /Slurp/" -->
<!--#set var="brtype" value="inktomi" -->
<!--#elif expr="${HTTP_USER_AGENT} = /Lynx/" -->
.....

The next SSI script that runs on that page has access to the "brtype" variable in the environment and can examine whatever value has been set to that variable. This works on my apache 1.3.6 server, I can't vouch for anything else...