adho12 Posted July 30, 2013 Posted July 30, 2013 HiI'm new to html and PHP and ended up coming to a point where I have no more knowledge and the Internet solutions don't work... So I’m trying to do a simple PHP-redirect after a mobile detection: <?php // Include the mobile device detect class require_once 'Mobile_Detect.php'; // Init the class $detect = new Mobile_Detect; // checking if the user comes with a mobile device if ($detect->isMobile()) { // Detects any mobile device. // Redirecting header("Location: http://www.ahornung.heliohost.org/mob");} else {header("Location: http://www.ahornung.heliohost.org/pc");} ?> Well on my PC, it’s a XAMPP-Server, I get my redirect but on the online-Server (Helios) I get this back:Warning: Cannot modify header information - headers already sent by So I hope someone could help me.Thanks for your help adho12 p.s. Sorry for my English 1
Byron Posted July 30, 2013 Posted July 30, 2013 Is there any html before your php redirect code? There can't be any content sent before the header redirect.
adho12 Posted July 30, 2013 Author Posted July 30, 2013 <html> <head> </head> <body> <?php // Include the mobile device detect class require_once 'Mobile_Detect.php'; // Init the class $detect = new Mobile_Detect; // And here is the magic - checking if the user comes with a mobile device if ($detect->isMobile()) { // Detects any mobile device. // Redirecting header("Location: http://www.ahornung.heliohost.org/mob");} else {header("Location: http://www.ahornung.heliohost.org/pc");} ?> WEITERLEITUNG FOLGT! </body> </html> This is the rest of the Code, so No html...
Byron Posted July 30, 2013 Posted July 30, 2013 Remove this before your script: <html><head></head><body>
adho12 Posted July 30, 2013 Author Posted July 30, 2013 ahhhhh It works THANKS ^^(but<html><head></head><body>is this also HTML?)
Byron Posted July 30, 2013 Posted July 30, 2013 Yes that's html. You can have html in your script but you can't have it before the header redirect.
adho12 Posted July 30, 2013 Author Posted July 30, 2013 I see...why not?(sorry for my stupid Questions)
Byron Posted July 30, 2013 Posted July 30, 2013 I really don't know. It's just how the php is written. Google is your friend!
Recommended Posts