PHP Login System with Admin Features

Would you like to react to this message? Create an account in a few clicks or log in to continue.
PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


2 posters

    Redirect After Login...

    avatar
    dubLeE


    Number of posts : 10
    Registration date : 2009-02-16

    Redirect After Login... Empty Redirect After Login...

    Post  dubLeE Mon Feb 16, 2009 7:39 pm

    I am pretty sure I did everything correctly since have it works and other half does not. I wanted to setup the script so that when the user logs in, it redirects to a specific page such as user1 goes to user1.php, user2 goes to user2.php, and so on. I only need 10 users and 1 admin for this project. Now to do this I did the following:

    Edited constants.php proclogin() so that it now looks like this:
    Code:

          /* Login successful */
          if($retval){
            if(strcmp($session->username, "team1") == 0){
               header("Location: team1.php");
            }
            if(strcmp($session->username, "team2") == 0){
               header("Location: team2.php");
            }
            if(strcmp($session->username, "team3") == 0){
               header("Location: team3.php");
            }
            else{
               header("Location: ".$session->referrer);
            }
          }

    And everything works sort of works except team1 does not redirect to team1.php (it goes to the default page, main.php), however team2 and team3 do redirect to their specified pages. I can't figure out why team2 and team3 redirect but team1 does not.

    Also, if add another user redirect so that it looks like this:
    Code:

          /* Login successful */
          if($retval){
            if(strcmp($session->username, "team1") == 0){
               header("Location: team1.php");
            }
            if(strcmp($session->username, "team2") == 0){
               header("Location: team2.php");
            }
            if(strcmp($session->username, "team3") == 0){
               header("Location: team3.php");
            }
            if(strcmp($session->username, "team4") == 0){
               header("Location: team4.php");
            }
            else{
               header("Location: ".$session->referrer);
            }
          }

    It totally stops working, and nothing redirects and they all go to the main.php default page. Seems like it can't handle more than 3 (or maybe 2) redirects this way?
    I've been pulling my hair out this and just can't seem to wrap my head around why this is not working! Any help at all is greatly appreciated!

    Thank you!
    avatar
    dubLeE


    Number of posts : 10
    Registration date : 2009-02-16

    Redirect After Login... Empty Re: Redirect After Login...

    Post  dubLeE Mon Feb 16, 2009 9:22 pm

    sorry about that! when i wrote it, i was using user1 and user 2 but in my actual code im using team 1 and team2 and so one. user = team. Sorry about the confusion!

    This might be easier...

    I am pretty sure I did everything correctly since have it works and other half does not. I wanted to setup the script so that when the user logs in, it redirects to a specific page such as user1 goes to user1.php, user2 goes to user2.php, and so on. I only need 10 users and 1 admin for this project. Now to do this I did the following:

    Edited constants.php proclogin() so that it now looks like this:
    Code:
          /* Login successful */
          if($retval){
            if(strcmp($session->username, "user1") == 0){
              header("Location: user1.php");
            }
            if(strcmp($session->username, "user2") == 0){
              header("Location: user2.php");
            }
            if(strcmp($session->username, "user3") == 0){
              header("Location: user3.php");
            }
            else{
              header("Location: ".$session->referrer);
            }
          }
    And everything works sort of works except user1 does not redirect to user1.php (it goes to the default page, main.php), however user2 and user3 do redirect to their specified pages. I can't figure out why user2 and user3 redirect but user1 does not.

    Also, if add another user redirect so that it looks like this:
    Code:
          /* Login successful */
          if($retval){
            if(strcmp($session->username, "user1") == 0){
              header("Location: user1.php");
            }
            if(strcmp($session->username, "user2") == 0){
              header("Location: user2.php");
            }
            if(strcmp($session->username, "user3") == 0){
              header("Location: user3.php");
            }
            if(strcmp($session->username, "user4") == 0){
              header("Location: user4.php");
            }
            else{
              header("Location: ".$session->referrer);
            }
          }
    It totally stops working, and nothing redirects and they all go to the main.php default page. Seems like it can't handle more than 3 (or maybe 2) redirects this way?
    I've been pulling my hair out this and just can't seem to wrap my head around why this is not working! Any help at all is greatly appreciated!

    Thank you!
    Admin
    Admin
    Admin


    Number of posts : 18
    Registration date : 2007-05-12

    Redirect After Login... Empty Re: Redirect After Login...

    Post  Admin Mon Feb 16, 2009 9:35 pm

    You have forget to write else if statement.


    /**
    * procLogin - Processes the user submitted login form, if errors
    * are found, the user is redirected to correct the information,
    * if not, the user is effectively logged in to the system.
    */
    function procLogin(){
    global $session, $form;
    /* Login attempt */
    $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));

    /* Login successful */
    if($retval){
    if(strcmp($session->username, "team1") == 0) header("Location: team1.php");
    elseif(strcmp($session->username, "team2") == 0) header("Location: team2.php");
    elseif(strcmp($session->username, "team3") == 0) header("Location: team3.php");
    elseif(strcmp($session->username, "team4") == 0) header("Location: team4.php");
    elseif(strcmp($session->username, "team5") == 0) header("Location: team5.php");
    else header("Location: ".$session->referrer);
    }
    /* Login failed */
    else{
    $_SESSION['value_array'] = $_POST;
    $_SESSION['error_array'] = $form->getErrorArray();
    header("Location: ".$session->referrer);
    }
    }
    avatar
    dubLeE


    Number of posts : 10
    Registration date : 2009-02-16

    Redirect After Login... Empty Re: Redirect After Login...

    Post  dubLeE Tue Feb 17, 2009 3:38 am

    WoW! That did the trick! Works great!

    One more thing I want to add is have each page protected such that only a specified user can see that page. If user1 goes to user1.php, he can see the content however, if user2 goes to user1.php, he cannot see it.

    I tried setting this up by adding the following code to the pages but this does not allow HTML within the php tags:
    Code:
    <?
    if(strcmp($session->username, "user1") == 0){
      echo "You are allowed to view this page";
    }
    else{
      echo "User2, you are NOT allowed to view this page";
    }
    ?>

    I was also successfully able to protect the pages so that only signed in users could see it but I want to take a step further.

    I protected the pages with:
    Code:
    <html>
    <?
    /* User is not logged in */
    if(!$session->logged_in){
    ?>

    <body>
    HTML stuff here which guest (not signed in user) can see
    </body>

    <?
    }
    /* User is logged in */
    else{
    ?>
    <body>
    HTML stuff that signed in users can see here
    </body>

    <?
    }
    ?>

    </html>

    I want to be able to only allow only the user to see that page however, I need to be able to add HTML within the php tags as well.

    Thanks!
    Admin
    Admin
    Admin


    Number of posts : 18
    Registration date : 2007-05-12

    Redirect After Login... Empty Re: Redirect After Login...

    Post  Admin Tue Feb 17, 2009 10:55 am

    Code:
    <?include("include/session.php")?>
    <html>
    <head>
    <title></title>

    </head>

    <body>
    <?
       if($session->logged_in && strcmp($session->username, "user1") == 0){
             print 'display the content';
          } else {
             print 'you cannot view this page.';
          }
    ?>
    </body>
    </html>
    avatar
    dubLeE


    Number of posts : 10
    Registration date : 2009-02-16

    Redirect After Login... Empty Re: Redirect After Login...

    Post  dubLeE Tue Feb 17, 2009 11:51 am

    WORKED LIKE A CHARM!
    Thank you so much!!!
    Admin
    Admin
    Admin


    Number of posts : 18
    Registration date : 2007-05-12

    Redirect After Login... Empty Re: Redirect After Login...

    Post  Admin Tue Feb 17, 2009 2:10 pm

    dubLeE wrote:WORKED LIKE A CHARM!
    Thank you so much!!!

    Your welcome

    Sponsored content


    Redirect After Login... Empty Re: Redirect After Login...

    Post  Sponsored content


      Current date/time is Fri May 17, 2024 3:45 am