index.php
changeset 4 2c829de4b83c
parent 3 ad69d332e9dc
child 13 bfe0d3de2764
--- a/index.php	Tue May 19 18:41:47 2009 +0100
+++ b/index.php	Wed May 20 15:46:51 2009 +0100
@@ -24,6 +24,7 @@
 }
 function create_session($mysql, $uid, $password)
 {
+
         //
         // Build list of existing SIDs
         //
@@ -54,12 +55,22 @@
         // the MySQL session table.
         //
 
-$uid = (string)$uid;
+#$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 30 MINUTE),
-                DATE_ADD(NOW(), INTERVAL 8 HOUR))");
+                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();
 
@@ -92,34 +103,29 @@
 		if (!isset($_COOKIE['uid'])) 
 		{
 			$currID = 1;
+			$uid = $currID;
 		}
 	}
 	mysql_close();
 	// retrieve session cookie if it exists
 #	$real_password = password;
-$mysql = new mysqli("localhost", "www-data", "www-data", "members");
-/* check connection */
-#if (mysqli_connect_errno()) {
-#    printf("Connect failed: %s\n", mysqli_connect_error());
-#    exit();
-#}
-$result = $mysql->query("SELECT uid,password_md5 FROM creds WHERE username='$username'");
-$row = $result->fetch_assoc();
-$real_password = $row["password_md5"];
+	$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
+        	{
 
-	#print $uid;
- 	#if ((isset($_COOKIE['sid1'])) && (isset($_COOKIE['sid2'])))
-        #{
-        #        $sid1 = $_COOKIE['sid1'];
-        #        $sid2 = $_COOKIE['sid2'];
-	#	print $sid1;
-	#	print $sid2;
-        #}
-
-	$mysql = new mysqli("localhost", "www-data", "www-data", "members");
-	create_session($mysql, $uid, $real_password);
-       	header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php');
-$result->close();
+		create_session($mysql, $uid, $real_password);
+       		header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php');
+		}
+	$result->close();
 
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">