PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
qads
DevNet Resident
Posts: 1199 Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane
Post
by qads » Tue Nov 12, 2002 4:14 pm
Code: Select all
<?php
$type = $_ENVї"HTTP_USER_AGENT"];
if(empty($type))
{
$type = $_SERVERї"HTTP_USER_AGENT"];
}
$arrayї3] = "Win";
$arrayї2] = "Linux";
$arrayї1] = "Mac";
$howmany = count($array);
for($cvf = 1; $cvf<=$howmany; $cvf++)
{
if(!strstr($type,$arrayї$cvf]))
{
$type = "Unknowen";
}
}
echo $type;
?>
this works fine if the $type is "Win" but it puts Unknowen with "Mac" and "Linxs".
what i am trying to do is to see if the user agent is on one of $array(win, mac, linux), if it is then it inserts into a table if not it then it replaces the $type value with "Unknowen".
thanks for your help.
- Qads
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Nov 12, 2002 5:15 pm
you're setting $type -the variable you're testing- to 'unknown' in every loop if the user-agent string does not match. Quite weird
try
Code: Select all
<?php
$array = array('Mac', 'Linux', 'Win');
if(isset($_ENVї"HTTP_USER_AGENT"]))
$type = $_ENVї"HTTP_USER_AGENT"];
if(empty($type) && isset($_SERVERї"HTTP_USER_AGENT"]))
{
$type = isset($_SERVERї"HTTP_USER_AGENT"]) ?
$howmany = count($array);
for($cvf = 1; $cvf!=$howmany; $cvf++)
{
if(strstr($type,$arrayї$cvf]))
break;
}
if($cvf==$howmany)
$type = 'Unknown';
}
else
$type = 'unknown';
echo $type;
?>
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Tue Nov 12, 2002 5:47 pm
Code: Select all
<?php
$type = $_ENVї"HTTP_USER_AGENT"];
if(empty($type))
{
$type = $_SERVERї"HTTP_USER_AGENT"];
}
$arrayї3] = "Win";
$arrayї2] = "Linux";
$arrayї1] = "Mac";
foreach($array as $var){
if(strstr($type, $var){
$unknown = TRUE;
}
}
if($unknown === TRUE) $type = "Unknowen";
echo $type;
?>
qads
DevNet Resident
Posts: 1199 Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane
Post
by qads » Tue Nov 12, 2002 8:48 pm
these did't work
but this did:
Code: Select all
<?php
$arrayї1] = "Win";
$arrayї2] = "Linux";
$arrayї3] = "Mac";
foreach($array as $var)
{
if(strstr($type,$var))
{
$unknown = TRUE;
}
}
//this line was missing a !..
if(!$unknown === TRUE) {$type = "Unknowen"; }
echo $type;
?>
thanks alot guys