Jump to content

PHP Browser detection


driz

Recommended Posts

Please look at the following PHP code. It doesn't seem to be working, can you tell me what is wrong? Thanks. x

<?phpfunction browser() {		if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))	echo '<p>You are using IE</p>';	else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko/'))	echo '<p>You are using Firefox</p>';	else if (strstr($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit'))	echo '<p>You are using Safari</p>';	}	?>

Link to comment
Share on other sites

I know JS can detect browsers really easilly, but idk how... try looking at this function and alter your code to follow itget_broswer()http://us2.php.net/manual/en/function.get-browser.php(Wow, I didn't realize PHP could get that much information about the user's browser! I just sort of spotted the function when I was looking at $_sever vars! :))

Link to comment
Share on other sites

Im not really a PHP coder but doesn't a function need to be called?

Link to comment
Share on other sites

Please look at the following PHP code. It doesn't seem to be working, can you tell me what is wrong? Thanks. x
<?phpfunction browser() {		if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))	echo '<p>You are using IE</p>';	else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko/'))	echo '<p>You are using Firefox</p>';	else if (strstr($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit'))	echo '<p>You are using Safari</p>';	}	?>

Hey try
<?phpfunction browser() {		if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))	echo '<p>You are using IE</p>';	else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko/'))	echo '<p>You are using Firefox</p>';	else if (strstr($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit'))	echo '<p>You are using Safari</p>';	}	browser();?>

:)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...