PHP,标题(重定向)无法在活动服务器上工作 [英] PHP, header(redirect) not working on live server

查看:104
本文介绍了PHP,标题(重定向)无法在活动服务器上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码

  if(isset($ _GET ['elimina_id'])){
if (in_array($ _ GET ['elimina_id'],$ _SESSION ['cart'])){
$ index =(array_keys($ _ SESSION ['cart'],$ _GET ['elimina_id']));
$ i = $ index [0];
unset($ _ SESSION ['cart'] [$ i]);
header('location:cart.php');
}
}

基本上,我想删除购物车中的物品。问题是,在测试页上,localhost,一切正常,但在实时服务器上,我遇到了 header()的问题。如果我把 header()这个项目不会被删除,页面只会在没有任何操作的情况下重新加载。如果我没有放置标题(),在点击删除项目链接后,没有任何反应,但是如果我手动重新加载它的工作页面,删除。
在本地主机上我没有这个问题,它可能是什么? PHP版本是好的,它可以在.ini文件中进行一些设置吗?
希望您能帮助我,谢谢 为什么不使用元重定向标记或javascript解决方案? / b>

HTML:
< meta http-equiv =refreshcontent =0; url = http://www.site.com/cart.php>



JavaScript#1:
< script> window.location =http://www.site.com/cart.php;< / script>



JavaScript#2: < script> window.navigate(http://www.site.com/cart.php );< / script>


I have this code

if(isset($_GET['elimina_id'])){
    if (in_array($_GET['elimina_id'], $_SESSION['cart']) ) {
        $index = (array_keys($_SESSION['cart'], $_GET['elimina_id']));
        $i = $index[0];
        unset($_SESSION['cart'][$i]);
        header('location: cart.php');
    }
 }

Basically, I want to delete a item in the cart. The thing is, on the test page, localhost, everything works, but on live server I have problems with header(). If I put header() the item won't be deleted, the page only reloads without any action taken effect. If I don't put the header(), after I click the 'Delete item' link, nothing happens, but then if I manually reload the page it works, the item deletes. On localhost I don't have this problem, what could it be? The php version is OK, could it be some settings in the .ini file ? Hope you can help me, Thanks

解决方案

Why not use a meta redirect tag, or a javascript solution?

HTML: <meta http-equiv="refresh" content="0;url=http://www.site.com/cart.php">

JavaScript #1: <script>window.location = "http://www.site.com/cart.php";</script>

JavaScript #2: <script>window.navigate("http://www.site.com/cart.php");</script>

这篇关于PHP,标题(重定向)无法在活动服务器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