Marius van Witzenburg We fight for our survival, we fight!

4Jul/110

How to generate a Windows Live Messenger or MSN Messenger contactlist file with PHP

Posted by mariusvw

If you would like to generate a contact list with PHP to import email addresses into your contact list use the following...

PHP contactlist generator

mysql_connect('localhost', 'username', 'password');
mysql_select_db('database');
 
$doc = new DOMDocument('1.0');
$doc->formatOutput = true; 
 
$node = $doc->createElement('messenger');
$messenger = $doc->appendChild($node);
 
$node = $doc->createElement('service');
$node->setAttribute('name', '.NET Messenger Service');
$service = $messenger->appendChild($node);
 
$node = $doc->createElement('contactlist');
$contactlist = $service->appendChild($node);
 
$result = mysql_query("SELECT `email` FROM `contacts`");
while ($data = mysql_fetch_assoc($result)) {
    $node = $doc->createElement('contact', $data['email']);
    $contactlist->appendChild($node);
}
 
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename=contacts.xml');
echo $doc->saveXML();

Output

<?xml version="1.0"?>
<messenger>
  <service name=".NET Messenger Service">
    <contactlist>
      <contact>email1@domain.tld</contact>
      <contact>email2@domain.tld</contact>
      <contact>email3@domain.tld</contact>
      <contact>email4@domain.tld</contact>
      <contact>email5@domain.tld</contact>
    </contactlist>
  </service>
</messenger>
29Mar/100

How to use Internet Explorer 8 (IE8) compatibility view mode

Posted by mariusvw

Everybody knows that Internet Explorer can be a bitch... And so for IE8!

For the scripts who do not work right yet on IE8 there is a way to put IE8 in compatibility mode so you can view the website in a IE7 sorta like environment.

In PHP you have to send the following header, my advice is to add it to your first index file if you handle everything through this index.

<?php
header('X-UA-Compatible: IE=EmulateIE7');
?>

Or you can add a header in the HTML head with a meta tag.
Add this right after the <head> tag:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

In the same way specify IE=5, IE=7, or IE=8 to select one of those compatibility modes. A complete table is given below.

I hope this makes your life with Internet Explorer a bit easier!

Ps. If you want to break this feature, you could use something like this to force IE to always be compatible:

<?php
header('X-UA-Compatible: IE=100');
?>