therecluse26 / PHP-Login

A login system built with PHP, MySQL, jQuery and Bootstrap
MIT License
839 stars 444 forks source link

Defining roles and the pages they get redirected to #199

Open dbavosi opened 6 years ago

dbavosi commented 6 years ago

I'm trying to set up a few different roles for users, various roles for standard users. When 1 type of new role logs in, I would like them to see a different page. There are pages, like page_2, page_3, etc... which is nice, but how do I attach roles to new pages so I can create page_6, page_7 and so on?

therecluse26 commented 6 years ago

You’d want to use the $auth object that’s spawned in the pagehead file on page load and use the “hasRole” method. This returns true or false based on if the current user has the method that you pass it. From there you can redirect (or conditionally display content or whatever else you want) based on if it’s true or false.

Sent with GitHawk

dbavosi commented 6 years ago

Interesting. I'm trying that. In the mean time, when a user logs in, they click the login button, and get looped back to /login/index.php, but shouldn't it go to /index.php without the login? The user's session is valid and can navigate by the menu, it's just the login process. Where does that get set? I checked my DB and the base URL there is correct.

therecluse26 commented 6 years ago

I've never had it loop back to the login page, and I'm unable to replicate the problem myself now. Could you list out the steps for me that you go through to cause that to happen?

dbavosi commented 6 years ago

I go to the login page, log in and it loops back to the login page. The URL doesn't change, but the top nav bar shows me logged in.

therecluse26 commented 6 years ago

What webserver are you running? Also, what operating system/version?

All I can think off of the top of my head is some sort of configuration issue with your webserver or redirect rule messing things up. The PHP script is set to automatically redirect to the homepage if the login page is accessed while the user is already logged in.

dbavosi commented 6 years ago

It's a shared linux box. Kinda all I can dig up from the cpanel. Composer barely ran on my machine to set up the vendor file. I had to pull in the jquery and the bootstap css files manually. I

dbavosi commented 6 years ago

Also, thank you for your help here! It is truly appreciated!

therecluse26 commented 6 years ago

Ah, I hate those shared servers, honestly. They always seem to cause all kinds of weird problems, and you have no control over the underlying system to solve them. Have you thought about using a cheap VPS provider instead like vultr or digitalocean? I'd highly recommend going for one of those over a shared hosting service.

therecluse26 commented 6 years ago

No problem! Happy to help! Good luck to you :)

On Mon, Jun 18, 2018 at 1:51 PM, d_diddy notifications@github.com wrote:

Also, thank you for your help here! It is truly appreciated!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/therecluse26/PHP-Login/issues/199#issuecomment-398139828, or mute the thread https://github.com/notifications/unsubscribe-auth/AH24AsrJobN7WdS7iFpcgeOOiEba1lvQks5t9-itgaJpZM4Uol3D .

uomopalese commented 6 years ago

HI, I'm facing the same problem here, after login i'm still on the /login/index.php istead of /index.php. Any idea? Thanks schermata-2018-08-13-alle-12 31 43 z