That almost didn't make alot of sense...maybe I'm just thick skulled though 😃
What I got from your post is that you want anyone (registered or unregistered) to use your handy-dandy little function (or service) on page B, but you want to make sure they're logged in or no handy-dandy function. Am I on to something here?? If they're not logged in, you want it to prompt them for a username and password and then remember where they were headed basically.
Sessions are your friend then!!!
Set two session variables:
Set $_SESSION["autheticated"] (or whatever you want to call it.) to test if the user is logged in.
Set $_SESSION["current_page"] (or whatever you want to call it.) to test what page the user was last accessing.
$autheticated will be set to true when the user successfully provides a valid username and password.
$current_page can be set to $_SERVER["PHP_SELF"] Just make sure you don't set this varibale in your login page(s).
So once a user submits the "handy-dandy little function" request, check to see if $SESSION["$autheticated"] is set to true, if not redirect via Header() to login page, if credentials match, redirect to $SESSION["current_page"]
Have fun!!