|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
hopefully someone can help me.
I'm trying to write an 'include' into a perl script that will spit out bad_email.html when the conditional is met, and the best i'm getting is the printing of the 'hash'. here's the code: sub bad_email { print <<__STOP_OF_BADMAIL__; Content-type: text/html <!--#include file="bad_email.html" --> __STOP_OF_BADMAIL__ } Please help! Thanks in advance... |
|
#2
|
|||
|
|||
|
Use page redirection
Assuming the bad_email.html is the complete page that you want to be shown in this situation, the easiest thing to do is just to redirect the browser to that page.
Instead of outputting the Content-type header, output: Code:
print "Location: bad_email.html\n\n"; This is an HTTP header just like Content-type, and like that, has to be the very first thing you output to the page and followed by a blank line, as in the code above. If the bad_email.html page is just part of the code you want on the page, then you'll have to write a routine that opens up the file, reads in the lines and outputs them. As far as I know, there's no way for the web server to parse the output of a Perl script for server-side includes, but I'd be interested to hear if anyone knows how to do it. Perhaps it can be done by adding: Code:
AddType text/x-server-parsed-html .cgi to your directory's .htaccess file, but I doubt it. Try it! I think it's more likely to screw things up. |
|
#3
|
|||
|
|||
|
Adrian2,
Great solution, i'll be damned if i can get it to work though. Either i get a server error 500, or simply "; is printed to the page. Any other ideas? |
|
#4
|
|||
|
|||
|
Well using the Location header *does* work to redirect the browser to another page. You probably have some other problem with your code. Does it syntax check when you run it from the command line? (perl -c yourscript.cgi) Is the Location header the very first thing that gets printed to the page?
Paste the relevant bits of the code up here and we can have a look. As an aside, I find using print qq an easier way to output large chunks of HTML rather than the "here document" style in your code. Example: Code:
print qq{
<p>This is a load of HTML code in here!</p>
<hr>
};
Note the semicolon after the closing brace: essential. |
|
#5
|
|||
|
|||
|
Write a parse_ssi() sub routine that will use LWP to fetch the ssi page and parse it back into your code.
|
|
#6
|
|||
|
|||
|
Well as an SSI would be a local file anyway, you don't need to use LWP to fetch the file. Just, er, open it!
Code:
show_ssi('your_ssi_file.htm');
sub show_ssi {
open FILE, $_[0];
print (<FILE>);
close FILE;
}
[Edited by Adrian2 on 02-15-2001 at 11:16 AM] |
|
#7
|
|||
|
|||
|
Quote:
But what if that file has ssi's in it? or what if the file is actually <!--#exec cgi...-->? Trust me, letting apache do the parsing of the file is a much better idea. |
|
#8
|
|||
|
|||
|
Ok, well in that situation that sounds reasonable. However, the original poster wanted to do an #include which isn't a script, just plain HTML.
|
|
#9
|
|||
|
|||
|
Yes, but you don't seem to understand is that you can parse SSI's _inside_ another SSI... as many times as you want. You can have include.html with 50 other ssi's being included in it. Allowing apache to do this is best way. It's not like LWP is hard to use or slow at all.
|
|
#10
|
|||
|
|||
|
Ok Jon, good point. I promise if I ever need to do this I'll go the LWP way. Been using it quite a bit recently for non-CGI scripts and it's jolly neat.
|
|
#11
|
|||
|
|||
|
Heh, alright
. Just looking out for the welfare of the perl community . |
|
#12
|
|||
|
|||
|
here is the pertinent code
Hi Guys, once again, thanks for the input. Here is the bad_email variable. Basically when an improperly formatted
email is entered, this chunk of code is run. What i'm trying to do is instead of it printing the "SORRY!" bit, i'd like it to print my own custom html page. Don't know what the cleanest way to do this is, hopefully you can help. Thanks again. sub bad_email { print <<__STOP_OF_BADMAIL__; Content-type: text/html <FONT SIZE="+1"> <B> SORRY! Your request could not be processed because of an improperly formatted e-mail address. Please use your browser's back button to return to the form entry page. </B> </FONT> __STOP_OF_BADMAIL__ } sub get_the_lock { local ($endtime); $endtime = 60; $endtime = time + $endtime; while (-e $lockfile && time < $endtime) { # Do Nothing } open(LOCK_FILE, ">$lockfile"); } sub drop_the_lock { close($lockfile); unlink($lockfile); } |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > printing SSI from PERL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|