If you don't pass any information into the PHP file, there is no way to determine which course you are in (for example, if you have 3 different browser pages open, you could be in 3 different courses at the same time).
For this to work, the place you link to your page from would need to be something like this:
$cmid = required_param('id', PARAM_INT);
To get the coursemodule ID.
See any existing Moodle page for examples of this.