# HG changeset patch # User Alex McMahon # Date 1242837222 -3600 # Node ID c692d0081830200bba633f2bb1ea5d1e83a04edf # Parent e4238b7321b487b216cae0a5fbf0524241dfd0c4# Parent e8c21d72976d1e52f8a3fa70e722ec3b27d2ef7a branch merge diff -r e8c21d72976d -r c692d0081830 add_search.php --- a/add_search.php Wed May 20 13:20:27 2009 +0100 +++ b/add_search.php Wed May 20 17:33:42 2009 +0100 @@ -6,7 +6,7 @@ } // get user ID from cookie - $currID = $_COOKIE['n4c_ID']; + $currID = $_COOKIE['uid']; if ($currID == "") { @@ -51,7 +51,7 @@ $message = "#" . $currID . "#" . $reqID . "#" . $search_term; $host="localhost"; - $port = 8080; + $port = 9090; $timeout = 30; $sk=fsockopen($host,$port,$errnum,$errstr,$timeout); diff -r e8c21d72976d -r c692d0081830 delete.php diff -r e8c21d72976d -r c692d0081830 details.php --- a/details.php Wed May 20 13:20:27 2009 +0100 +++ b/details.php Wed May 20 17:33:42 2009 +0100 @@ -1,11 +1,30 @@

It works!

diff -r e8c21d72976d -r c692d0081830 index.php --- a/index.php Wed May 20 13:20:27 2009 +0100 +++ b/index.php Wed May 20 17:33:42 2009 +0100 @@ -1,34 +1,132 @@ query("SELECT sid FROM sessions"); + $num_rows = $result->num_rows; + while($num_rows > 0) + { + $row = $result->fetch_assoc(); + $sids[$row["sid"]] = TRUE; + $num_rows--; + } + $result->close(); + // + // Generate main SID (making sure it is unique) + // + $max_attempts = 500000; + $seed = crc32($password); + do + { + $sid1 = genID($seed + time(), 32); + $max_attempts--; + } while(isset($sids[$sid1]) && $max_attempts > 0); + if($max_attempts <= 0) // NOT GOOD + return FALSE; + $sid2 = genID(crc32($sid1) + time(), 32); + // + // Create the session: set the UID and SID in both the client's cookies and + // the MySQL session table. + // + +#$uid = (string)$uid; + $mysql->query("INSERT INTO sessions (sid, sid_dir, uid, signature, timeout_date, expiration_date) + VALUES ('$sid1', '$sid2', '$uid', 'members', DATE_ADD(NOW(), INTERVAL 43200 MINUTE), + DATE_ADD(NOW(), INTERVAL 720 HOUR))"); + setcookie("sid1", $sid1, time() + 964224000); + setcookie("sid2", $sid2, time() + 964224000); + if (!isset($_COOKIE['sid1'])) + { + $currSID1 = 1; + } + if (!isset($_COOKIE['sid2'])) + { + $currSID2 = 1; + } + + + #setcookie("uid", $uid, time() + 964224000); + exit(); + + return TRUE; +} + + $conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error()); mysql_select_db('members'); // retrieve cookie if it exists - if (isset($_COOKIE['n4c_ID'])) + if (isset($_COOKIE['uid'])) { - $currID = $_COOKIE['n4c_ID']; + $currID = $_COOKIE['uid']; + $uid = $currID; } else { // SQL queries $result = mysql_query("INSERT INTO creds (uid) VALUES ('')"); - $user_id = mysql_query("SELECT MAX(uid) as id FROM creds"); + $uid = mysql_query("SELECT MAX(uid) as id FROM creds"); $expiry = time() + (3600 * 24 * 30 * 12); //create cookies - while ($db_field2 = mysql_fetch_assoc($user_id)) { - setcookie('n4c_ID', $db_field2['id'] , $expiry, '/', '', 0); + while ($db_field2 = mysql_fetch_assoc($uid)) { + setcookie('uid', $db_field2['id'] , $expiry, '/', '', 0); } - if (!isset($_COOKIE['n4c_ID'])) + if (!isset($_COOKIE['uid'])) { $currID = 1; + $uid = $currID; } } - mysql_close(); - - header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/details.php'); + // retrieve session cookie if it exists +# $real_password = password; + $mysql = new mysqli("localhost", "www-data", "www-data", "members"); + $result = $mysql->query("SELECT uid,password_md5 FROM creds WHERE username='$username'"); + $row = $result->fetch_assoc(); + $real_password = $row["password_md5"]; + if ((isset($_COOKIE['sid1'])) && (isset($_COOKIE['sid2']))) + { + $sid1 = $_COOKIE['sid1']; + $sid2 = $_COOKIE['sid2']; + header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php'); + } + else + { + + create_session($mysql, $uid, $real_password); + header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php'); + } + $result->close(); + ?> diff -r e8c21d72976d -r c692d0081830 login.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/login.html Wed May 20 17:33:42 2009 +0100 @@ -0,0 +1,9 @@ + + +N4C router + + +
+
+ +