Collecting the user agent

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

Post Reply
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

Collecting the user agent

Post by therat »

I have the following code that is suipposed to record the user agent of a visitor, but it does not show anything. I did not write this code, it comes from another stats script that I no longer have. Any suggestions as to why it does not work.

Code: Select all

function GetUserAgent() {
		if (isset($_SERVER['HTTP_USER_AGENT']))
		{
			if ($_SERVER['HTTP_USER_AGENT'] != NULL)
			{
				$this->GetUserAgent = strtolower((string)$_SERVER['HTTP_USER_AGENT']);	
			}
			else
			{	
				$this->GetUserAgent = '';
			}
		}
		else
		{
			$this->GetUserAgent = '';
		}
	}
dipit
Forum Newbie
Posts: 12
Joined: Thu Apr 08, 2004 2:36 am
Location: india
Contact:

hi

Post by dipit »

try this.
it is working on my machine

*************************************************************
<?php

function GetUserAgent() {
if (isset($_SERVER['HTTP_USER_AGENT']))
{
if ($_SERVER['HTTP_USER_AGENT'] != NULL)
{
$this->GetUserAgent = strtolower((string)$_SERVER['HTTP_USER_AGENT']);
}
else
{
$this->GetUserAgent = '';
}
}
else
{
$this->GetUserAgent = '';
}
echo $this->GetUserAgent;
}


GetUserAgent();

?>

*************************************************************
8O
Post Reply