Re: Parsing a file as it is being served

2003-02-18 Thread Philip Pawley
Wiggins D'Anconia wrote:
Philip Pawley wrote:
I want to be able to adapt my web-files, as they are being served, so that older 
browsers get an xhtml 1.0-transitional version instead of the default xhtml 1.1 
version. This will involve replacing the DOCTYPE declaration and, also, various xhtml 
tags to include deprecated html attributes. This needs to happen only for older user 
agents such as Netscape 4.
I imagine this can be done using some search-and-replace module but I can't find a 
suitable one. 
Currently, I am using SSI to run a browser-detection script and insert appropriate 
css link .. and javascript script../script tags. The problem with that is that 
it limits me to parsing only a small portion of the html file. Earlier, I asked a 
question about re-using variables so that I could use the several SSI includes and 
several scripts to do the task. It seems that storing the computed values of the 
variables from one script to the next is a bit too involved. (Thanks you, Wiggins 
D'Anconia, for your help with that).

Though it may not be the best way, it is certainly a way.  We used to embed special 
comments in a file, then in the script, read in the template as we called it, 
looked for the comment and whenever we found it dropped in whatever content was 
necessary.  You could do something similar to this...

-- THIS IS PSEUDO CODE!!! --

#!/usr/bin/perl

my $browser = 'old' if ($ENV{'USER_AGENT'} =~ /Netscape 4/);
my $newtag = 'p /';

print Content-type: text/html\n\n;

my $TEMPLATE;
open($TEMPLATE,'/path/to/template.html') or die Can't open template for reading: $!;
my @template = $TEMPLATE;
close($TEMPLATE);

foreach my $line (@template) {
   if ($line =~ /!--doctype--/) {
   if ($browser eq 'old') {
   # print old version of doctype (or no doc type)
   }
   }
   elsif ($line =~ /!--oldtag--/) {
   $line =~ /!--oldtag--/$newtag/;
   print $line;
   }
}


This only works when comments are on their own line for the doctype and any server 
side includes will *NOT* be parsed without special treatment from the web server, or 
by getting the template through a second request to the server, but it should give 
you some ideas and get you started. Obviously you can use the power of hashes to 
handle multiple old tags, etc.

http://danconia.org

Thanks for the suggestions. The problem is I need to start from someone requesting an 
html file, not someone calling a script.

How can I do it?

Thanks,

Philip Pawley


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Parsing a file as it is being served

2003-02-06 Thread Philip Pawley
I want to be able to adapt my web-files, as they are being served, so that older 
browsers get an xhtml 1.0-transitional version instead of the default xhtml 1.1 
version. This will involve replacing the DOCTYPE declaration and, also, various xhtml 
tags to include deprecated html attributes. This needs to happen only for older user 
agents such as Netscape 4.

I imagine this can be done using some search-and-replace module but I can't find a 
suitable one. 

Currently, I am using SSI to run a browser-detection script and insert appropriate css 
link .. and javascript script../script tags. The problem with that is that it 
limits me to parsing only a small portion of the html file. Earlier, I asked a 
question about re-using variables so that I could use the several SSI includes and 
several scripts to do the task. It seems that storing the computed values of the 
variables from one script to the next is a bit too involved. (Thanks you, Wiggins 
D'Anconia, for your help with that).

Thanks,


Philip Pawley


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Reusing a variable from another script

2003-01-25 Thread Philip Pawley
I am calling 2 scripts separately using server-side includes. I want to reuse the 
variables from the first script in the second.

I am very much aware that I need to do more reading. Where do I look for the answers 
to this particular question?

Thanks, 
Philip Pawley


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: HTTP headers

2003-01-16 Thread Philip Pawley
Thanks William,

The server is Apache. I was calling the script using an SSI in an html page:
!--#include virtual=/cgi-bin/test.cgi --

I just tried calling the script directly with the browser and that did work. I suppose 
this means that you can't alter the headers using a script called with a virtual 
include. Is that right?

Actually, this brings me to my reason for messing with HTTP headers: I want to create 
Expires: HTTP headers for the server response when it is dishing out image files 
(also for javascript and css files). Server-side includes would be no use for this 
anyway. How would I do it?

Thanks again,


At 16/01/03 11:03 -0500, William McKee wrote:
Hi Philip,

I looked at the script. How are you running it? From the command
line or from a web server? It works fine on the comand line and from the
server for me. What server are you using to display it? I'm using Apache. 

If you are running it from the server you may need to include -nph = 1 to
tell the server not to generate headers because you are doing it
yourself. I've never had a need to do this myself.

Good luck,
William

Philip Pawley


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




HTTP headers

2003-01-14 Thread Philip Pawley
Can I add an HTTP header to my web-site's server's response with perl? (It isn't my 
server). The server is running perl 5.6.1. If I can get it to work, I want to start 
using Expires: headers.

I've no idea whether this makes any sense but I tried the following:-

I have a .pl script called by SSI from my html pages. The other functionality of the 
script works fine.
I added these lines culled from the HTTP::Headers documentation (I added the my):-


require HTTP::Headers; 
my $h = HTTP::Headers-new; 
$h-header('Content-Type' = 'text/plain');


The page is still served, but there is no difference in the headers. I tried other 
headers too, still without any effect.

As I say, I don't know what I'm doing, so all this may be totally absurd.

Please put me on the right track.

Thanks,
Philip Pawley


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: CGI scripts permissions

2002-12-25 Thread Philip Pawley
I'm a newbie, so the below is a question: Is this problem of cgi permissions different 
when you are just running a perl script from a virtual include - as I am?

Reading this thread, I did some tests and changed my script's permissions to 500 and 
it still works fine. (I first did it just for a test script of course)! 

I am just an ordinary user (in my own group) on the web server. How is this possible?

Thanks, 
Philip Pawley


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]