Emirnop
Emirnop

Reputation: 43

PHP redirect user to personal page

I want to redirect a user to specific page with their user name (which will I manually create) so when user2 logs in it will redirect them to user2.php, when user1 logs in it will redirect them to user1.php. I will manualy create the user page from their username after registering.

This is what I use but it redirects every user to the same page (except admin)

if ( IsUserConnected() ) {
    if (IsUserAuthorized($_SESSION['username'])) {
        header('Location: /username.php');
    }
}

Upvotes: 1

Views: 153

Answers (3)

Alireza Fallah
Alireza Fallah

Reputation: 4607

you are redirecting all users to username.php .

Do this instead :

if ( IsUserConnected() ) {
    if (IsUserAuthorized($_SESSION['username'])) {
        header('Location:/'.$_SESSION['username'].'.php');
  }

}

Upvotes: 2

Jasper
Jasper

Reputation: 168

You probably want to change the third line to

header("Location: /path/" . $_SESSION['username'] . ".php");

Upvotes: 0

Krish R
Krish R

Reputation: 22721

Try this, Added header('Location: /'.$_SESSION['username'].'.php');

if ( IsUserConnected() ) {
    if (IsUserAuthorized($_SESSION['username'])) {
        header('Location: /'.$_SESSION['username'].'.php');
        exit();
    }   
}

Upvotes: 0

Related Questions