Presumably your login fields are in an html form. When you're constructing the form, put the current URI in a hidden input field, then you have the information available to you when you want to perform the redirect after the POST data has been submitted.
I don't typically use PHP without a framework, but here are some resources that will help you get this information:
http://www.webcheatsheet.com/PHP/get_current_page_url.php
http://stackoverflow.com/questions/189113/how-do-i-get-current-page-full-url-in-php
Basically, it goes like this:
$current_url = "http://" .$_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'];
But if you are using https
, you have to change that string accordingly.