我需要修改我的Bluehost php.ini文件吗?标头功能在远程服务器上不起作用 [英] Do I need to modify my Bluehost php.ini file? Header function not working on remote server
问题描述
下面显示的使用php标头重定向的这段代码在本地有效,但不适用于我的Bluehost服务器:
This block of code shown below using a php header redirect works locally, but not on my Bluehost server:
if ($_POST['submit']=='No')
{
$url ='Location: index.php?id='.$id.'&page='.$page;
header($url);
exit;
}
当服务器访问此代码块时,绝对不会发生任何事情。没有错误,没有警告,只是一个空白页。我的表单提交重定向到的页面除了将用户重新定向到相关页面外,不应执行任何操作。
When the server gets to this block of code, absolutely nothing happens. No error, no warning, just a blank page. The page that my form submit redirects to isn't supposed to do anything except reroute the user to the relevant page.
我很坦率地说,它与重定向之前包含HTML的常见问题无关(因为它在本地有效)。因此,我怀疑这与我的php.ini文件之间的差异有关。我为两台服务器都安装了PHPinfo(),本地服务器上有一个名为mod_headers的模块,而Bluehost服务器上没有。我认为这可能是问题所在,尽管通常情况下,我的Bluehost使用标头重定向没有问题,但在这种情况下除外。
I'm pretty dang positive it has nothing to do with the common problem of including HTML before the redirect (since it works locally). Therefore I suspect it has something to do with differences between my php.ini files. I've pulled up PHPinfo() for both servers, and my local server has a module named mod_headers while my Bluehost server has none. I think this potentially could be the problem, although normally my Bluehost has no problems using header redirects, except in this one instance.
因此,我怀疑问题有待解决
So I suspect the problem has something to do with my ini file, but I don't know exactly what.
使这个问题更奇怪的是,例如,还有其他代码块也可以正常工作
What makes this problem even stranger is that there are other blocks of code which work just fine, for instance
if(!empty($_POST['id']))
{
$id = htmlentities(strip_tags($_POST['id']));
$sql = "UPDATE entries SET title=?, entry=? WHERE id=? LIMIT 1";
$stmt = $db->prepare($sql);
$stmt->execute(array($title,$entry,$id));
$stmt->closeCursor();
$url= 'Location: ../index.php?id='.$id.'&page='.$page;
header($url);
exit;
}
效果很好。
推荐答案
我遇到了同样的问题,即它在XAMPP上可以正常运行,但在bluehost或1& 1上却不能。
I had the same problem that it works fine on XAMPP but not on bluehost or 1&1.
PHP文档说在调用标头函数之前应该没有输出。
http://php.net/manual/zh-CN/function.header.php
就我而言,在开头之前有一个空格<使标题功能无法使用的PHP。
In my case there was a space before the opening <?PHP which made the header function not work.
这应该有助于解决问题。
This should help to solve the problem.
问题仍然存在:为什么它可以在XAMPP和不是在bluehost,1& 1等的服务器上?
(因为我在两个测试中都使用了Firefox-绝对不是浏览器问题)
The quesiton remains though: why does it work on XAMPP and not on the servers of bluehost, 1&1, etc? (since I use firefox for both tests - it is definitely not a browser issue)
这篇关于我需要修改我的Bluehost php.ini文件吗?标头功能在远程服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!