PHP Code:
<?php $mysql = @mysql_connect( "localhost", "yourserverusername", "yourserverpassword" ); @mysql_select_db( "my_db" ); $user = $_POST['username']; $pass = sha1( $_POST['password'] ); $ref = $_SERVER['HTTP_REFERER']; //check db for these values $sql = "SELECT * FROM my_table WHERE username = '$user'"; $query = mysql_query( $sql ); $result = mysql_fetch_array( $query ); if( $result['password'] == $pass ) // if it returned with a result { session_start(); //assign session data to mysql data $_SESSION['username'] = $user; $_SESSION['password'] = $pass; $_SESSION['author'] = $result['forename']." ".$result['surname']; header( "location:".$ref ); } else { header( "incorrect.php" ); //if not correct send user here. } ?>
what this does is check if theyre is a user on the database and if theyre is a matching username & password combination it starts a session. NOTE:: this script is vulnerable and you should be escaping the variables and adding salt to your passwords but for the purpose i just did this script and you should know a little PHP if your posting here so thats why i left out security just do a search on the forum and youll find out how toincrease security.
__________________
My webmaster news & tips blogs with free scripts and tutorials - Please login or register to view this content. Registration is FREE
|