|
10 | 10 | if(loggedin()) |
11 | 11 | header("Location: index.php"); |
12 | 12 | else if(isset($_POST['action'])) { |
13 | | - $username = mysql_real_escape_string($_POST['username']); |
| 13 | + $username = array_key_exists('username', $_POST) ? trim($_POST['username']) : null; |
14 | 14 | if($_POST['action']=='login') { |
15 | | - if(trim($username) == "" or trim($_POST['password']) == "") |
| 15 | + if(trim($username) == "" or trim($_POST['password']) == ""){ |
16 | 16 | header("Location: login.php?derror=1"); // empty entry |
| 17 | + } |
17 | 18 | else { |
18 | 19 | // code to login the user and start a session |
19 | 20 | connectdb(); |
|
29 | 30 | } |
30 | 31 | } else if($_POST['action']=='register') { |
31 | 32 | // register the user |
32 | | - $email = mysql_real_escape_string($_POST['email']); |
33 | | - if(trim($username) == "" or trim($_POST['password']) == "" or trim($email) == "") |
34 | | - header("Location: login.php?derror=1"); // empty entry |
| 33 | + //$email = mysql_real_escape_string($_POST['email']); |
| 34 | + $username = array_key_exists('username', $_POST) ? trim($_POST['username']) : null; |
| 35 | + $email = array_key_exists('email', $_POST) ? trim($_POST['email']) : null; |
| 36 | + if(trim($username) == "" and trim($_POST['password']) == "" and trim($email) == ""){ |
| 37 | + header("Location: login.php?derror=1"); // empty entry\ |
| 38 | + } |
35 | 39 | else { |
36 | 40 | // create the entry in the users table |
37 | 41 | connectdb(); |
|
42 | 46 | else { |
43 | 47 | $salt = randomAlphaNum(5); |
44 | 48 | $hash = crypt($_POST['password'], $salt); |
45 | | - $sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('".$username."', '$salt', '$hash', '".$email."')"; |
| 49 | + $sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email`, `status` ) VALUES ('".$username."', '$salt', '$hash', '".$email."', '1')"; |
46 | 50 | mysql_query($sql); |
47 | 51 | header("Location: login.php?registered=1"); |
48 | 52 | } |
|
0 commit comments