How do I print http 404 not found header?

PERL

    Next

  • 1. parse CSV review
    I have nothing against Text::CSV except that it can be a pain coercing recalcitrant sysadmins to install modules. This can take days to never. A while back I asked about glueing CSV records back together that contain linebreaks. The crux of this is that valid records contain even numbers of double quotes. It's occured to me that a simlar strategy would work for CSV fields. sub parseCSVLine{ my $line=shift; my @fields=();my $field=''; # initialize my @fragments=split(/,/,$line,-1); # split into "," seperated fragments foreach my $nibble(@fragments){ if($field){$field .= ','} # add the missing commas; $field .= $nibble; # combine fragment into a field until... my $count = $field =~tr/"/"/; # count quotes unless($count % 2){ # ...there's an even number of double quotes $field =~s/""/"/g; $field=~s/^\s*"//g; $field=~s/"\s*$//g; # fix quotes # fix quotes push @fields, $field; $field=''; # reinitialize $field } } return @fields; } It all seems too easy. Does this seem like a reasonable approach? Have I missed something? I'm unsure of that fix quotes line. BTW that wild parse CSV regex that's floating around doesn't seem to work on my data. It's a bit too complex for me to figure out why not! Jeff
  • 2. starting apache with mod_perl, error on Apache.pm
    Hi, At the moment i try to install apache_1.3.29 and mod_perl1.29. The installations procedure was successful, but then i tried to start apache with pachecrl start? although i saw on my screen : ./apachectl start: httpd started? then i saw in the error log pache.pm failed to load!.? So i search on the internet for this problem. Someone said then erlModule Apache? should be added to my httpd.conf. So i have done this. Then i get the error on my screen while starting: error] Global symbol "@ISA" requires explicit package name at /usr/lib/perl5/vendor_p erl/5.8.3/CGI/Util.pm line 6.\nGlobal symbol "@EXPORT_OK" requires explicit package name at /usr/lib/perl5/vendor _perl/5.8.3/CGI/Util.pm line 7.\nGlobal symbol "$VERSION" requires explicit package name at /usr/lib/perl5/vendor _perl/5.8.3/CGI/Util.pm line 9.\n ?etcetera..... So i went to /usr/lib/perl5/vendor_perl/5.8.3/CGI/util.pm and comment the se strict? After doing this i now try again to start apache: ?/apachectl start ./apachectl start: httpd could not be started? So do anyone know how i can start apache? Thanks in advance!! Selmar.
  • 3. Comparing system time to specific hours
    Hi, I am fairly new to writing Perl code. I need to write a routine that will redirect website traffic to a maintenance screen between 3am and 4am every night. How do I check a given system date against these schedule down times. Thanks Mike

Re: How do I print http 404 not found header?

Postby Robert Sedlacek » Wed, 20 Oct 2004 01:26:56 GMT




You could first say what you are trying to do. :) If you want to have a
custom ErrorDocument, print out the Data you want to sent to the browser.
And if this is html, a Content-Type set to text/html should be right.

g,
Robert

-- 
 http://www.**--****.com/ 
sapere aude.


How do I print http 404 not found header?

Postby nntp » Wed, 20 Oct 2004 01:28:10 GMT

print "HTTP/1.1 404 Not Found";
do I need
print "Content-type: text/html\n\n"; after it?

Should I print
print "HTTP/1.1 404 Not Found";
print "locatioin: ...";



Re: How do I print http 404 not found header?

Postby lesley_b_linux » Wed, 20 Oct 2004 04:29:48 GMT

Robert Sedlacek < XXXX@XXXXX.COM > writes:





I'd advise against a customised error document.  Nimda seized quite a few
servers up because they were sending customised 404 pages out.  A simple 404
not found http message left to the browser default display mechanism is
sufficient.

Regards

Lesley

Re: How do I print http 404 not found header?

Postby Gunnar Hjalmarsson » Wed, 20 Oct 2004 05:38:17 GMT




Nothing is preventing you from doing both, is there?

     print "Status: 404 Not Found\n",
           "Content-type: text/html; charset=ISO-8859-1\n",
           "\n";

-- 
Gunnar Hjalmarsson
Email:  http://www.**--****.com/ 

Re: How do I print http 404 not found header?

Postby nntp » Wed, 20 Oct 2004 06:50:31 GMT

>

Do you know where I can find the correct header for 404?
You did
print "Status: 404 Not Found\n",
I did
print "HTTP:/1.1 404 Not Found\n",

I need to fake the header to make the brower think it is 404. The fact is I
am using a script to give the error.
So, when seombody visits at some.cgi?okok, I return a 404 header.



Re: How do I print http 404 not found header?

Postby Gunnar Hjalmarsson » Wed, 20 Oct 2004 07:06:08 GMT



I thought that "Status: 404" was correct. Actually, I hope it is,
because I'm using it myself for similar purposes. ;-)

Your question is off topic here, and if you want to go into details with
respect to the HTTP specification, this is definitely the wrong place.

-- 
Gunnar Hjalmarsson
Email:  http://www.**--****.com/ 

Re: How do I print http 404 not found header?

Postby lesley_b_linux » Wed, 20 Oct 2004 07:38:12 GMT

Gunnar Hjalmarsson < XXXX@XXXXX.COM > writes:




In a totally OT way : 

From RFC2616

