Jquery Mobile and RTL websites

One more piece of info to share:

It appears that sometimes your RTL mobile website looks awful on some of devices: it has HUGE horizontal scroll.
The reason is simple (once you find it): there are hidden elements in Jquery Mobile, which are hidden by moving them to the left. Yep.

Just search JQMobile css file for the left:-9999px; and change them to whatever is suitable for you.

Leave a comment

Output CSV from PHP

I’d rather call it “an example for why developers do not like Microsoft”, actually..
After 3 days of struggling, I have now non-English csv file, which opens correctly in MS Office. No, standards are not important here; creating a valid file won’t help. It will open in Open and Libre Office, and probably even in notepad and wordpad. But not in MS Excel, which is used by all those people we create reports for..
Keeping the long story short, this is the code that worked:


header ( 'HTTP/1.1 200 OK' );
header ( 'Date: ' . date ( 'D M j G:i:s T Y' ) );
header ( 'Last-Modified: ' . date ( 'D M j G:i:s T Y' ) );
header ( 'Content-Type: application/vnd.ms-excel') ;
header ( 'Content-Disposition: attachment;filename=report.csv' );
print chr(255) . chr(254) . mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');
exit;

(found here)

It is about 50th sample of code I tried. I’ve encoded it as ISO, and as Windows-1252 (yes, it’s hebrew), and what not…
Hope it would help someone.

1 Comment

MySQL and encodings

This one will be short.
When migrating old DB to a new one, I often come to handle non-utf encoding.
Here’s the code I’m using, so far worked on any “gibberish”, including bad encodings on Hebrew.

CONVERT(CAST(your_field as BINARY) USING utf8)

How from now on I won’t be looking for it for ages..

Leave a comment

Signing your email

When creating a website, one will most likely want to send emails from the code. It can be contact request, response to the user or anything else. Many of these emails are better to be signed, as otherwise email clients will show them in a strange (for regular user) or suspicious (for a bit more experience user) way, or send them to spam. For example, Gmail adds a “via” part to From field. So, how would we sign the outgoing emails?

1. SPF
SPF is Sender Policy Framework, an open standard specifying a technical method to prevent sender address forgery. You can read about it more here to find out what and why it is, I will focus only on how would you use it.

You need to create a DNS TXT record with string, saying whom do you allow to send emails by your name. Here is the syntax; if you want to allow anyone from your domain (works perfect for mails sent from the code, but is not too much secure), you can use the string “v=spf1 +a +mx -all”. To be sure your string is correct, you can use the validator.

At the end, you Zonefile will have something like this:
@ IN TXT "v=spf1 +a +mx -all"

After your DNS had updated, you can check the record from the same validator.
However, the best check is in your mail client; for Gmail, validated SPF looks like this:
Received-SPF: pass (google.com: domain of mailer@example.com designates *.*.*.* as permitted sender) client-ip=*.*.*.*;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of mailer@example.com designates *.*.*.* as permitted sender)

2. DKIM
DKIM states for DomainKeys Identified Mail, which attaches a new domain name identifier to a message and uses cryptographic techniques to validate authorization for its presence. The identifier is independent of any other identifier in the message, such in the author’s From: field. More on it here.

This one is a bit more complex. You need to generate keys, add one of them to your emails’ header and the second one to you DNS records.
There are rather many implementations of DKIM, I use the simplest for me, PHP-DKIM.

Here are the steps:

1. Create the keys. For example, you can run (on any system):
openssl genrsa -out key.priv 384
openssl rsa -in key.priv -out key.pub -pubout -outform PEM

This one is not too secure, better use SHA256.

2. Copy the keys into dkim-cfg.php, do not mix up public and private. Set there your domain and selector (I understand it can be any word). Run dkim-test.php, it will output a DNS record for you, add it to your Zonefile. Now, add AddDKIM function to your email sending scripts, like it is shown in dkim-test.php.

After DNS had updated, you’ll have something like this:
Received-SPF: pass (google.com: domain of mailer@example.com designates *.*.*.* as permitted sender) client-ip=*.*.*.*;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of mailer@example.com designates *.*.*.* as permitted sender) smtp.mail=mailer@example.com; dkim=pass header.i=@example.com

If you see dkim=hardfail instead, it means something went wrong. I found this service for checking, but had no reason to use it.

This is it! Now your emails must be signed, Gmail won’t show VIA thing in headers, and everyone will like you. Probably :)

Leave a comment

When your Google Tasks are gone…

