0

I am using mobiledetect for redirect mobile users to a specific page. But, when I'm writing this then I am getting the Fatal error for redirect(). Can anyone please let me know where and what I'm missing?

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>';
Rob Starling
  • 3,868
  • 3
  • 23
  • 40
Md Mazedul Islam Khan
  • 5,318
  • 4
  • 40
  • 66
  • 5
    `redirect()` is not a function. Error is fairly clear. Where are you creating this function? Do you actually want the [`header()`](http://uk3.php.net/manual/en/function.header.php) function? – naththedeveloper Feb 17 '14 at 08:58
  • See this question for a lot of options: http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php – Rob Starling Feb 17 '14 at 09:00
  • That means it couldn't find a function with a name `redirect` anywhere. Try using `header("Location:iammobile.php")` instead – asprin Feb 17 '14 at 09:00

6 Answers6

6

Try with header like

header("Location: iammobile.php");
die();
GautamD31
  • 28,552
  • 10
  • 64
  • 85
2

Use This function as construct

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

Use this code as redirect

redirect(base_url().'login','refresh');
Suresh
  • 85
  • 1
  • 13
1
 redirect('iammobile.php');

replace it with

  header('location:iammobile.php');
wild
  • 340
  • 1
  • 3
  • 14
0

Rather than redirect you should use the header function:

<?php
    header("Location: iammobile.php");
?>
James
  • 5,137
  • 5
  • 40
  • 80
0

You need add $autoload['helper'] = array('url', 'form'); in file autoload.php

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
0

Add construct function in your constructor then your redirect function will work.

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