Jump to content


elseif not working


5 replies to this topic

#1 pukirocks

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male

Posted 11 September 2007 - 01:39 AM

hi!! i'm using this redirect script which i think is very popular to redirect my site from between pc and wap, now i want to redirect also depending on browser so i changed $ub="pc" to something else in on the browsers that i want a diferent redirect to $ub="something else" i added a new $htmllink = " http://www.mywebpage.com"; like this $htmllinknew = "http://www.mywebpage.com/index2.php"; and a new if at the end where the redirection takes place like this

if($ub == "PC") {

    header("Location: ".$htmllink);

    exit;

    }
elseif($ub == "something else") {
   
     header("Location: ".$htmllinknew);

    exit;

    }
else

    {

    header("Location: ".$wmllink);

    exit;

    }
it still redirects to wap no problem but not to the browser version any help or pointing me into the right direction?

#2 .CJ

    Young Padawan

  • Members
  • Pip
  • 114 posts
  • Gender:Male
  • Location:Leeds, UK

Posted 11 September 2007 - 12:55 PM

Hmmm, from what it looks like to me, you seem to believe that $ub == "PC" will check if the user is on the PC... if that is the case, you are sadly mistaken, as it doesn't work like that. Take a look here and see if it helps. You need to check for the user agent to see what operating system the user is on, I.E. Windows or Mac... or Linux.

#3 pukirocks

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male

Posted 11 September 2007 - 01:08 PM

hi! i use $ub="PC"; to determine the browser redirect like this
if(stristr($userBrowser, 'Mozilla')) {  $ub="PC";}
i changes it to $ub="something else"; to redirect somewhere else different from $ub="PC"; which is what the elseif does but doesn't. i know PC doesn't mean you're on a pc i wish that was my mistake it seems to easy.thanks!!!i forgot i also use this $userBrowser = $_SERVER['HTTP_USER_AGENT'];

#4 .CJ

    Young Padawan

  • Members
  • Pip
  • 114 posts
  • Gender:Male
  • Location:Leeds, UK

Posted 11 September 2007 - 01:19 PM

Try a switch instead:

switch($ub) {
	case "PC":
		header("Location: ".$htmllink);
	break;
	case "somethingelse":
		header("Location: ".$htmllinknew);
	break;
	default:
		header("Location: ".$wmllink);
	break;
}


#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 11 September 2007 - 01:39 PM

Could you possibly show us the rest of your code? The set up for the if-statements looks fine, but often times this is a logic error. Knowing what everything is set to and how can make a difference.

#6 pukirocks

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male

Posted 11 September 2007 - 04:17 PM

hi! here it goes:
global $userBrowser;
//enter the link you want user to be redirected in case of WML browser

$wmllink = "http://www.mysite.com/wap.php";

//enter the link you want user to be redirected in case of PC browser

$htmllink = "http://www.mysite.com/index.php";
$htmlielink = "http://www.mysite.com/index2.php";

//Detect the browser

$userBrowser = $_SERVER['HTTP_USER_AGENT']; 



//Check for Mozilla

if(stristr($userBrowser, 'Mozilla')) 

{

  $ub="PC";

}

//Check for Mozilla

elseif(stristr($userBrowser, 'gecko')) 

{

  $ub="PC";

}

//Check for opera

elseif(stristr($userBrowser, 'opera')) 

{

  $ub="PC";

}

//Check for omniweb

elseif(stristr($userBrowser, 'omniweb')) 

{

  $ub="PC";

}

//Check for msie

elseif(stristr($userBrowser, 'msie')) 

{

  $ub="PC";

}

//Check for konqueror

elseif(stristr($userBrowser, 'konqueror')) 

{

  $ub="PC";

}

//Check for safari

elseif(stristr($userBrowser, 'safari')) 

{

  $ub2="PC";

}

//Check for netpositive

elseif(stristr($userBrowser, 'netpositive')) 

{

  $ub="PC";

}

//Check for lynx

elseif(stristr($userBrowser, 'lynx')) 

{

  $ub="PC";

}

//Check for elinks

elseif(stristr($userBrowser, 'elinks')) 

{

  $ub="PC";

}

//Check for Mozilla

elseif(stristr($userBrowser, 'Mozilla')) 

{

  $ub="PC";

}

//Check for links

elseif(stristr($userBrowser, 'links')) 

{

  $ub="PC";

}

//Check for w3m

elseif(stristr($userBrowser, 'w3m')) 

{

  $ub="PC";

}

//Check for webtv

elseif(stristr($userBrowser, 'webtv')) 

{

  $ub="PC";

}

//Check for amaya

elseif(stristr($userBrowser, 'amaya')) 

{

  $ub="PC";

}

//Check for dillo

elseif(stristr($userBrowser, 'dillo')) 

{

  $ub="PC";

}

//Check for ibrowse

elseif(stristr($userBrowser, 'ibrowse')) 

{

  $ub="PC";

}

//Check for icab

elseif(stristr($userBrowser, 'icab')) 

{

  $ub="PC";

}

//Check for crazy browser

elseif(stristr($userBrowser, 'crazy browser')) 

{

  $ub="PC";

}

//Check for IE

/*elseif(stristr($userBrowser, 'internet explorer')) 

{

  $ub="PC";

}*/
//versiones ie
//4
elseif(stristr($userBrowser, "MSIE 4") || stristr($userBrowser, "Internet Explorer/4")) 

{

  $ub="OL";

}
//5
elseif(stristr($userBrowser, "MSIE 5") || stristr($userBrowser, "Explorer 5")) 

{

  $ub="OL";

}
//5.5
elseif(stristr($userBrowser, "MSIE 5.5") || stristr($userBrowser, "MSIE+5.5") || stristr($userBrowser, "MSIE+5+.+5")) 

{

  $ub="OL";

}

//6
elseif(stristr($userBrowser, "MSIE 6.")) 

{

  $ub="OL";

}



//If it's not any of the above browsers

//Then it gotta be a WML or very unpopular browser

else

{

  $ub="WML";

  }

//Code for redirecting based upon the results


if($ub == "PC") {

    header("Location: ".$htmllink);

    exit;
    }

    else 

    {

    header("Location: ".$wmllink);

    exit;

    }
if($ub2 == "OL") {
	
	header("Location: ".$htmlielink);

    exit;

    }

?>






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users