|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
make all url variables one variable on page....
I was wondering how I can direct users to a login page, and then back where they were going... I've figured that to do it I would jsut check to see if the user is logged in, and if not, use header(location: url);. But when they log in, they will be sent to index.php (thats the header I have after login is done). I figured maybe I could just somehow get ALL variables sent through the url and make them one variable which I could just do header(location: $var);. Can this be done? getting all variables into one var? I could concactanate. But without know what vars have been sent, can I jsut grab them ALL? Or jsut assume a variable may have been sent.
How do other websites do this, if this isnt how? thanks!
__________________
hey it's the CHARKING |
|
#2
|
|||
|
|||
|
Off the top of my head the following should be of use:
I assume you are using a function to do the login check, then in that function you redirect the user to the correct location. Modify your function to take a location parameter. It should be optional so give it a default value or leave it blank by default. Check for the value first, if it exists then use it. To fill this variable/parameter, you would need to actually grab the page the user was trying to access. In order to do this, I assume you are using an include to validate a logged in session or cookie, so at that point you should gather the location information. You can use $_SERVER['REQUEST_URI'] This will give you the name of the script (relative to the server's document root), and the associated query string. If you want to consider POST variables also you will need to put in more work. If you wanted Get and Post Variables you would have to use $_SERVER["REQUEST_URI"] and append the query string to that. To get the querystring values you could create an array like the following: $qs_array = array_merge($_POST, $_GET); foreach ($qs_array as $key=>$value) $qs .= "$key=$value";
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
|||
|
|||
|
I created a fairly handy authentication script that I use on most sites that require form-based authentication.
it uses the following function (I am function checkAuth() { //Perform code that ensures that the user is authenticated //if the user is not yet authenticated if (!$auth) { $pageAfterAuth = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; header("login.php?redirect=" . urlencode($pageAfterAuth)); } } then on login.php you could display your form and be sure to include a hidden form field named 'redirect' that contains the value of $_REQUEST['redirect'] as its value. On the page that processes the logon you could then include the following code: //perform code to log user in and set cookies or whatever //check to see if the redirect variable is set if (array_key_exists('redirect', $_REQUEST)) { header('Location: ' . $_REQUEST['redirect']); } else { //otherwise you could send them to a default location header('Location: /index.php'); } That is probably more involved than you were looking for but it is just a simple overview of I how I do it and it has worked well for me. |
|
#4
|
|||
|
|||
|
just wanted to say hanks, and although I don't think I understood the first example I figured out the other one with the querystring fetching... thats a cool thing to know. thanks both of you!
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > make all url variables one variable on page.... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|