Html generated by a CGI page counter script displayed in browser without being parsed
I tried to write a CGI script for a page counter. The script produces correct HTML when I execute it at the shell but the HTML does not get parsed by the browser, it is displayed instead. HTML is parsed by the browser for other scripts (none of them use files).
Code:
#!/usr/bin/perl -wT |
You probably need to set the ContentType header.
Your problem is probably that the ContentType header of the response from Apache contains "text/plain" instead of "text/html". The browser uses this header field to determine how the page should be displayed. Set the ContentType to "text/html" in the header before the line 'print header;' in your script and it should fix this issue.
|
Thank you for your response but the content type isn't text/plain. This is the code generated.
Code:
<!DOCTYPE html |
I see the content-type meta header in the HTML, but what about the Content-Type header in the HTTP? It is probably not text/html and that's whats confusing the browser. To find out, telnet to the web server (port 80 by default). E.g., "telnet webserver.hostname 80" (replace webserver.hostname with your web server hostname or IP address). Then enter "GET /path/to/your/page HTTP/1.0" (but replace /path/to/your/page with the URI of the page) and press the enter key twice. The server should respond with the HTTP headers, followed by a blank line, and then the HTML you showed above. What does the Content-Type in the HTTP headers say?
|
This is what I got:
Code:
me@mycomputer:~$ telnet localhost 80 P.S. The other webpages work for some reason. |
Anyone understands why?
|
All times are GMT -5. The time now is 08:49 AM. |