Forum Moderators: open

Message Too Old, No Replies

PHP Redirect after login

Redirect after login

         

tommorrison

10:17 pm on Aug 12, 2008 (gmt 0)

10+ Year Member



Hi
i have made a database and a login and logout php and everything is working fine. The only thing thats wrong is that when a user logs in they get redirected to a specific page. I want the user to be redirected to a different page for each user. This is the section in my form process php where the redirection php is

// Register the values & redirect:
$_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC);
mysqli_free_result($r);
mysqli_close($dbc);

$url = BASE_URL . 'login/memberarea.php'; // Define the URL:
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.

As you can see its will direct all users to the page memberarea.php

Can anyone help?

mack

7:05 pm on Aug 13, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If you simply want to send them to a specific page can you not just change...

$url = BASE_URL . 'login/memberarea.php'; // Define the URL:

to the correct page location with relative URI?

Mack.

tatorface

9:04 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



I would imagine that it depends on what type of specific page they need to be directed to. Since it has not been mentioned, I will assume it is something like a user permission level idea where you have guests, administrators, level1, level2, etc.

The


$url = BASE_URL . 'login/memberarea.php'; // Define the URL:

is where you need to start. You could just pass a query string to the memberarea.php telling it what specific items need to be displayed.

Like membersarea.php?level=admin shows all admin features which the php file determines, membersarea.php?level=guest shows all guest features, etc.

Your membersarea.php would need to include a variable to capture the 'level' variable, then use a case statement or if statements to determine if X needs to be shown.

You could also create a seperate page for each level, category, etc and just put an if statement before the $url declaration and pass whatever is determined to be the right page:

$level = $_GET['level'];

switch ($level) {
case "admin";
$url = BASE_URL . 'login/memberarea_admin.php'; // Define the URL:
break;

case "guest";
$url = BASE_URL . 'login/memberarea_guest.php'; // Define the URL:
break;

}

either of these ideas would work, but without any more explaination, its hard to tell exactly what would be best.