Jump to content
Killersites Forums

Help Using BOOLEAN


Recommended Posts

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;	
	}

}

?>

Link to post
Share on other sites

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.

Link to post
Share on other sites

i have no idea what the problem was.....

 

but i found a way around it. :clap:

 

 

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 :)

Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...