How to return users to the right page?
February 25, 2008 7:13 AM   Subscribe

How can I put a login box on every page of my website?

The site is coded in PHP and talks to a MySQL database, and it authenticates users perfectly, sets sessions and so on. The form to log in is on every page, and the action of the form is set to be $_SERVER['PHP_SELF'].

My header.php is included in every page, and contains the script to do all the logging in business. However, the URL to a page might be details.php?id=123, to see the details of an item. $_SERVER['PHP_SELF'] takes the user back to just details.php - is there any way to take them back to the page details.php?id=123?
posted by xvs22 to Computers & Internet (5 answers total)
Could you construct one from the http server variables? Try substituting $_SERVER['PHP_SELF'] with:

"http://" . $_SERVER['SERVER_NAME'] . $_SERVER['URL'] . "?" . $_SERVER['QUERY_STRING']

It depends on if the login will pass them back to that page though.
posted by jwells at 8:00 AM on February 25, 2008

posted by missmagenta at 8:12 AM on February 25, 2008

I believe phpbb does this, or something like it. It takes you to an interstitial page, anyways, that redirects you back to the thread you were reading, so it might be useful to look at how it does this.
posted by Mr. Gunn at 2:47 PM on February 25, 2008

I'd do what MissMagenta said.
posted by foxydot at 7:08 AM on February 26, 2008

But I don't think you can just add "$_SERVER['REQUEST_URI']" as the form action -- when the form POSTS (or GETs), the form elements will override the query string variables. (and the destination page won't know what to do with that URL anyway) You want to add a hidden form input called "redirect" or something, and then, when the page posts to itself, process the rest of the form contents, and if successful, redirect ( header('Location:'); ) to that URI.
posted by misterbrandt at 7:43 AM on February 26, 2008

« Older How does a garden grow?   |   I'd like to eat more than cheese and butter. Newer »
This thread is closed to new comments.