jbwebdesign Posted August 20, 2012 Report Share Posted August 20, 2012 Hello, i am trying to understand why this is happening to me..... can someone please explain why when i use a boolean inside of a function, it echo's out the number 1 instead of returning it? I am doing this on a Wordpress website inside of the index.php file at the first line. when it redirects the user, the number 1 appears at the very top of the page. here is my code for trying to use it: <?php if($tm->mobile_check()){ header("Location: http://m.mywebsite.com/"); } ?> here is my code for the function: <?php function mobile_check() /* THIS FUNCTION IS FOR MOBILE WEBSITE USE */ { $iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod"); $iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone"); $iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad"); $Android= stripos($_SERVER['HTTP_USER_AGENT'],"android"); $webOS= stripos($_SERVER['HTTP_USER_AGENT'],"webOS"); $mobile = FALSE; switch($mobile) { case $iPod: case $iPhone: case $iPad: case $Android: case $webOS: $mobile = TRUE; break; } } ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 20, 2012 Report Share Posted August 20, 2012 Are you absolutely sure that it is this code that is causing the issue, and not something else? When testing this outside of Wordpress, I don't get any "1"s. That said, two points: -- Don't you need to "return $mobile;" at the end of your function? -- I'm pretty sure that you are using "switch" incorrectly, and it won't have the results you are expecting: http://php.net/manual/en/control-structures.switch.php. You're currently saying if $mobile (set to false) == $ipad (set to false) then turn $mobile to true. Seems like a logic error there. Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted August 20, 2012 Author Report Share Posted August 20, 2012 i have no idea what the problem was..... but i found a way around it. by the way, i think the switch case statement is working correctly. i am trying to say that if the $_SERVER['HTTP_USER_AGENT'] contains any of the following: ipad, iphone, android, ipod, webos then return is mobile. so that i can re-direct the user to a mobile compatible website. Thanks for your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.