Mental note on Safari, cookies and underscores

In short: do not use underscores for your local domains.

Apparently, Safari decided to be kind of very strict, which means it will show a website whose domain name contains underscores, but will dutifully ignore every request to set cookies on it.

It's very funny because if they really wanted to be strict they should not show the website at all, instead of making me peek into odd pages trying to find out why oh why it worked on opera and firefox but not in Safari.

And it seems it also can lead to the same problem in IE, which makes me kind of agree with that lemma: Safari is the new IE!

Luckily underscores are not allowed when registering a domain (I just checked that). Otherwise we would have heard a ton of complaints from customers who ordered a website and then couldn't login at their own website because the domain contained an underscore.

Extra bonus: you can use this snippet of code for checking that cookies are working. Save it as 'cookie-test.php' or something that you fancy and reload reload reload. It should show "X is 0", "X is 1", "X is 2", etc.

If it doesn't work, it'll always show "X is 0";


<?php

if(isset($_COOKIE['x']))
{
    $x = $_COOKIE['x'];
}
else
{
    $x = 0;
}

setcookie('x', $x+1);

echo "X is $x";

?>