--- nanourl-0.1.orig/create.php +++ nanourl-0.1/create.php @@ -1,58 +1,63 @@
-
TinyURL was created!
";
+ if(! ($connection = @ mysql_connect($nanourlHost, $nanourlUser, $nanourlPassword)) ) {
+ echo mysql_error();
+ die("could not connect");
+ }
+ if(! (mysql_select_db($nanourlDB, $connection))) {
+ die("cannot select DB");
+ }
+
+ srand( ((int)((double)microtime()*1000003)) ); //seeding...
+ do {
+ $hash = '';
+
+ for($i = 0; $i< 5; $i++) {
+ $random = (rand()%36);
+ if($random <26) {
+ $random = $random + 97; //map to lowercase ASCII
+ } else {
+ $random = $random + 22; //map to number ASCII
+ }
+ $hash = $hash . chr($random);
+ }
+ $result = mysql_query("INSERT INTO urls VALUES ('$hash', '$newurl')");
+
+ //on the off chance this didn't work (collisions of hashes
+ //most likely...) do it all again
+ } while(! ($result));
+
+ //build the forwarding URL
+ $fwdurl = "$server/nanourl/".$hash;
+ //echo out the create signature
+ echo "