Possible Duplicate:
Headers already sent by PHP
I have inherited a website that has a mobile detect php script running that should redirect the user to a subdomain if the user is accessing the website via a mobile device.
The website works fine on my desktop, but on my iphone I get the following:
"Warning: Cannot modify header information - headers already sent by (output started at /home/autolox/public_html/index.php:1) in /home/autolox/public_html/common.php on line 16
Warning: Cannot modify header information - headers already sent by (output started at /home/autolox/public_html/index.php:1) in /home/autolox/public_html/common.php on line 17"
I'm not exactly experienced with PHP, so I've no idea what this means, but here is my common.php file in full:
require_once(realpath(implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'MobileDetect.php'))));
$MobileDetect = new MobileDetect();
if($MobileDetect->IsMobile()){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://mobi.autolox.co.uk/");
exit();
}
and this is the top of my index file:
Would love some help on this, I'm stumped!
EDIT:
There is also a mobile detect php file running, see below:
/**
* Detect mobile devices
* @idilico
* @version 2.7.0
* @copyright Copyright (c) 2010-2011 Idilico (http://www.idilico.com)
*/
class MobileDetect {
// Device constants
const DEVICE_ANDROID = "android";
const DEVICE_BLACKBERRY = "blackberry";
const DEVICE_IPHONE = "iphone";
const DEVICE_IPHONE4 = "iphone4";
const DEVICE_OPERA = "opera";
const DEVICE_PALM = "palm";
const DEVICE_WINDOWS = "windows";
const DEVICE_GENERIC = "generic";
const DEVICE_IPAD = "ipad";
const DEVICE_NORMAL = "normal";
/**
* Hold the device useragent
*
* @var string
*/
private $_useragent;
/**
* Boolean that is set to true if
* the current device is mobile
*
* @var bool
*/
private $_isMobile = false;
/**
* Device booleans that get set when
* the devices matche
*
* @var bool
*/
private $_isAndroid = null;
private $_isBlackberry = null;
private $_isIphone = null;
private $_isIphone4 = null;
private $_isOpera = null;
private $_isPalm = null;
private $_isWindows = null;
private $_isGeneric = null;
private $_isIpad = null;
/**
* Regular expressions for the different devices
*
* @var array
*/
private $_devices = array(
"android" => "android",
"blackberry" => "blackberry",
"ipad" => "ipad",
"iphone4" => "(8A293|4_3)",
"iphone" => "(iphone|ipod)",
"opera" => "(opera mini|opera mobi)",
"palm" => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino|webos)",
"windows" => "(iemobile|smartphone|windows phone|htc_hd2)",
"generic" => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap|u970)"
);
/**
* Constructor
*
* @access public
* @return void
*/
public function __construct() {
$this->_useragent = $_SERVER['HTTP_USER_AGENT'];
foreach ($this->_devices as $device => $regexp) {
if ($this->IsDevice($device) && $this->_isMobile == FALSE) {
$this->_isMobile = true;
}
}
}
/**
* Check if surfing with a particular device
*
* @access private
* @param string $device
* @return bool
*/
private function IsDevice($device) {
$var = "_is" . ucfirst($device);
$this->$var = @$this->$var === null ? (bool) preg_match("/" . $this->_devices[strtolower($device)] . "/i", $this->_useragent) : $this->$var;
if ($device != 'generic' && $this->$var == true) {
$this->_isGeneric = false;
}
return $this->$var;
}
/**
* Get the device type
*
* @param public
* @return string
*/
public function GetDevice(){
foreach($this->_devices as $device_string => $regex){
if( $this->IsDevice($device_string) ){
return $device_string;
}
}
return self::DEVICE_NORMAL;
}
/**
* Call methods like this IsMobile() | IsAndroid() | IsIphone() | IsBlackberry() | IsOpera() | IsPalm() | IsWindows() | IsGeneric() | IsIpad() through IsDevice()
*
* @access public
* @param string $name
* @param array $arguments
* @return bool
*/
public function __call($name, $arguments) {
$device = substr($name, 2);
if ($name == "Is" . ucfirst($device)) {
return $this->IsDevice($device);
} else {
trigger_error("Method $name is not defined", E_USER_ERROR);
}
}
/**
* Returns true if surfing on a mobile device
*
* @access public
* @return bool
*/
public function IsMobile() {
return $this->_isMobile;
}
}
No comments:
Post a Comment