开发者

PHP Mobile Detect Script Not Redirecting, Sends Blank Page

开发者 https://www.devze.com 2023-03-25 06:37 出处:网络
I am attempting (given my very limited knowledge of PHP) to use the mobile device detection script 开发者_运维百科from http://detectmobilebrowsers.mobi to redirect mobile users to a mobile-specific si

I am attempting (given my very limited knowledge of PHP) to use the mobile device detection script 开发者_运维百科from http://detectmobilebrowsers.mobi to redirect mobile users to a mobile-specific site. The PC version of the site lives [here] while the mobile site lives with the /mobile/ folder [here].

I've ensured that there is nothing before the php redirect call. Testing on a mobile device, the redirect simply goes to a blank page while the PC version goes to the full site as it should.

I have mobilecheck1.php at the top of the page calling the following:

<?php
require_once('mobile_device_detect.php');
mobile_device_detect(true,false,true,true,true,true,true,'http://www.epworthindy.org/mobile/index.php',false);
?>

I've used this very same script before in an almost identical configuration and it has worked, but not here. I would really appreciate any help/guidance through this problem. Thanks!


I took a look at the script and looks like in your use case, it will simply return when it does not detect a mobile browser.

Which mobile device are you using? Maybe you're using one that is not known by the script. Note also that you're not treating the iPad as mobile, so using an iPad will trigger the problem.


Here's what I would try ...

  1. Install this on Firefox: https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher/
  2. Download and install the free trial of Charles here: https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher/
  3. Run Charles and let it record (it probably will by default, but if not, it's the red and white button in the toolbar); change your user-agent in Firefox to the iPhone (if you are on a recent version of FF you may need to click on the Firefox menu, go to Options and select Menu Bar; the user agent switcher will be under the tools menu and will say "Default User Agent" - go to that menu and select iPhone)
  4. Request the page; then stop Charles from recording.
  5. In the left-hand pane, expand http://epworthindy.org and select the page you tried to load; then click on the response tab and then select the raw tab at the bottom, and you'll be able to see exactly what the server sent back.

Once you've done that you should be able to see the server sending the redirect at the top; feel free to copy and paste the results and I can take a look as well.


Thanks to Doug, I was able to determine I had saved the php files as utf-8 to include the BOM unicode signature which was producing the following characters at the beginning of the files: Ôªø

I simply resaved without the unicode signature and it works as expected. Thanks for pointing me in the right direction!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号