Gossamer Forum
Home : General : Perl Programming :

how to pass a variable with ssi?

Quote Reply
how to pass a variable with ssi?
I need to add lines like this <!--#exec cgi="count.pl?1"--> obviously I can't do this. It's an html page and not in the cgi dir where these links will be.
count.pl will open a file called 1.dat (or whatever the var is) and get the number that is there, its just a count number, and print on the html page.
Any ideas?
Quote Reply
Re: how to pass a variable with ssi? In reply to
I see you've already discovered that trynig to use arguements on a SSI call is not possible. That really sucks! Smile

I have 2 suggestions for you though, take a look at some of the counter scripts that use <img src="coung.pl?1.dat"> type stuff.. maybe that will lead you in the right direction. Also, you can use a Config file, I understand how un "on the fly" that is, but it is a solution. You could say like

if ($refdocument eq index.html {
$dat_file = 1.dat;
}
else { $dat_file = default.dat; }

I forget how to assign $refdocument, I think its one of the $ENF{Remote_Addr} type commands.

Hope that points you in the right direction!




------------------
The Crowe crowe@darkspiral.com
www.darkspiral.com
www.lit.org
Quote Reply
Re: how to pass a variable with ssi? In reply to
You have a couple different ways:

Quote:
The CGI script is given the PATH_INFO and query string (QUERY_STRING) of the original request from the client; these cannot be specified in the URL path. The include variables will be available to the script in addition to the standard CGI environment.

So if you can make your link:

http://www.myserver.com/page.html?1

then 1 will be passed to your SSI script as the QUERY_STRING.

A little more secure and safe way:

Quote:
The value is a (%-encoded) URL relative to the current document being parsed. The URL cannot contain a scheme or hostname, only a path and an optional query string. If it does not begin with a slash (/) then it is taken to be relative to the current document.

Use the include directive and you can use query string:

<!--#include virtual="/path/to/cgi/count.pl?1"-->

will work.

Cheers,

Alex
Quote Reply
Re: how to pass a variable with ssi? In reply to
$refdocument = $ENV{'HTTP_REFERER'};

Although you may have to use the full url, particularly if some of the pages will have the same filename (index.html for example). If all your pages have unique names, you can strip the HTTP_REFERER variable down to just the filename.

Cheers,
adam
Quote Reply
Re: how to pass a variable with ssi? In reply to
I get this error when using the include virtual :
[an error occurred while processing this directive]
This is how I call it
Code:
<!--#include virtual="http://www.djmixes.com/cgi-bin2/ra/count.pl?2"-->

This is the count.pl script
Code:
$file = $ENV{'QUERY_STRING'};
$file = "$file.dat";

$count_file = "/usr/local/etc/httpd/htdocs/usr/dance/cgi-bin/ra/data";

print "Content-type: text/html\n\n";
open(FILE,"$count_file/$file") | | die "BUSY";
$filenum = <FILE>;
while(<FILE> ) {
print $_;
}
close(FILE);
exit(0);

Maybe it's this code that is screwing it up?

Not too sure how to do the first one you mentioned? How will it know that I am calling count.pl when there is no mention of it? Or am I seeing it wrong?
Thanks,
Derek


[This message has been edited by Predator (edited April 13, 1999).]
Quote Reply
Re: how to pass a variable with ssi? In reply to
Have any one got a URL to a good SSI online manual or FAQ?


Thanks in advance!

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: how to pass a variable with ssi? In reply to
Pasha,

Try:

Code:
<!--#include virtual="/cgi-bin2/ra/count.pl?2"-->

And change

Code:
print $_;

to

Code:
print $filenum;

Might be the same thing, but try it anyway! Can't do any harm now can it? Can it? Smile

adam
Quote Reply
Re: how to pass a variable with ssi? In reply to
I tried all that and others. I gotta find a way to do this.
Thanks for trying tho.
Quote Reply
Re: how to pass a variable with ssi? In reply to
I got it!
Stupid mistake too!
I had this
print $filenum;
should have been this
print "$filenum";

QUOTES!
Always learning I guess.
Thanks to all!
Quote Reply
Re: how to pass a variable with ssi? In reply to
Is there a limit to how many of these I can have on a page? It seemed to have crapped out at about 25 on one page. I got that directive error again. Then I took a few out and the ones that gave an error weren't anymore.

Thanks again Smile
Quote Reply
Re: how to pass a variable with ssi? In reply to
You really don't want 25 on one page, make the page a .cgi page instead and generate it all with one script call.

Each SSI command has to run a program and load perl, lots of overhead if you want to do it 25 times for one script.

Cheers,

Alex