One may call me addicted or whatever, but I use many Google Services, and use them a lot.
Orijinn’s calendar contains all my ongoing projects, planning what I do and when, and Tasks. In other words, there’s all my work data.
So you can imagine, what did I feel yesterday, when the Tasks panel has suddenly gone!

Digging Google (the search, I mean..) shows there are tons complaints on the net, starting from several months ago, and tons of solutions, which do not work.
To save your time: the problem is still unknown to Google, but it seems to pop up only on Non-english interfaces.
Now, the catch is that the fact your Calendar is in English does not say your interface is (WAT?).

To solve this somewhat weird issue:
1. Goto your Calendar settings and ensure the language is set to English
2. Goto to here: http://www.google.com/preferences?hl=EN (being logged in) and set the first option to be English.
3. Refresh the calendar and enjoy your tasks panel.

Actually, I’m rather mad on Google for changing my language preferences all the time.. But well, everything cannot be ideal :)

1 Comment

Microsoft opens an IE6 Countdown site

Here it is: http://ie6countdown.com/

Not sure, why exactly is it a “countdown”, I’d rather call it “IE6 agony” or something.. or would like it to be an agony.
The data shown on the map is correct only for the .Net applications, so it is not relevant for me (being PHP and Java developer), but in any case it is useful to have an overall picture.

I wish I see all the percentage there on 0%… when will this day come?

Leave a comment

Iframe and ‘Back’ browser button

Iframes had became very important part of web development. I bet there aren’t many serious sites without any iframe inserted: analytics, some widget, ads or anything else.. I use them often, too, and I’ve encountered an annoying problem: ‘back’ browser button won’t trigger iframe refresh.
Actually, it is the same with the parent page, but there we always may catch this and do something. Iframe cannot handle this event. We also don’t want to refresh our iframe explicitly each time it is loaded.

The solution is what you might think it is, but it took me some time to figure it out. Actually, I received a great help, so I own no credit here. However, as I couldn’t find any mention of this issue on the web, I’m posting it here for the future reference.

We’d like to create our iframe on each window.load event, as this one is fired also when user hits ‘back’ button. We’ll create it dynamically, using two tricks:
1. set iframe.src to about:blank before the append, and after the append change it to actual data
2. add some random value among the iframe.src parameters

Like this:

window.onload = function(){
	var ifr = document.createElement("iframe");
	ifr.width = '100%';
	ifr.height = '500px';
	ifr.frameBorder = '0';
	ifr.marginHeight = '0';
	ifr.marginWidth = '0';
	ifr.scrolling = 'no';
	ifr.id = 'myIframe';
 
	ifr.src = 'about:blank';
	var elt = document.getElementById('eltToAppend');
	elt.appendChild(ifr);
 
	ifr.src = ['http://example.com','&r=',Math.random()].join('');
}
Leave a comment

HTML form and “Enter” key

Do you think that any form on a web-page may be submitted by pressing “Enter”?

I was surprised to discover, that this fact is true only for the forms having a submit button or the single input field. It appears that the form more than one input but without “submit” won’t submit if you press the “Enter” key.
You are welcome to check: the first form submits (and alert a message), while the second one does nothing.

After a quick search this problem appears to be a known and rather old one. People on the web say this bug is known since Netscape times; also they say that there is an open bug on it for IE – I cannot check, as Microsoft does not allow unregistered users to see its bugs.

Where does this issue come from?
This is what we see in W3C HTML specifications:
“When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form.”

Does it mean that otherwise UA should not accept it? Obviously, our browsers think so. I’ve checked in all my browser zoo (all the latest browsers on Linux and Windows (XP and 7), plus IE7, IE6, and Safari on Mac) – the behavior is equal in all of them except Safari, which nicely submits both of the forms.

So, though we most likely won’t use the input of a type button, we still must add it, being hidden, to any form with more than one input field:

With display:none it works in Firefox and Opera, but won’t work in Chrome, so I stopped checking. The example above has visibility:hidden on the button; it is ok in all the browsers I have except IE8 and below (surprising, indeed). Setting width and height to zero leaves us with ugly rectangle; setting a JS event to catch “Enter” is bad for all users who has their JS off. I think, from here any site has to make its own decision. Or maybe someone knows the ultimate cross-platform solution?

Tagged | Leave a comment

a kind of hello

Ok, it seems for me that finally there is too much stuff I need to remember – these small quirks you might need some day. Moreover, there have been too many places I used to write these down.. so this is the time to start a blog. Probably there is someone except me who will find these points interesting, too. And, as we all know, you always remember better something you’ve got to write down. Two articles coming soon. Way to go!

(..and I cannot stay and will say it: I finally put this site on, found the time for it, hooray!)
Leave a comment