]> git.ozlabs.org Git - ccan/blob - web/login.php
tdb: use tdb_nest_lock() for transaction lock.
[ccan] / web / login.php
1 <?php
2 session_start(); // start session.
3 include('configuration');
4
5 if($_SESSION['slogged'] != ''){
6         include('logo.html');
7         include('menulist.html');
8         echo "<br><div align=\"center\">Already logged in as ".$_SESSION['susername']."...</div>";
9         exit();
10 }
11
12 if(!isset($_POST['submit'])) {
13         include('logo.html');
14         include('menulist.html');
15         loginhtml("Members only. Please login to access.");
16         exit();
17 }
18
19 // get username and password
20 $username = $_POST['username'];
21 $password = $_POST['password'];
22
23 // register username and logged as session variables.
24 session_register("susername");
25 session_register("slogged"); 
26
27 //set session variables
28 $_SESSION["susername"] = $username;
29 $_SESSION["slogged"] = false;
30
31 // open database file
32 $handle = sqlite3_open($db) or die("Could not open database");
33 // query string
34 $query = "SELECT * FROM login where username=\"$username\"";
35 // execute query
36 $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
37 // if rows exist
38 if (($row = sqlite3_fetch_array($result)) != '') { 
39         if(md5($password) == $row["password"])
40                 $valid_user = 1;
41 }
42 else {
43 $valid_user = 0;
44 }
45
46 //if not valid user
47 if (!($valid_user)) {
48         // Unset session variables.
49         session_unset();   
50         include('logo.html');
51         include('menulist.html');
52         loginhtml("Incorrect login information, please try again. You must login to access.");
53         exit();
54 }
55
56 //if valid user
57 else {
58         $referer = $_GET['referer'];
59         $_SESSION["slogged"] = true;
60         if($referer != '') {
61                 header('Location: '.$referer);
62                 exit();
63         }       
64         include('logo.html');
65         include('menulist.html');
66         echo "<br><div align=\"center\">Logged in sucessfully...<//div><//body><//html>";
67 }
68
69
70
71 function loginhtml($info)
72 {
73 ?>
74 <form action="<?=$PHP_SELF.$referer?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
75 <p align="center"><?=$info?></p>
76 <table align="center" border="0">
77  <tr>
78   <th>
79 Username:
80   </th>
81   <th>
82 <input type="text" name="username">
83   </th>
84  </tr>
85  <tr>
86   <th>
87 Password:
88   </th>
89   <th>
90 <input type="password" name="password">
91   </th>
92  </tr>
93  <tr>
94   <th colspan="2" align="right">
95 <input type="submit" name="submit" value="Login">
96 </form>
97   </th>
98  </tr>
99 </table><hr>
100 </body>
101 </html>
102 <?php
103 }
104 ?>
105