Get user operating system with PHP

Ever wanted to find out what operating system your visitors are using? The following function will allow you to get the user operating system so you can use in a statistics application or show certain content on your website. This will allow server side decisions on what stylesheets to show or any other operating system specific content to be shown/hide.

<?php
function getOS($userAgent) {
  // Create list of operating systems with operating system name as array key 
	$oses = array (
		'iPhone' => '(iPhone)',
		'Windows 3.11' => 'Win16',
		'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)', // Use regular expressions as value to identify operating system
		'Windows 98' => '(Windows 98)|(Win98)',
		'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
		'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
		'Windows 2003' => '(Windows NT 5.2)',
		'Windows Vista' => '(Windows NT 6.0)|(Windows Vista)',
		'Windows 7' => '(Windows NT 6.1)|(Windows 7)',
		'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
		'Windows ME' => 'Windows ME',
		'Open BSD'=>'OpenBSD',
		'Sun OS'=>'SunOS',
		'Linux'=>'(Linux)|(X11)',
		'Safari' => '(Safari)',
		'Macintosh'=>'(Mac_PowerPC)|(Macintosh)',
		'QNX'=>'QNX',
		'BeOS'=>'BeOS',
		'OS/2'=>'OS/2',
		'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)'
	);

	foreach($oses as $os=>$pattern){ // Loop through $oses array
    // Use regular expressions to check operating system type
		if(eregi($pattern, $userAgent)) { // Check if a value in $oses array matches current user agent.
			return $os; // Operating system was matched so return $oses key
		}
	}
	return 'Unknown'; // Cannot find operating system so return Unknown
}
?>

An example of how this would be used:

<?php
echo getOS($_SERVER['HTTP_USER_AGENT']);
?>

This script can be used with the Get Browser Type, which also has the same structure as this script.

Sanitize copy/paste text from word

In a recent project I have had to deal with text copied from a Microsoft Word document and pasted into a textarea. Word automatically changes a few certain characters to what it thinks it should be, such as the ellipsis and quotes. When dealing with inserting that text into a database I was getting errors. To solve my problems I created a sanitize function to replace these certain characters with acceptable characters.

<?php
// Used to sanitize Microsoft Word's Special Characters
// Good reference http://www.lookuptables.com

function SanitizeFromWord($Text = '') {

	$chars = array(
		130=>',',     // baseline single quote
		131=>'NLG',   // florin
		132=>'"', 	  // baseline double quote
		133=>'...',   // ellipsis
		134=>'**',	  // dagger (a second footnote)
		135=>'***',	  // double dagger (a third footnote)
		136=>'^', 	  // circumflex accent
		137=>'o/oo',  // permile
		138=>'Sh',	  // S Hacek
		139=>'<',	  // left single guillemet
		140=>'OE',	  // OE ligature
		145=>'\'',	  // left single quote
		146=>'\'',	  // right single quote
		147=>'"',	  // left double quote
		148=>'"',	  // right double quote
		149=>'-',	  // bullet
		150=>'-',	  // endash
		151=>'--',	  // emdash
		152=>'~',	  // tilde accent
		153=>'(TM)',  // trademark ligature
		154=>'sh',	  // s Hacek
		155=>'>',	  // right single guillemet
		156=>'oe',	  // oe ligature
		159=>'Y',	  // Y Dieresis
		169=>'(C)',	  // Copyright
		174=>'(R)'	  // Registered Trademark
	);
	
	foreach ($chars as $chr=>$replace) {
		$Text = str_replace(chr($chr), $replace, $Text);
	}
	return $Text;
}
?>

Enjoy!

Remote computer management

Sometimes it is rather amazing what some people can call for help with on their computers. Many times they have done something really simple such as remove a toolbar, switched default printers or something similar. If something is not the way it looked when they got trained they freak out! If you are like me you start to become aware of these co-workers and you can easily walk them through most problems over the phone. However there are special circumstances when attempting to walk somebody through a process over the phone just does not work and you need to take control over their computer to see what they are talking about. Having 5 different offices with computers in and only 2 IT people it can make it a challenge to drive to each office on a whim to support the user. Here are a few things that we use in the company I work for to support the employees:

