code function implemented for php and javascript