The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect After Login based on Username
#1
Photo 
I need to redirect after login based on user name ?
Let's say if user John log in he would be redirected to /john/index.php if 
User Michael log in he would be redirected to /micahel/index.php
  Reply
#2
Sure no problem. In users/scripts there is a file called custom_login_script.php

In there just put Redirect::to($us_url_root.$user->data()->username."index.php");

I'm on my phone so if that is not it it is pretty close
  Reply
#3
thank you, so it does work only for 1 user. here what I did..

Redirect::to($us_url_root.$user->data()->admin."101/index.php");
Redirect::to($us_url_root.$user->data()->Steven."calendar/");

so if I log in with admin it redirect to correct page, if log in with Steve it take to admin page not to calendar/
  Reply
#4
can someone help me with this issue/project
  Reply
#5
Ok. So let me make sure I understand. So let's say your project is at https://example.com.

If you want to direct the user named steven to a folder that is at https://example.com/steven

Then you would probably want to first make sure that everything is lowercase, so maybe you would do...
$url = strtolower($user->data()->username);

Note that if you go into the database, then username is the COLUMN in the database in the users table. That's where the information is coming from.

So to redirect to https://example.com/steven if steven is the username then you would do
Redirect::to($us_url_root.$url);

This is because $us_url_root already has the / at the end.
if you want to do something beyond that, like calendar you can definitely just add something to the end of the url.

So one more thing. This requires you to create a custom folder for every single user. Normally with php, people will have one calendar.php file and just load the information of the logged in user. Is there any particular reason of why you want to do it this way?
  Reply
#6
so you previous code worked kind of.
this is what I have

1. Redirect::to($us_url_root.$user->data()->id->admin. "101/index.php")   ;
2. Redirect::to($us_url_root.$user->data()->id->Steven."calendar/");

BUT
no matter what user I use to log in,  ether admin or Steven it takes me to 101/index.php , it doesn't recognize username and redirects to proper page.
Basically I want to redirect multiple use to their own homepages.
  Reply
#7
Can you explain what admin and Steven are?
are they pages or folders? How does the id fit into it? Are you using the id in the foldername?
  Reply
#8
admin and Steve are usernames.
  Reply
#9
Ok. So....
1. Redirect::to($us_url_root.$user->data()->id->admin. "101/index.php") ;
will redirect you to something that doesn't exist because $user->data()->id->admin doesn't exist. I also don't know what the 101 is

If you are trying to get a user named admin to go to a link like mydomain.com/admin101/index.php that is
Redirect::to($us_url_root.$user->data()->username. "101/index.php") ;

If you just want him to go to mydomain.com/admin/index.php that is
Redirect::to($us_url_root.$user->data()->username. "/index.php") ;


2. Redirect::to($us_url_root.$user->data()->id->Steven."calendar/");
if you are trying to redirect a user named steven to mydomain.com/Steven/calendar that is
Redirect::to($us_url_root.$user->data()->username. "/calendar") ;

$user->data()->username will output the username of the logged in user, so you don't need to type it out.
  Reply
#10
ok so username. = user that just logged in..

what I am trying to accomplish ::> 
  if user= admin log in send to to x.html
 if user = Steven send him to w.html 
if user = Alex send him to 564.html ?
  Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)