IanS Posted June 26, 2013 Share Posted June 26, 2013 Total php noob.Have a simple php useragent sniffer needed to redirect mobile users, etc...Where is best to place the script within the main HTML index file? Top of page? Before head, after it, in the body? Do bots read this script or ignore it? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 26, 2013 Share Posted June 26, 2013 If you're redirecting then you should put that code before any HTML code or any other output. Browsers and other user agents like bots do not see PHP code, they see the result of it. Link to comment Share on other sites More sharing options...
IanS Posted June 27, 2013 Author Share Posted June 27, 2013 Hmm, that's where I put it, just under the doctype. Is there some reason why something simple like this would not work? -- <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/iPhone|Android|Blackberry/i', $agent)){ header("Location: mobile.html"); exit; } ?> Bearing in mind I have no idea what I'm doing with PHP code! (There is a more complicated version of this, but even this cut-down one isn't working.) Could use JavaScript, but I'd prefer this to work. many thanks. btw, php does run on my server. I have forums working just fine. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 27, 2013 Share Posted June 27, 2013 It doesn't work because you put it after the doctype. It goes before anything else in the file. If you're redirecting then you can't send any output. Output is anything outside of the PHP tags, including blank spaces or the doctype. Link to comment Share on other sites More sharing options...
IanS Posted June 27, 2013 Author Share Posted June 27, 2013 Right! Which is what you said... Done. Thanks! Link to comment Share on other sites More sharing options...
IanS Posted June 29, 2013 Author Share Posted June 29, 2013 Turns out this code didn't work after all. Beats me why. I'll have to use javascript... (But then the viewport meta isn't working on iPhone either. Not having much luck with this mobile site all round!) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now