Redirect user to specific page after login

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Laim71
User
Posts: 75

Redirect user to specific page after login

Post by Laim71 »

Hi ,
I've tried a lot of solutions about this topic but none of them worked in my case.

I use PhpMaker V 2017.

I wish my users to be redirected to a specific page according to their userleveid.

here is my code in Server Events > Default >Login_page >User_LoggedIn

if (CurrentUserLevelid == -1) {
$url = "Admin.html";
} else {
$url = "userpage.html";
}
}

Thanks for your help


mobhar
User
Posts: 11702

Post by mobhar »

There is no $url context in "User_LoggedIn" server event. You should use "Page_Redirecting" server event under "Server Events" -> "Other Page" -> "Default Page" instead.


Laim71
User
Posts: 75

Post by Laim71 »

Thanks for your help, but page redirecting does'nt still work.

This is my last code In Other > Default Page > page_redirecting

if (IsLoggedIn()) {
if (CurrentUserlevel() == 'Administrator') {
$url= "t_eqadd.php";
} else {
$url = "t_eqlist.php";

Your help woudl free me !!!


mobhar
User
Posts: 11702

Post by mobhar »

Double check your code. It seems you missed two closing curly brackets.

Your code should be:

if (IsLoggedIn()) {
if (CurrentUserlevel() == 'Administrator') {
$url= "t_eqadd.php";
} else {
$url = "t_eqlist.php";
} // <--- end of else
} // <--- end of IsLoggedIn


Laim71
User
Posts: 75

Post by Laim71 »

Thanks for your help.
But rather than in default page, for users of v 2017, you have to put the code in Page_Redirecting Server Event of the login page.
It works good.


dh1340
User
Posts: 58

Post by dh1340 »

Hi,
so I am on 2018 and tried this in Default Page :

// Page Redirecting event
function Page_Redirecting(&$url) {
	// Example:
	//$url = "your URL";
	if (IsLoggedIn()) {
if (CurrentUserlevel() == 'Fussball') {
$url= "mitglieder_fussballlist.php";
} elseif (CurrentUserlevel() == 'Futsal') {
$url= "futsal_mitgliederlist.php";
} else {
$url = "mitgliederadd.php";
} // <--- end of else
} // <--- end of IsLoggedIn
} // <--- end of Page_Redirecting

For some reason it allways gives the "mitgliederadd.php" as default page for all Userlevels

what I am doin wrong ?

THX


mobhar
User
Posts: 11702

Post by mobhar »

CurrentUserLevel() should return an Integer, and not String. Make sure the field type of your "UserLevel" in your "users" table is Integer, then synchronize your project, and change your code above.


dh1340
User
Posts: 58

Post by dh1340 »

THX this works :
// Page Redirecting event
function Page_Redirecting(&$url) {
// Example:
//$url = "your URL";
if (IsLoggedIn()) {
if (CurrentUserlevel() == 100) {
$url= "mitglieder_fussballlist.php";
} elseif (CurrentUserlevel() == 112) {
$url= "futsal_mitgliederlist.php";
} elseif (CurrentUserlevel() == 104) {
$url= "mitglieder_badmintonlist.php";
} else {
$url = "mitgliederadd.php";
} // <--- end of else
} // <--- end of IsLoggedIn
} // <--- end of Page_Redirecting


ampsys56
User
Posts: 21

Post by ampsys56 »

The redirection based on Userlevel seems to work fine based on posts by @dh1340 and @mobhar using v2022.12.2 , but what I'm not clear on is how the Home breadcrumb can link back to that dashboard for the session.

I've got users going to the right dash on login but no way to get them back and the Home breadcrumb (or Home Link on navbar) makes the most sense.

Any advice on how to accomplish this would be greatly appreciated - sorry for bumping an old thread. :)


mobhar
User
Posts: 11702

Post by mobhar »

ampsys56 wrote:

but what I'm not clear on is how the Home breadcrumb can link back to that dashboard for the session.

This was happened, since you define the Dashboard as your default page. This will cause the Home breadcrumb link will redirect to that Dashboard page. Please correct me if I'm wrong.


ampsys56
User
Posts: 21

Post by ampsys56 »

Yes, you're right. I was overthinking it.

I just needed to delete the declaration page on the 'Generate' Tab...leave it blank, let the code do the work.

Its funny - I was about ready to add a 'dashboard' column to userlevels... In the end this was all I had to do.

Thanks for your help.


Post Reply