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

    register auto logout?


    Number of posts : 37
    Registration date : 2009-04-11

    register auto logout?

    Post  intothefantasy on Mon Nov 09, 2009 2:12 pm

    i am currently creating a admin add user page where admin can add users by filling up forms like the register form but this time i use my own code for a simple change..

    but my problem is after successfuly added new current session automatically logout is my code


          $time = time();
          $username = $_POST['user'];
          $firstname = $_POST['name'];
          $pw = $_POST['pass'];
          $email = $_POST['email'];
          $userlevel = $_POST['addlevel'];
          $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
          $email = stripslashes($email);
          $firstname = stripslashes($firstname);
          $pw = stripslashes($pw);
          $username = stripslashes($username);
          if(!$username || strlen($username = trim($username)) == 0){
                echo "<font size=\"2\" color=\"#ff0000\">* Username not entered</font>";
            else if(strlen($username) < 5){
                echo "<font size=\"2\" color=\"#ff0000\">* Username below 5 characters</font>";
            else if(strlen($username) > 20){
                echo "<font size=\"2\" color=\"#ff0000\">* Username above 20 characters</font>";
            else if(!eregi("^([0-9a-z])+$", $username)){
                echo "<font size=\"2\" color=\"#ff0000\">* Username not alphanumeric</font>";
            else if(strcasecmp($username, GUEST_NAME) == 0){
                echo "<font size=\"2\" color=\"#ff0000\">* Username reserved word</font>";
            else if($database->usernameTaken($username)){
                echo "<font size=\"2\" color=\"#ff0000\">* Username already in use</font>";
            else if($database->usernameBanned($username)){
                echo "<font size=\"2\" color=\"#ff0000\">* Username banned</font>";
            echo "<br><font size=\"2\" color=\"#ff0000\">* Password not entered</font>";
            else if(strlen($pw) < 4){
                echo "<br><font size=\"2\" color=\"#ff0000\">* Password too short</font>";
            else if(!eregi("^([0-9a-z])+$", ($pw = trim($pw)))){
                echo "<br><font size=\"2\" color=\"#ff0000\">* Password not alphanumeric</font>";
            if(!$email || strlen($email = trim($email)) == 0){
            echo "<br><font size=\"2\" color=\"#ff0000\">* Email not entered</font>";
          else if(!eregi($regex,$email)){
                echo "<br><font size=\"2\" color=\"#ff0000\">* Email invalid</font>";
          $password = md5($pw);
          $query = "insert into users values('$username', '$password',0, $userlevel,'$email', '$firstname',$time)";
          $result = mysql_query($query) or die ('Could not add'.mysql_error());
          echo "success";
          echo "failed";


    <div class="title_box">Add User</div><br />
     <table border="0" cellpadding="0" cellspacing="0" width="100%">
     <td width="100%" valign="top" class="content_text">

    <form action="<?php echo $_SERVER[PHP_SELF] ?>" method="POST">
    <table align="left" border="0" cellspacing="0" cellpadding="3" class="content_text">
    <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value=""></td></tr>
    <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value=""></td></tr>
    <tr><td>Email:</td><td><input type="text" name="email" maxlength="50" value=""></td></tr>
    <tr><td>Level User:</td><td><select name="addlevel">
    <option value="1">Normal User
    <option value="7">Team K-THX-BAI
    <option value="8">Team Keyboard Warriors
    <option value="9">Admin
    <tr><td colspan="2" align="right">
    <input type="hidden" name="subjoin" value="1">
    <input type="submit" value="Add New User"></td></tr>
            <br />

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: register auto logout?

    Post  Linchpin311 on Sun Nov 15, 2009 11:51 am

    when you submit your form are you sending it to process.php (which would also send it to session.php)? if so im thinking that because when users register with register.php they are never logged in, and when that goes to session.php the current session is that of a guest (meaning the user name isnt saved anywhere in the session info). maybe this has something to do with why you are logged out after creating a user name.

    you may need to run a check in the register function of session.php to see if a user is logged in and then possibly send seperate instructions on what to do if this is true.

    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.

      Current date/time is Fri Jan 18, 2019 1:28 pm