22 return $ID; |
22 return $ID; |
23 |
23 |
24 } |
24 } |
25 function create_session($mysql, $uid, $password) |
25 function create_session($mysql, $uid, $password) |
26 { |
26 { |
|
27 |
27 // |
28 // |
28 // Build list of existing SIDs |
29 // Build list of existing SIDs |
29 // |
30 // |
30 $result = $mysql->query("SELECT sid FROM sessions"); |
31 $result = $mysql->query("SELECT sid FROM sessions"); |
31 $num_rows = $result->num_rows; |
32 $num_rows = $result->num_rows; |
52 // |
53 // |
53 // Create the session: set the UID and SID in both the client's cookies and |
54 // Create the session: set the UID and SID in both the client's cookies and |
54 // the MySQL session table. |
55 // the MySQL session table. |
55 // |
56 // |
56 |
57 |
57 $uid = (string)$uid; |
58 #$uid = (string)$uid; |
58 $mysql->query("INSERT INTO sessions (sid, sid_dir, uid, signature, timeout_date, expiration_date) |
59 $mysql->query("INSERT INTO sessions (sid, sid_dir, uid, signature, timeout_date, expiration_date) |
59 VALUES ('$sid1', '$sid2', '$uid', 'members', DATE_ADD(NOW(), INTERVAL 30 MINUTE), |
60 VALUES ('$sid1', '$sid2', '$uid', 'members', DATE_ADD(NOW(), INTERVAL 43200 MINUTE), |
60 DATE_ADD(NOW(), INTERVAL 8 HOUR))"); |
61 DATE_ADD(NOW(), INTERVAL 720 HOUR))"); |
61 setcookie("sid1", $sid1, time() + 964224000); |
62 setcookie("sid1", $sid1, time() + 964224000); |
62 setcookie("sid2", $sid2, time() + 964224000); |
63 setcookie("sid2", $sid2, time() + 964224000); |
|
64 if (!isset($_COOKIE['sid1'])) |
|
65 { |
|
66 $currSID1 = 1; |
|
67 } |
|
68 if (!isset($_COOKIE['sid2'])) |
|
69 { |
|
70 $currSID2 = 1; |
|
71 } |
|
72 |
|
73 |
63 #setcookie("uid", $uid, time() + 964224000); |
74 #setcookie("uid", $uid, time() + 964224000); |
64 exit(); |
75 exit(); |
65 |
76 |
66 return TRUE; |
77 return TRUE; |
67 } |
78 } |
90 } |
101 } |
91 |
102 |
92 if (!isset($_COOKIE['uid'])) |
103 if (!isset($_COOKIE['uid'])) |
93 { |
104 { |
94 $currID = 1; |
105 $currID = 1; |
|
106 $uid = $currID; |
95 } |
107 } |
96 } |
108 } |
97 mysql_close(); |
109 mysql_close(); |
98 // retrieve session cookie if it exists |
110 // retrieve session cookie if it exists |
99 # $real_password = password; |
111 # $real_password = password; |
100 $mysql = new mysqli("localhost", "www-data", "www-data", "members"); |
112 $mysql = new mysqli("localhost", "www-data", "www-data", "members"); |
101 /* check connection */ |
113 $result = $mysql->query("SELECT uid,password_md5 FROM creds WHERE username='$username'"); |
102 #if (mysqli_connect_errno()) { |
114 $row = $result->fetch_assoc(); |
103 # printf("Connect failed: %s\n", mysqli_connect_error()); |
115 $real_password = $row["password_md5"]; |
104 # exit(); |
116 if ((isset($_COOKIE['sid1'])) && (isset($_COOKIE['sid2']))) |
105 #} |
117 { |
106 $result = $mysql->query("SELECT uid,password_md5 FROM creds WHERE username='$username'"); |
118 $sid1 = $_COOKIE['sid1']; |
107 $row = $result->fetch_assoc(); |
119 $sid2 = $_COOKIE['sid2']; |
108 $real_password = $row["password_md5"]; |
120 header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php'); |
|
121 } |
|
122 else |
|
123 { |
109 |
124 |
110 #print $uid; |
125 create_session($mysql, $uid, $real_password); |
111 #if ((isset($_COOKIE['sid1'])) && (isset($_COOKIE['sid2']))) |
126 header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php'); |
112 #{ |
127 } |
113 # $sid1 = $_COOKIE['sid1']; |
128 $result->close(); |
114 # $sid2 = $_COOKIE['sid2']; |
|
115 # print $sid1; |
|
116 # print $sid2; |
|
117 #} |
|
118 |
|
119 $mysql = new mysqli("localhost", "www-data", "www-data", "members"); |
|
120 create_session($mysql, $uid, $real_password); |
|
121 header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php'); |
|
122 $result->close(); |
|
123 |
129 |
124 ?> |
130 ?> |
125 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
131 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
126 <html xmlns="http://www.w3.org/1999/xhtml"> |
132 <html xmlns="http://www.w3.org/1999/xhtml"> |
127 <head> |
133 <head> |