PHP
  Home arrow PHP arrow Page 3 - Filters and Login Systems for Web Application Security
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Filters and Login Systems for Web Application Security
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2008-10-06


    Table of Contents:
  • Filters and Login Systems for Web Application Security
  • Definition and Storage File
  • The Login page
  • The code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Filters and Login Systems for Web Application Security - The Login page
    ( Page 3 of 4 )

    The login page is the main entrance to our site. Any user that wants to use our site needs to be authenticated by this script. We want only users that have registered to be allowed in, so we filter out those that are not registered through this script.

    <?

    session_start();

    //someone registered?

    if(isset($_GET['reg'])){

    $reg="Your details have been added, please login";

    }

    $error=false;

    $errmsg="";


    //has form been submitted

    if(isset($_POST['key'])){

    //check that the username and password is not empty

    if( empty($_POST['uname']) && (empty($_POST['upass']))){

    print "Please enter your username and password.";

    $errmsg="Please enter your username and password.";

    $error=true;

    }

    //check that the username and password is string

    if( is_numeric($_POST['uname']) && (is_numeric($_POST['upass']))){

    print "Please enter a valid username and password.";

    $errmsg=" Please enter a valid username and password.";

    $error=true;

    }

    //if no error then start authentication process

    if(!$error){


    //transfer to shorter var

    $n=$_POST['uname'];

    $p=$_POST['upass'];


    //if no error then start authentication process


    //connect to db

    include('../config.inc');

    //clean using mysql cleaner

    $cleanuname=mysql_real_escape_string($n);

    $cleanupass=mysql_real_escape_string($p);

    $query="select uname,pw from users where uname='$cleanuname' and pw='$cleanupass' ";

    $result=mysql_query($query);


    $num=mysql_num_rows($result);

    if($num>0 ){


    //put in session vars

    session_start();

    $mytime=time();

    $mytime=date("H:i:s A",$mytime);

    $_SESSION['time'] = $mytime;

    $_SESSION['status'] = 'logged';

    $_SESSION['username'] = $cleanuname;

    //goto next page

    header("location:welcome.php");

    exit;

    }

    }else{

    $_SESSION['status'] = 'not logged';

    $errmsg="Your username ($n) and password do not match, please try again.";

    }

    }

    ?>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/primary/Templates/was.dwt.php" codeOutsideHTMLIsLocked="false" -->

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <!-- InstanceBeginEditable name="doctitle" -->

    <title>WebSecure::Login</title>

    <!-- InstanceEndEditable -->

    <!-- InstanceBeginEditable name="head" -->

    <!-- InstanceEndEditable -->

    <link href="Templates/was.css" rel="stylesheet" type="text/css" />


    <script language="javascript" type="text/javascript">

    function checkform(pform1){

    if(pform1.uname.value==""){

    alert("Please enter a username")

    pform1.uname.focus()

    return false

    }


    if(pform1.pw.value==""){

    alert("Please enter a password")

    pform1.pw.focus()

    return false

    }


    if(pform1.pw.value=="" && pform1.uname.value==""){

    alert("Please make sure that you have entered your username and password")

    return false

    }

    return true

    }

    </script>

    </head>


    <body>

    <table width="99%" border="1">

    <tr>

    <td bgcolor="#333333" class="header">Web Secure</td>

    </tr>

     

     

    <tr>

    <td><!-- InstanceBeginEditable name="main" -->

    <form name="form1" onSubmit="return checkform(this)" method="post" action="">

    <table width="41%" border="0" align="center" cellpadding="0" cellspacing="3">

    <tr class="listtop">

    <td colspan="3">Login Status:<? if(isset($msg)){

    echo "$msg";

    }elseif(isset($reg)){

    echo "$reg";

    }?></td>

    </tr>

    <tr>

    <td width="9%">Username</td>

    <td width="41%"><input name="uname" type="text" id="uname" size="50"></td>

    <td width="50%" rowspan="4">&nbsp;</td>

    </tr>

    <tr>

    <td>Password</td>

    <td><input name="upass" type="text" id="upass" size="50">

    <input type="hidden" name="key" /></td>

    </tr>

    <tr>

    <td>&nbsp;</td>

    <td><a href="../password.php">Forgotten your password?</a>|<a href="register.php">Register</a></td>

    </tr>

    <tr>

    <td>&nbsp;</td>

    <td><input type="submit" name="Submit" value="Login"></td>

    </tr>

    </table>

    </form>

    <!-- InstanceEndEditable --></td>

    </tr>

    <tr>

    <td class="copy">&copy;2008</td>

    </tr>

    </table>

    </body>

    <!-- InstanceEnd --></html>



     
     
    >>> More PHP Articles          >>> More By David Web
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT