Find the version of OSX the user is running with a bash command:
sw_vers -productVersion
It outputs the version number, so you'll get something like "10.9" or "10.8.4" which you can then parse further for however you need.
Use it in Applescript:
set the_version to do shell script "sw_vers -productVersion"
Use it in PHP
$version = exec('sw_vers -productVersion');