简体   繁体   English

php redirect()在联机服务器上不起作用

[英]php redirect() not working on online server

I had redirected my page like: 我已经重定向了我的页面,例如:

redirect(base_url().'user/login/?redirect=site/cart_steps/steps');

and it works fine in localhost and when i uploaded it to server it didnt redirect. 并且它在localhost中工作正常,当我将其上传到服务器时,它没有重定向。 I checked all the codes and above this all code executes. 我检查了所有代码,并在此之上执行了所有代码。 But when it comes to redirect the page doesnt redirects. 但是,当涉及到重定向时,页面不会重定向。 I also tried 我也试过

redirect(base_url().'user/login?redirect=site/cart_steps/steps');
redirect(base_url().'user/login');
header('Location:'.base_url().'user/login?redirect=site/cart_steps/steps');
header('Location:'.base_url().'user/login');

but the page didn't redirect? 但是页面没有重定向? and also i checked out this The header function is not working on online server? 而且我也签出了此标头功能不能在在线服务器上工作吗? but it cant help me too.... can any one explain what is the problem here.... 但这也帮不了我....任何人都可以在这里解释问题是什么....

You can use the refresh method like this: 您可以使用以下刷新方法:

    <?php
        redirect($this->input->server('HTTP_REFERER'), 'refresh'); // refresh the page
    ?>

Another common mistake could be echoing out / printing something before the redirection. 另一个常见的错误可能是在重定向之前回显/打印某些内容。

I would check your CodeIgniter error logs to verify that particular file isn't throwing any error messages that could tell you what needs fixing. 我将检查您的CodeIgniter错误日志以验证特定文件没有引发任何错误消息,这些错误消息可以告诉您需要修复的内容。

If you haven't already, you'll probably also want to make sure that the URL helper is loaded. 如果还没有,您可能还需要确保URL助手已加载。 ex: 例如:

$this->load->helper('url');

另一种解决方案

<meta http-equiv="refresh" url=http://example.com/"> 

Try to use like this, 尝试像这样使用

First define your base URL as : 首先将您的基本网址定义为:

$base_url = "Your base url";

then apply this $base_url variable to your redirect link. 然后将此$ base_url变量应用于您的重定向链接。

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM