Jump to content

Warning: Cannot Modify Headers Error


timothyarden

Recommended Posts

Hi Everyone am having errors with this:

Warning: Cannot modify header information - headers already sent by (output started at /------/--------/public_html/-------------------------.com/--------------------/classes/mobile.php:15) in /------/--------/public_html/-------------------------.com/--------------------/classes/mobile.php on line 6

 

Here is mobile.php


<?php // line 1
// mobile.php // line 2
class mobile_redirection { // line 3
function __construct($pagename = NULL){ // line 4
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT'])) { // line 5
if(isset($pagename)){ header('Location: http://www.----------------------------.com/mobile/'.$pagename); } else { header('Location: http://www.-------------------------------.com/mobile/'); } // line 6
} else { // line 7
return false; // line 8
} // line 9
} // line 10
} // line 11

?> // line 13

 

I dont understand why there is an error on line fifteen as it doesn't exist and I dont know whats wrong on line 6.

 

When someone goes to my domain it the index file the error comes up but what should happen is if they are a mobile they are redirected to a mobile sub directory or if they aren't a mobile they should be redirected to form.php.

<?php

// Login or Sign Up

 

require('classes/mobile.php');

$mobile = new mobile_redirection('form.php');

 

if($mobile === false){

header('Location: form.php');

}

 

 

?>

 

Any ideas why this isn't happening?

 

Also, it isnt redirecting to form.php yet but if they get there and submit it will be using sessions: is it okay to use headers to redirect from 1.php to 2.php and then on 2.php start_session()?

 

Thanks for reading and for any help in advance,

Timothy

Link to comment
https://forums.phpfreaks.com/topic/274272-warning-cannot-modify-headers-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.