【问题标题】:fatal error: call to undefined function redirect()致命错误:调用未定义的函数重定向()
【发布时间】:2014-02-17 08:58:18
【问题描述】:

我正在使用mobiledetect 将移动用户重定向到特定页面。但是,当我写这篇文章时,我收到了redirect() 的致命错误。谁能让我知道我在哪里以及缺少什么?

require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $detect->getScriptVersion();

if ($detect->isMobile())
   redirect('iammobile.php');
else
   echo '<h1>I am Desktop</h1>';

【问题讨论】:

  • redirect() 不是函数。错误相当明显。你在哪里创建这个功能?你真的想要header() 函数吗?
  • 看到这个问题有很多选择:stackoverflow.com/questions/768431/…
  • 这意味着它无法在任何地方找到名称为 redirect 的函数。尝试改用header("Location:iammobile.php")

标签: php redirect


【解决方案1】:

试试header 喜欢

header("Location: iammobile.php");
die();

【讨论】:

  • 嗨,当我这样使用时:if ($detect-&gt;isMobile())header("Location: iammobile.php"); 然后它显示内部服务器错误
  • 您需要提供该文件的整个 url..同时重定向
  • 你的意思是这样的:home/user/public_html/?
  • 还是不行。我也试过/home3/chew/public_html/fundmanagementsystem.com/demo/mobile/mobile.phphttp://google.com
  • 检查您的服务器日志,看看为什么它显示内部服务器错误
【解决方案2】:
 redirect('iammobile.php');

替换为

  header('location:iammobile.php');

【讨论】:

  • 嗨,当我这样使用时:if ($detect-&gt;isMobile())header("Location: iammobile.php"); 然后它显示内部服务器错误
  • 您是否在iammobile.php 上检查此条件,如果是,它将在循环中重定向。
【解决方案3】:

将此函数用作构造

public function __construct() {
    parent::__construct();
    $this->load->helper('form');
    $this->load->helper('url');
}

将此代码用作重定向

redirect(base_url().'login','refresh');

【讨论】:

    【解决方案4】:

    你应该使用header函数而不是重定向:

    <?php
        header("Location: iammobile.php");
    ?>
    

    【讨论】:

      【解决方案5】:

      您需要在文件 autoload.php 中添加$autoload['helper'] = array('url', 'form');

      【讨论】:

        【解决方案6】:

        在您的构造函数中添加构造函数,然后您的重定向函数将起作用。

        function __construct(){ parent::__construct(); }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-12-01
          • 2014-03-21
          • 2013-02-17
          相关资源
          最近更新 更多