Results 1 to 3 of 3

Thread: PHP Login Scripts

  1. #1
    Join Date
    Jul 2003
    Posts
    424
    Rep Power
    0

    Default PHP Login Scripts

    Does anyone have a reusable PHP Login scripts to spear. I changed Intranet server operating system from windows NT to Linux Redhat - I use to authenticate using an ASP script but as you know that willnot work here.

    Help Please.

    Thanx

  2. #2
    Join Date
    Jul 2002
    Posts
    818
    Rep Power
    0

    Default Re:PHP Login Scripts

    Code:
    <?
    session_unregister("valid_user");
    session_unregister("valid_id");
    $valid_user = "";
    $valid_id = ""; 
    ?>
    
    <CENTER>Please select your username and enter your password then click <I><B>"Enter"</B></I></CENTER>
    
    <TABLE WIDTH="100%">
       <TR>
          <TD WIDTH="100%" HEIGHT=300 ALIGN="Center" VALIGN="Center">
    <FORM ACTION="<?=$PHP_SELF?>" METHOD="Post">
    <TABLE BGCOLOR="#CCCCFF">
       <TR>
          <TD>
          <B>Username:<B>
          </TD>
          <TD>
          <SELECT NAME="Username">
          <OPTION VALUE=""></OPTION>
          <?
          $query = "select * from users";
          $result = mysql_query($query);
          ?>
          <?
          mysql_data_seek($result, 0);
          while ($rows=mysql_fetch_row($result))
          {
             $name = $rows[1];
             $value = $rows[0] . "|" . $name;
             echo "<OPTION VALUE='" . $value . "'>" . $name . "</OPTION>\n";
          }
          ?>
          </SELECT>
          </TD>
       </TR>
    
       <TR>
          <TD>
          <B>Password:</B>
          </TD>
          <TD>
          <INPUT TYPE="Password" NAME="Password">
          </TD>
       </TR>
       <TR>
          <TD COLSPAN=2 ALIGN="Center">
          <INPUT TYPE="Submit" NAME="Enter" VALUE="Enter">
          </TD>
       </TR>
    </TABLE>
    </FORM>
          </TD>
       </TR>
    </TABLE>
    
    
    <CENTER>If you have problems logging in please contact your <A HREF="mailto:admin@yourcompany.com">System Administrator</A></CENTER>
    
    <?
    if ($Username){
       $info = explode ("|", $Username);
    
       $id = $info[0];
       $valid_id = $id;
       $valid_user = $info[1];
       $id = "'" . $id . "'";
       If ($Password == "") $Password = "null"; else $Password = "'" . $Password . "'";
    
       $query = "select count(*) from users where user_id = $id and password = $Password";
       $result = mysql_query($query) or die(mysql_error());
    
    
       $rows = mysql_fetch_array($result);
    
       if ($rows[0] == 1)
       {
          session_register("valid_user");
          session_register("valid_id");
          ?>
             <SCRIPT LANGUAGE="Javascript">
             window.location = "menu.php"
             </SCRIPT>
          <?
       }
    }
    ?>

    The above code is a butchered version of a basic login script I made for use in my office. It assumes a tabke called users with filelds for name, id, password, etc. (You'd probably use a hash for your passwords.)

    Upon entering a correct password, it stores values in two session variables: valid_user and valid_id. These are used for displaying the user currently logged in and to log user actions respectively.

  3. #3
    Join Date
    Jul 2003
    Posts
    424
    Rep Power
    0

    Default Re:PHP Login Scripts

    Thanks much, will definetly try this and let you know.

Posting Permissions

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