Sorry, I don't know php, so can't help much

Maybe some expert would be able to help you.

Shabbir: Can you check this one?