[BUGFIX] Improve FE context detection

Improve detection of FE context and make sure that a page id
really exists. The log entry will fail if the pid is NULL.

Resolves: #58536
Releases: 2.11
Change-Id: If4c02a33dd47e594fb8ae3a66861ec1c71a5177e
Reviewed-on: https://review.typo3.org/30255
Reviewed-by: Francois Suter
Tested-by: Francois Suter