Skip outputting the main HTML if redirected

On the main index.php file, I'm redirecting the user if he is using a mobile phone. But after sending the Location header, the rest of the HTML would also be sent to the user, unnecessarily. Is there a way to prevent that and skip sending the normal HTML?

The code looks like this:

<?php

if(preg_match(...)){
  header('Location: http://m.mysite.com/');
}

?>

<html>
...normal version of the website...
</html>

Answers


Always exit; after a header( 'Location' ), so the action doesn't continue. That should solve your issue.


Need Your Help

Xamarin build action warning XA0101

c# android xamarin xamarin.android warnings

I'm getting following warning while building the Xamarin Android project.

Rounding floating variables in C to display upto only 2 digits of precision

c floating-point-precision

I have a question - it may seem stupid to most, but i'm still a novice coder.