zxcv Posted December 30, 2006 Share Posted December 30, 2006 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<?phpheader("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 More sharing options...
btherl Posted December 30, 2006 Share Posted December 30, 2006 Why is the newline required? The simplest way to fix this is to remove the newline. Link to comment https://forums.phpfreaks.com/topic/32249-using-header-with-cgi/#findComment-149739 Share on other sites More sharing options...
zxcv Posted December 30, 2006 Author Share Posted December 30, 2006 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 More sharing options...
mainewoods Posted December 30, 2006 Share Posted December 30, 2006 there is a line in php.ini that should be set this way for the redirect:[code]cgi.force_redirect=0[/code] Link to comment https://forums.phpfreaks.com/topic/32249-using-header-with-cgi/#findComment-149899 Share on other sites More sharing options...
zxcv Posted December 31, 2006 Author Share Posted December 31, 2006 [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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.