Fetch user id on behalf of the non-drupal php
If you copy that code/file to another directory, DRUPAL_ROOT will be set to that directory, not that of drupal's... so I'd change up that first define to point to where drupal is and you should be all set.