Page 1 of 1

Php User login script

Posted: Fri Jan 02, 2009 10:58 am
by mtb211
I can not seem to find a freeware login script for php. I have created a database and I would like to use login software such as loginmanv3
but I can not seem to install it at the moment... anyone know of a good freeware software...

I would like a login php logout... and just something so clients can download files that I upload


thanks in advance!

Matt

Re: Php User login script

Posted: Fri Jan 02, 2009 11:49 am
by The_Anomaly

Re: Php User login script

Posted: Sat Jan 03, 2009 4:08 pm
by MichaelR
Here's a simple login script that I use:

Code: Select all

 
<?php
 
if (isset($_POST["submit"])) {
 
 $username = mysql_real_escape_string($_POST["username"]);
 $password = mysql_real_escape_string($_POST["password"]);
 
 $sql = "SELECT `id` FROM `users` WHERE `username` = '".$username."' AND `password` = '".$password."' LIMIT 1";
 
 $result = mysql_fetch_array(mysql_query($sql));
 
 if (empty($result["id"]))
  header("Location: index.php");
 
 else {
 
  session_start();
 
  $_SESSION["id"] = $result["id"];
 
  header("Location: main.php");
 
 }
 
}
 
?>
 
And for a logout script (note: it assumes that any non-logged-in user who tries to access this page must be redirected to the index page):

Code: Select all

 
<?php
 
 session_start();
 
 if (isset($_SESSION["id"]))
  session_destroy();
 
 header("Location: index.php");
 
?>