Jump to content

Using header() with CGI


zxcv

Recommended Posts

Hello,

I created this topic in the afternoon, but for some reason, it disappeared.  Here it is again.
I'm able to use header() for redirection with a regular PHP script.  In order to interact with a database, I need to use PHP as CGI, but header() does not work with PHP as CGI.  Here's some code:
[code]
#!/usr/pkg/bin/php

<?php
header("Location: http://www.yahoo.com/");

?>
[/code]
Nothing is outputted.  The newline after the shebang is required, and I thought that would cause problems, so I put calls to ob_start() and ob_end_clean() before header(), but I get the same results.  Any ideas?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/32249-using-header-with-cgi/
Share on other sites

I don't know why but it's required.  My scripts used to not have a newline after the shebang, but when the sysadmin installed a new version of PHP, the CGI scripts stopped working; I would get error 500, internal service error.  He said to add a newline to prevent this from happening, but now I noticed that CGI stopped working with header(); this used to work before.
The server is running PHP 5.1.2 and Apache 2.0.59.
Link to comment
https://forums.phpfreaks.com/topic/32249-using-header-with-cgi/#findComment-149841
Share on other sites

[code]
; cgi.force_redirect is necessary to provide security running PHP as a CGI under
; most web servers.  Left undefined, PHP turns this on by default.  You can
; turn it off here AT YOUR OWN RISK
; **You CAN safely turn this off for IIS, in fact, you MUST.**
; cgi.force_redirect = 1
[/code]
The sysadmin is overly concerned about security, so I don't know how he will react to this.  I'll ask him.
Thanks.
Link to comment
https://forums.phpfreaks.com/topic/32249-using-header-with-cgi/#findComment-150207
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.