Results 1 to 10 of 10

Thread: Fix for logged in users

  1. #1
    mpdaddy is offline Active Member
    Join Date
    Nov 2007
    Posts
    227

    Default Fix for logged in users

    This is my fix for the issue I brought up at Bug? Should it work this way?.

    This code fixes it so that when a user is logged into IndexU,
    if they access either the login.php or register.php page, they will be redirected to the index.php page.

    Fixing this issue involves some minor modifications to the login.php and register.php files.

    Open login.php and replace the following function:

    Code:
      function ShowFormLogin() {
    
        // vars global configuration
        global $theme_path;
    
        // vars url & form
        global $f, $b;
    
        // vars template
        global $error_msg;
    
        if ($f == 1)
          DisplayTemplate($theme_path . "permission_error.html", "\$error_msg,\$username,\$password,\$f,\$b");
        else
          DisplayTemplate($theme_path . "login_form.html", "\$error_msg,\$username,\$password,\$f,\$b");
      }
    With this:

    Code:
      function ShowFormLogin() {
    
        // vars global configuration
        global $theme_path;
    
        // vars url & form
        global $f, $b;
    
        // vars template
        global $error_msg;
    
      $users_obj = new clsUsers;
    
      if ($users_obj->GetUserAuthentication() == 0) {
    
        if ($f == 1)
          DisplayTemplate($theme_path . "permission_error.html", "\$error_msg,\$username,\$password,\$f,\$b");
        else
          DisplayTemplate($theme_path . "login_form.html", "\$error_msg,\$username,\$password,\$f,\$b");
    }
      else {
    	    Redirect("index.php");
        }
    }

    Now open register.php and replace the following function:


    Code:
      function ShowFormRegister() {
    
        // vars global configuration
        global $theme_path;
    
        // vars template
        global $error_msg;
    
        DisplayTemplate($theme_path . "register_form.html", "\$error_msg,\$username,\$password,\$password2,\$email");
      }

    With this:

    Code:
      function ShowFormRegister() {
    
        // vars global configuration
        global $theme_path;
    
        // vars template
        global $error_msg;
    
      $users_obj = new clsUsers;
    
      if ($users_obj->GetUserAuthentication() == 0) {
    
        DisplayTemplate($theme_path . "register_form.html", "\$error_msg,\$username,\$password,\$password2,\$email,\$logged_in");
      }
      else {
    	    Redirect("index.php");
        }
    }
    Thats all there is to it.

    You can download the login.php and register.php files for free along with the instructions in zip format at http://store.scriptdragon.com/viewitem.php?ItemID=8

    Wayne
    For questions related to any mods I developed, please contact me by pm or email at webmaster [at] scriptdragon [dot] com

  2. #2
    esm's Avatar
    esm
    esm is offline Active Member
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    is Redirect a standard php function?


    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  3. #3
    esm's Avatar
    esm
    esm is offline Active Member
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    another way to do it is to add the following just after the first line <?php in the register.php and login.php files

    PHP Code:
    $url="index.php";
    if (
    $_COOKIE['COOKIE_USER_AUTHENTICATED'])
    {
      if(!
    headers_sent()) 
      { 
        
    header("Location: "$url); 
        exit; 
      } else {

      
    // otherwise, try to redirect with javascript 
      
    echo 
      
    "<script language='javascript'>\n"
      
    "document.location.href='".$url."';\n"
      
    "</script>\n"
        exit;
      }

    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  4. #4
    mpdaddy is offline Active Member
    Join Date
    Nov 2007
    Posts
    227

    Default

    Quote Originally Posted by esm View Post
    is Redirect a standard php function?


    .
    No the php way is with the header() way you did it. I just used the redirect function found in misc.lib.php. Either way it works.

    As Bruce said

    Mods have never really been added to the base code just because they were submitted as far as I know. It's probably easier for Dody to write the code and add it himself than it is to try and incorporate someone else's code.
    My intention was to get it included in the core code. I tried to write it as Dody would using his built in functions. The redirect code is actually used farther down in the login.php file. I truly think this is the way the script should work right out of the box. We should not have to fix it.

    What site have you ever been to that allows you to re-register when you are already logged in?

    What site lets you re-login when you are already logged in?
    For questions related to any mods I developed, please contact me by pm or email at webmaster [at] scriptdragon [dot] com

  5. #5
    esm's Avatar
    esm
    esm is offline Active Member
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    well, dody may end up doing it that way.

    But I would remove the register button by wrapping an IF statement around it in the header file and modify the DisplayTemplate function. But that would mean the DisplayTemplate function would need to be modified in several files.

    Is the login box still there after you login? I thought it just showed you status as logged in with a link to logout...?



    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  6. #6
    Bruceper is offline Active Member
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    I did that with my ICE theme, so that when a user logs in the register link is hidden. Of course the page is still there, but most users wouldn't go hunting for it.

  7. #7
    echo@'s Avatar
    echo@ is offline Active Member
    Join Date
    Oct 2007
    Location
    UK Essex
    Posts
    591

    Default

    good idea, shame it doesnt work.

    modified the files acordingly and now im just redirected regardless if im logged in or not.

    I must of missed something , running indexu 5.4,

    Whats happed to your mods site ??

  8. #8
    mpdaddy is offline Active Member
    Join Date
    Nov 2007
    Posts
    227

    Default

    Quote Originally Posted by echo@ View Post
    good idea, shame it doesnt work.

    modified the files acordingly and now im just redirected regardless if im logged in or not.

    I must of missed something , running indexu 5.4,

    Whats happed to your mods site ??
    After the whole upgrade issue was botched, and I found out some information about John Milton and his company that I am not comfortable with (unconfirmed or I would post it) , I decided that IndexU was not the right script for me. I took the site down and have moved on to another venture, which I am sure you will hear about in the next couple months.

    I am currently updating my mods, but finding it difficult working with the plugin system. I will release the free ones when I get them finished and I am not sure what will happen to the pay ones yet. I might turn them over to somebody else to support. I will let you know when I figure it out.

    The code worked on my server, but I may have left something out. I put it together pretty fast and may have missed some code. This is a slight modification of what esm posted and it workes great. The only thing I changed was $_COOKIE['COOKIE_USER_AUTHENTICATED'] should have been $_COOKIE['COOKIE_USERNAME']. Add it to the top of your login.php and register.php just after the <?php tag at the top. Here it is...

    PHP Code:
    $url="index.php";
    if (
    $_COOKIE['COOKIE_USERNAME']) {
      if(!
    headers_sent()) {
        
    header("Location: "$url);
        exit;
      } else {

      
    // otherwise, try to redirect with javascript
      
    echo
      
    "<script language='javascript'>\n".
      
    "document.location.href='".$url."';\n".
      
    "</script>\n";
        exit;
      }

    Regards
    Wayne
    For questions related to any mods I developed, please contact me by pm or email at webmaster [at] scriptdragon [dot] com

  9. #9
    echo@'s Avatar
    echo@ is offline Active Member
    Join Date
    Oct 2007
    Location
    UK Essex
    Posts
    591

    Thumbs down what a shame

    ...............
    Last edited by echo@; 07-06-2008 at 05:53 PM.

  10. #10
    esm's Avatar
    esm
    esm is offline Active Member
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    Quote Originally Posted by mpdaddy View Post
    After the whole upgrade issue was botched, and I found out some information about John Milton and his company that I am not comfortable with (unconfirmed or I would post it) , I decided that IndexU was not the right script for me.

    Regards
    Wayne
    I agree.


    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

Similar Threads

  1. my Users
    By SKh in forum v5.x
    Replies: 0
    Last Post: 04-13-2007, 03:32 AM
  2. Logged users only
    By beto in forum v5.x
    Replies: 3
    Last Post: 12-21-2006, 07:59 PM
  3. xxx users online
    By landuyt in forum v5.x
    Replies: 2
    Last Post: 02-21-2005, 08:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •