Modify HTTP-Header in PHP running as CGI
Moderator: General Moderators
Modify HTTP-Header in PHP running as CGI
Is it possible to use the header-Function to modify the HTTP-header with PHP running as CGI?
So far I think it fails for me because my apache-webserver runs PHP as CGI and I have to use #!/usr/bin/php in the first line. And so (i think) the header-modification will not work because there is already a output to the file.
Any idears on this?
thx
So far I think it fails for me because my apache-webserver runs PHP as CGI and I have to use #!/usr/bin/php in the first line. And so (i think) the header-modification will not work because there is already a output to the file.
Any idears on this?
thx
Code: Select all
#!/usr/bin/php
<?php ob_start();
header("Content-type: text/html");
header("Location: http://server/goto.php");
?>What is the "shebang"?
oh, sorry the output is here: http://www.tfh-berlin.de/~s19436/cgi-bin/loc.php
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
#! = shebang or sharp bang.
headers:
content:
headers:
Code: Select all
HTTP/1.1 302 Found
Date: Fri, 10 Sep 2004 20:12:23 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.2 mod_perl/1.26
Location: https://cgi.tfh-berlin.de/~s19436/loc.php
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1Code: Select all
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>302 Found</TITLE>
</HEAD><BODY>
<H1>Found</H1>
The document has moved <A HREF="https://cgi.tfh-berlin.de/~s19436/loc.php">here</A>.<P>
<HR>
<ADDRESS>Apache/1.3.27 Server at www.tfh-berlin.de Port 80</ADDRESS>
</BODY></HTML>Okay. but this is only the Apache-Redirection to "https://cgi.tfh-berlin.de/~s19436/loc.php"...
and there:
headers:
content:
and there:
headers:
Code: Select all
Date: Fri, 10 Sep 2004 20:22:06 GMT
Server: Apache/1.3.26 (Linux/SuSE) mod_perl/1.27 mod_ssl/2.8.10 OpenSSL/0.9.6g
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/htmlCode: Select all
Content-type: text/html Location: http://server/goto.phpHeaders ideally should be sent prior to any other output to the buffer (although I believe you can get round this using ob_start).
The shebang line is an instruction to the server in order to locate the appropriate interpreter for the script, and as a result is not included (or classed) as output to the buffer therefore you should have no problems (I know I don't) modifying the headers when running the CGI version of PHP.
It is worth noting, if no headers are set in the script then the defaults are applied which in the case of CGI-PHP is text/html. So line 3 of script does not really show if the headers have been succesfully changed. Perhaps try changing the 'Content-type' to 'text/plain' (or is it 'plain/text' can quite remember at the moment) to ascertain of you can modify the headers.
The shebang line is an instruction to the server in order to locate the appropriate interpreter for the script, and as a result is not included (or classed) as output to the buffer therefore you should have no problems (I know I don't) modifying the headers when running the CGI version of PHP.
It is worth noting, if no headers are set in the script then the defaults are applied which in the case of CGI-PHP is text/html. So line 3 of script does not really show if the headers have been succesfully changed. Perhaps try changing the 'Content-type' to 'text/plain' (or is it 'plain/text' can quite remember at the moment) to ascertain of you can modify the headers.