6.1 Status-Line

   The first line of a Response message is the Status-Line, consisting
   of the protocol version followed by a numeric status code and its
   associated textual phrase, with each element separated by SP
   characters. No CR or LF is allowed except in the final CRLF sequence.

       Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF

Not sure about 'HTTP:/1.1' thought it might be 'HTTP/1.1'

Lesley

Re: How do I print http 404 not found header?

Postby Alan J. Flavell » Wed, 20 Oct 2004 07:46:37 GMT




Surely CGI.pm will take care of such details?

"Status: 404 reason text" is correct for a normal CGI response, but 
not for an nph response.


But if, for some reason, your script were to be repurposed as an
nph script, it would have to be re-cast.
 

Right.


But we have an FAQ which points to better places, and even to 
some specifications.  So we're not all bad  :-}
 

Re: How do I print http 404 not found header?

Postby Alan J. Flavell » Wed, 20 Oct 2004 07:52:13 GMT




RFC2616 is *not* a CGI specification.


Re: How do I print http 404 not found header?

Postby Abigail » Wed, 20 Oct 2004 09:41:59 GMT

nntp ( XXXX@XXXXX.COM ) wrote on MMMMLXVI September MCMXCIII in


{}  print "HTTP/1.1 404 Not Found";
{}  do I need
{}  print "Content-type: text/html\n\n"; after it?
{}  
{}  Should I print
{}  print "HTTP/1.1 404 Not Found";
{}  print "locatioin: ...";


Do you actually have a Perl question?


Abigail
-- 
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
           ${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'

Re: How do I print http 404 not found header?

Postby Jgen Exner » Wed, 20 Oct 2004 10:26:36 GMT



No, print() statements in Perl are independent of each other. The first text 
will print just fine without the second print() command.
Is there actually any programming language where you would have to issue a 
second print command for the first one to print?

Now, if you _want_ to print the second line for your particular application 
or not, that is a totally different questions and you should ask in a NG 
that actually deals with your kind of application.

jue



Re: How do I print http 404 not found header?

Postby Jgen Exner » Wed, 20 Oct 2004 10:28:42 GMT



[...]

He did. He wanted to know if in Perl you can use a single print() statement 
or if they must come in pairs. Or something like that....

jue 



Re: How do I print http 404 not found header?

Postby lesley_b_linux » Wed, 20 Oct 2004 17:02:53 GMT

"Alan J. Flavell" < XXXX@XXXXX.COM > writes:





Correct, 10 out 10, go to the top of the class :)

It does however happen to specify HTTP responses in Section 6 

However if you want a CGI specification the nearest I can offer was a URL
posted in another thread -->  http://www.**--****.com/ 

HTH

Lesley


Re: How do I print http 404 not found header?

Postby Alan J. Flavell » Wed, 20 Oct 2004 18:59:28 GMT





-?


That's not surprising, since it's the HTTP/1.1 specification.

As the relevant Perl FAQ says, at e.g
 http://www.**--****.com/ #What-is-the-correct-form-of-response-from-a-CGI-script-

 The similarity between CGI response headers (defined in the CGI 
 specification) and HTTP response headers (defined in the HTTP 
 specification, RFC2616) is intentional, but can sometimes be 
 confusing.


Actually, I prefer the one referenced in the Perl FAQ part 9:

 Current best-practice RFC draft at:  http://www.**--****.com/ 

although it never does seem to have quite made it to the 
originally-mooted RFC status.  Maybe the IETF don't really consider 
the CGI interface to be in their parish, but Ken did an excellent 
piece of work in collating a best-practice specification, and it seems 
to me that it's the best that we've got (the NCSA spec is rather 
informal, and leaves many questions unanswered).


U2.  :-}


Re: How do I print http 404 not found header?

Postby Greg Schmidt » Thu, 21 Oct 2004 03:32:48 GMT






Hmm, maybe buffering issues due to the first text not ending with a
newline?

-- 
Greg Schmidt   XXXX@XXXXX.COM 
  Trawna Publications   http://www.**--****.com/ 

Similar Threads:

1.404 not found message in simple script

#!/usr/bin/perl
#Open up subdirectory, and read in contents one line at a time
open(FORM,'subdirectory.txt') || die "cannot open subdirectory for reading:
$!";
	while (<FORM>) {
	if (/form3/) {
	print "the line is :" . $_;
close (FORM);
exit;
}
}

I get an error message every time saying 404 not found.  The file is a simple
text file sitting in my cgi-bin.  I'm searching for form3 in each line of the
file.  Am I missing something here?  


2.LWP::UserAgent and 404 page not found

3.WWW::Search::Google-->Service description 'file:' can't be loaded: 404 File `' does not exist

4.CGI.PM not setting HTTP header

My Perl CGI script is producing valid HTML (as far as I can tell,)
but the server is returning a MIME type of 'text/plain'. I have tried
using the CGI.PM module to set the MIME type in the header,
but this merely adds a _second_ header to the output stream,
and this second header ends up displaying as text in the browser
window! The actual HTTp header is unaffected, still returning the
'text/plain' MIME type.

Any suggestions?

Thanks
-Mark


5.IE Browser not setting Http-Referer header properly

6. ENV variables and custom 404 error page

7. Sending back 404 error

8. Headers not Printing properly



Return to PERL

 

Who is online

Users browsing this forum: No registered users and 3 guest