again php. Of course you need to know the HTML to render the page, but for all of the cleverness i'd deffinately reccomend php.
Make sure your server supports php first though!!! And be aware that the actual way in which it works can vary (can be run in safe mode etc...).
JavaScript can be very clever but my problem with it is that it is client side and so you are dependant on the client having a javaScript enabled browser and having it turned on. With php because it is serverside as long as your webserver supports it then it'll work for everyone