timothyarden Posted February 9, 2013 Share Posted February 9, 2013 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 More sharing options...
Jessica Posted February 9, 2013 Share Posted February 9, 2013 Did you read the sticky on this topic? You appear to have whitespace at the beginning of the file. Link to comment https://forums.phpfreaks.com/topic/274272-warning-cannot-modify-headers-error/#findComment-1411390 Share on other sites More sharing options...
timothyarden Posted February 9, 2013 Author Share Posted February 9, 2013 No, Could you please send a link to the sticky, when I searched this site before with the error it returned nothing. Thanks for the fast response Link to comment https://forums.phpfreaks.com/topic/274272-warning-cannot-modify-headers-error/#findComment-1411392 Share on other sites More sharing options...
trq Posted February 9, 2013 Share Posted February 9, 2013 The sticky as at the top of this very board. It's pretty hard to miss. Link to comment https://forums.phpfreaks.com/topic/274272-warning-cannot-modify-headers-error/#findComment-1411393 Share on other sites More sharing options...
timothyarden Posted February 9, 2013 Author Share Posted February 9, 2013 I read that before but it doesn't have anything about whitespace so I thought I must have read the wrong thing. Okay, thanks. Ill try without white space and see how I go. Link to comment https://forums.phpfreaks.com/topic/274272-warning-cannot-modify-headers-error/#findComment-1411394 Share on other sites More sharing options...
timothyarden Posted February 9, 2013 Author Share Posted February 9, 2013 Thanks for the help again Jessica and trq. Right again as always Link to comment https://forums.phpfreaks.com/topic/274272-warning-cannot-modify-headers-error/#findComment-1411397 Share on other sites More sharing options...
timothyarden Posted February 9, 2013 Author Share Posted February 9, 2013 Oh, 2 quick questions - is a comment counted as whitespace? And does session need to come before header() or the opposite way round? (or doesn't it matter) Link to comment https://forums.phpfreaks.com/topic/274272-warning-cannot-modify-headers-error/#findComment-1411399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.