Microsoft Terminal Services Manager: Our employees do 50-90% of their work in a Remote Desktop(RDP) terminal server. All of their email, health care software and most all other software is installed on this terminal server. Very few users actually use their local computer to do any actual work. Using the Terminal Services Manager we can easily see which terminal server they are logged into and remote control their session or even log off the user.

DameWare Mini Remote Control: We use this tool if the user is having difficulties getting into the terminal server or using their local computer. We will even use this application for setting up new software on a computer in a remote location without having to be in front of the computer. Sure there are methods of installing software via Active Directory GPO, System Center and others but sometimes manual is how it has to be done.

Lantronix SecureLinx Spider KVM over IP: This is great for computers that are having issues with WiFi connectivity issues and you cannot use the above tools while they are in the office. This device is powered by the USB ports and requires just a network cable plugged directly into the device. Also works great for laptops that are having problems booting. Just walk the person on the other end of the phone how to connect the device and go from there.

LogMeIn Rescue: This is the tool of choice for those employees that work outside the office where DameWare and KVM over IP just don’t work for us. Easily walk them through accessing a certain website, give them the 6 digit pin code and connect a remote support session easily. You can even install an application (Calling Card) to give even easier access to support right on the local computer desktop.

Dell Remote Access Controller(DRAC): Used in our servers for quick easy access to the machine. Easily power on/off the machine as well as view the screen. This will be helpful if we accidentally select shutdown instead of reboot on the ESX or SAN host cluster servers late at night while working from home via VPN. Just login to the web control panel and a few minutes later the server is back on.

With these tools we can easily solve most problems remotely unless it is something major like a hardware failure. Even re-loading the OS could be done remotely if somebody put the OS CD in the machine and plugged in the KVM since we currently are not using any imaging software.

If you have any other suggestions for remote management of computers leave a comment. Always looking for potentially better/easier ways to support computers.

Enabling / Disabling Bcc field in Microsoft Outlook

The use of the Bcc field in email is something that more people should use. Over the summer I had purchased a new home and gave my realtor my email address to email me new listings. A few months later her husband (her partner in the real estate firm) sent out some mass emails and placed everybody’s email address in the To field. The problem with this is that I along with every other one of her clients now have the email addresses of all of her clients, some of which I recognized. To prevent this you can use the Bcc field which will hide all of the recipients. Enabling this field in Microsoft Outlook 2003 and 2007 is rather easy.

Outlook 2003
Step 1 is open Outlook and create a new email. Once in the new email you will need to find the Options button that is located on the main toolbar. Click on the small down arrow just to the right of the word Options.

Bcc Outlook 2003

Step 2 is to click on the Bcc option which is 2nd from the bottom.

Bcc Outlook 2003

You will now see the Bcc address line just above the Subject field.

Bcc Outlook 2003

Outlook 2007
Step 1 is to open Outlook and create a new email. Once in the new email you will see the ribbon at the top. You will need to click the Options tab.

Bcc Outlook 2007

Step 2 is to click on the Show Bcc button in the Fields section of the Options ribbon.

Bcc Outlook 2007

The Show Bcc field will now be highlighted and the Bcc field will be placed just above the Subject field.

Bcc Outlook 2007

That is how easy it is to show the Bcc field in your new emails so you can hide the email addresses of the recipients of your email.

Outlook cannot find archive.pst after auto archive disabled

Recently we have added a new Windows Terminal Server into network and network load balanced the two servers. Shortly after allowing users to login on the new server we started having issues with Microsoft Outlook (2003) on select users saying that it could not find the archive.pst file.

The file c:\Documents and Settings\(username)\Local Settings\Application Data\Microsoft\Outlook\archive.pst could not be found.

Read the rest of this entry »