0

This is the code:

<html>
<body>
<?php
$iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");

if($iPhone || $iPad || $iPod)   {
header( 'Location: http://example.com' );
}
else if($Android)   {
header( 'Location: http://example.com' );
}
else    {
echo "<p>Error</p>";
}
?>
</body>
</html>

I'm always getting this:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web7_57/html/test2.php:24) in /var/www/web7_57/html/test2.php on line 31

Does anybody know what I can do?

  • Already found this myself but didn't help. –  Aug 28 '16 at 20:05
  • 1
    You don't have 31 lines of code posted and we don't know if there's anything above it. Plus, you are outputting before header here. – Funk Forty Niner Aug 28 '16 at 20:10
  • 1
    Post whole file next time, but the solutions is as stated in the other question, you have to move your header() function call before ANY characters are outputted, this includes , or even a space before opening php tag, in order for it to work. – Jozef Spisiak Aug 28 '16 at 20:21
  • I solved the problem by adding no code before ` –  Aug 29 '16 at 17:46

0 Answers0