SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old February 11th, 2001, 07:53 PM
chateau_x chateau_x is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 8 chateau_x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
  #2  
Old February 12th, 2001, 07:58 AM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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.

Reply With Quote
  #3  
Old February 13th, 2001, 01:42 PM
chateau_x chateau_x is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 8 chateau_x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry still no go...

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?

Reply With Quote
  #4  
Old February 13th, 2001, 05:36 PM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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.

Reply With Quote
  #5  
Old February 15th, 2001, 11:52 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 9
Write a parse_ssi() sub routine that will use LWP to fetch the ssi page and parse it back into your code.

Reply With Quote
  #6  
Old February 15th, 2001, 11:58 AM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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]

Reply With Quote
  #7  
Old February 15th, 2001, 12:02 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 9
Quote:
Originally posted by Adrian2
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!

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.

Reply With Quote
  #8  
Old February 15th, 2001, 12:21 PM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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.

Reply With Quote
  #9  
Old February 15th, 2001, 01:40 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 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.

Reply With Quote
  #10  
Old February 15th, 2001, 03:10 PM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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.

Reply With Quote
  #11  
Old February 15th, 2001, 03:37 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 9
Heh, alright . Just looking out for the welfare of the perl community .

Reply With Quote
  #12  
Old February 17th, 2001, 11:32 PM
chateau_x chateau_x is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 8 chateau_x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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);
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > printing SSI from PERL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |