Jump to content

querystring after redirect to login page


stijn0713

Recommended Posts

hello,

 

suppose i click on a 'group 1' which will direct me to group.php?ID= 'id of the group'

 

and in group.php i have restricted the page to logged users. Suppose they are not logged, so they are directed to logon page, after which they are redirected back to group.php.

 

Do i lose the information of the querystring then, i.e. ?ID=

 

 

if a user reaches a page they do not have access to until they log in, set the query string to their $_SESSION['previous'] and redirect them to log in.  Once successfully logged in, redirect them to the value in the session.

 

Ninja'd! :shakes fist:

mm, but if i add it to session, than i have to make sure that if they, after they select another group, they get the right group to see.

 

so i guess i'll do it like this:

 

if(isset($_GET['ID'])){

$ID_Onderzoek = $_GET['ID'];

}

else if(isset($_SESSION['get_ID'])) {

$ID_Onderzoek = $_SESSION['get_ID'];

} else {
	$ID_Onderzoek = "geen onderzoeksID gevonden";
	}

Is this how you mean it?

or add it to the redirect back to the login page

that i don't understand

 

use the session, it'll serve you best. plus, you can maintain the 'previous' entry to follow the user around (useful for analytics).

 

based on your new post:

consider path to file: /home/wwwdata/pages/groups.php

 

user goes to:

site.com/groups?id=3

 

they aren't logged in, so redirect

<?php
if( !logged_in() ) {
   $_SESSION['previous'] = 'groups.php?' . $_GET;
   header('Location', 'login.php');
}

 

then they log in:

header('Location', $_SESSION['previous'];

 

 

Not tested, not escaped, not sanitized. learning purposes only

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.