2014-02-17 160 views
0

我使用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>'; 
+5

添加$autoload['helper'] = array('url', 'form');'重定向()'是不是一個函數。錯誤相當清楚。你在哪裏創建這個功能?你真的想要[[header()'](http://uk3.php.net/manual/en/function.header.php)函數嗎? – naththedeveloper

+0

見很多的選擇這個問題:http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php –

+0

這意味着它無法找到一個名稱的函數'重定向'隨時隨地。嘗試使用'header(「Location:iammobile.php」)'代替 – asprin

回答

6

header

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

嗨, 當我這樣使用時: 'if($ detect-> isMobile())' 'header(「Location:iammobile.php」 );' 話,就說明內部服務器錯誤 –

+0

你需要給該file..while重定向 – Gautam3164

+0

你是指像這樣整個網址:'家用/用戶/的public_html /'? –

0

而不是重定向你應該使用header功能嘗試:

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

header('location:iammobile.php'); 
更換
+0

嗨, 當我用這樣的: '如果($ detect-> isMobile())'' 標題( 「位置:iammobile.php」);' 話,就說明內部服務器錯誤 –

+0

你如果是的話,在'iammobile.php'上檢查這個條件,它會在循環中重定向。 – wild

1

使用此功能爲構建

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

使用此代碼作爲重定向

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

您需要的文件autoload.php