-3

I am getting the following error

Parse error: syntax error, unexpected '$agent' (T_VARIABLE) in C:\xampp\htdocs\webconcept2.php on line 3

and the code is given below. I have checked all possible errors of semicolons etc but does not find the error     

<?php

 $agent = $_SERVER['HTTP_USER_AGENT'];

if(preg_match('/Linux/i',$agent)) $os = 'Linux';
  elseif(preg_match('/Mac/i',$agent)) $os = '/Mac';
  elseif(preg_match('/iPhone/i',$agent)) $os = 'iPhone';
  elseif(preg_match('/iPad/i',$agent)) $os = 'iPad';
  elseif(preg_match('/Droid/i',$agent)) $os = 'Droid';
  elseif(preg_match('/Unix/i',$agent)) $os = 'Unix';
  elseif(preg_match('/Windows/i',$agent)) $os = 'Windows';
  elseif $os = 'Unknown';
     // Browser Detection
if(preg_match('/Firefox/i',$agent)) $br = 'Firefox';
    elseif(preg_match('Mac/i',$agent)) $br = 'Mac';
    elseif(preg_match('Chrome/i',$agent)) $br = 'Chrome';
    elseif(preg_match('Opera/i',$agent)) $br = 'opera';
    elseif(preg_match('MSIE/i',$agent)) $br = 'IE';
    else $bs = 'Unknown';

?>
Sukhi
  • 3
  • 3

1 Answers1

1

In your last elseif statement in your checks for os detection, you are missing a condition elseif (condition).

What you meant to do is

else $os = 'Unknown';

Also, in your checks for browser detection, your regular expressions are not correct. elseif(preg_match('Mac/i',$agent)). It should be '/Mac/i'

MrByte11
  • 300
  • 2
  • 9