I'm trying to build an admin interface for site I'm working on and can't seem to figure out how to redirect users first to the login screen (if they haven't logged in yet), then verifying their credentials and redirecting back to the page they initially requested. Should I be storing the requested page in a session variable? I've tried storing $PHP_SELF, but that only seems to return the basename of the script and leaves out the GET values.

For instance, I'm trying to get to www.domain.com/admin/?p=links. (The index script pulls in the HTML for different pages based on the value of $_GET['p']) If the user hasn't logged in yet, it sends them to a login screen and submitting that form needs to validate their credentials and then redirect to /?p=links.

    You can use:

    header("location: [url]http://www.blarg.com/login.php[/url]");
    

    Just remember to replace the blarg thingy 😉.

    One more thing, this function must be placed above any output to the browser. If you need to output, use JavaScript.

      The actual redirects are not difficult. But how do I grab the URL (including the GET values) from the HTTP request, store it in a session variable or something and then reference it after a successful login attempt? Well, let's make it simple..

      What's the easiest way to grab the full and complete URL?

        $_SERVER['REQUEST_URI']
        

        That only have filename + Query String just add the domain name before that.

          Write a Reply...