Gossamer Forum
Home : General : Perl Programming :

SSI include in search.cgi. Subroutine help?

Quote Reply
SSI include in search.cgi. Subroutine help?
Hey,

I am trying to use my virtual SSI include in my search results page. I know that you can't use SSI within CGI generated pages, but is there a way to insert my HTML table into the search results?

I have found this thread that has some discussion on what I am trying to do:
http://www.gossamer-threads.com/scripts/forum/resources/Forum8/HTML/000601.html
But it is a little over my head. I think the following code is what I am trying to go for, but don't know how/where to put it, and call the sub into my page:

In Reply To:

sub include_file {
open(FILE, "/full/server/path/filename.html") or die("Couldn't open the file.");
@lines = <FILE>;
close(FILE);
foreach $line (@lines) {
print $line;
}
}

and this to insert it where it's wanted:
code:


|; &include_file; print qq|
The file I am trying to include is: http://www.addictfantasysports.com/perspectives/perspectives.htm


Any help? I fairly new to cgi, so I need someone to hold my hand and walk me through it.

Thanks!

Chad


Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
If the file you are trying to include from is on the same server you can just do:

open(FH, "/path/to/your.file") || die "Error: $!\n";
print for (<FH>);
close(FH);

If it is a remote web page you could do:

use LWP::Simple;
print get("http://www.addictfantasysports.com/perspectives/perspectives.htm");

-- Gordon



s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
If you are using Templates...

You also need to define the &include_file as a global tag or a tag to use in the search_results.html file.

You need to define it in the following manner:

Code:
insert_file => &insert_file,
Then you will need to use the following tag in your search_results.html file:

Code:
<%insert_file%>
Regards,

Eliot Lee
Anthro TECH, L.L.C
Web: http://www.anthrotech.com/
Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
Alright guys, thanks for the reply. I have added your code to site_html_templates:

%globals = (
date => &get_date,
time => &get_time,
db_cgi_url => $db_cgi_url,
build_root_url => $build_root_url,
site_title => $build_site_title,
css => $build_css_url,
insert_file => &insert_file
);

sub insert_file {
open(FH, "/usr/local/etc/httpd/vhosts/addictfantasysports.com/htdocs/perspectives/perspectives.htm") || die "Error: $!\n";
print for (<FH>);
close(FH);
}

Then inseted the <%insert_file%> into the search results template.

Right now it tries to download the file (ie. the window pops up prompting a 'save to disk'). Is there something I am missing?

Thanks!



****ON A SIDE NOTE*** It does however print the html file at the top of my page when when I am building pages! Before it starts the "Building..." routine it prints the html ile I was trying to insert on my search results page!
Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
Also, add, modify and rate.cgi's are all now trying to download the file when clicked. The permissions are set to 755.

What am I doing wrong?

Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
In Reply To:
print for (<FH>);
This line of code should be: print <FH>;

Regards,

Eliot Lee
Anthro TECH, L.L.C
Web: http://www.anthrotech.com/
Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
I did change that peice of code, but it still doesn't work. I changed the '<>' brackets to parentheses, and now it doesn't try to download, but it only prints '1' where the perspectives html should be.

Is the code correct? What could I be missing?

Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
Try replacing your sub with the following codes:

Code:
sub insert_file {
# ---------------------------------------------
# Displays file.

open (INC, "/path/to/file.html") or return "Can't find include file: {$_}";
return join ("", <INC> );
}
Change /path/to/file.html with the absolute path and file name/extension.

Regards,

Eliot Lee
Anthro TECH, L.L.C
Web: http://www.anthrotech.com/
Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
GENIOUS!

Thanks Eliot! It works great!

I really appreciate the help!

Chad ;)

Quote Reply
Re: SSI include in search.cgi. Subroutine help? In reply to
You're welcome.

Glad it worked.

Regards,

Eliot Lee