1) If you want to create a shapefile for download, you should be able to publish an async geoprocess that will return a link to the location of the generated shapefile on your ArcGIS Server. You call this service from the javascript API using esri.tasks.Geoprocessor. Take a look at the clip-and-ship example. It uses a file gdb, but you should be able to change it to a shapefile if you need.
javascript side:
http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/gp_clipasync.html
server side: http://resources.arcgis.com/en/help/main/10.1/index.html#/Clip_and_ship/01540000035r000000/
2) In javascript, I've successfully used the jquery based DataTables library to create a very functional data grid http://www.datatables.net/. DataTables has a plugin called TableTools that can save table data as a CSV file among other things -- it includes a tiny flash plugin for the local file saving. It has worked well for me. You could potentially put json geometry into a column. See this post for a sample Spatial query in ArcGIS Javascript Api 3.1
3) I'm sure you could do it with php accessing a shapefile library, write it out, zip it up and send back a link, but I don't have a recipe for you.