]> git.mjollnir.org Git - moodle.git/commitdiff
Added a new function to make a unique ID code, to be used in quiz
authormoodler <moodler>
Sat, 23 Aug 2003 12:22:27 +0000 (12:22 +0000)
committermoodler <moodler>
Sat, 23 Aug 2003 12:22:27 +0000 (12:22 +0000)
questions and elsewhere

It's based on the hostname, time, random string and a supplied version string.
These are packed using '+ separators so they can easily be unpacked if
necessary.

function make_unique_id_code($version=1)

lib/moodlelib.php

index 19f764ed71c32dd28b0a7cb0259f99a884d19f11..b626f2916a3170804a755c338dc31580d9ecd0ac 100644 (file)
@@ -1685,6 +1685,27 @@ function make_grades_menu($gradingtype) {
     return $grades;
 }
 
+function make_unique_id_code($version=1) {
+
+    $hostname = "unknownhost";
+    if (!empty($_SERVER["HTTP_HOST"])) {
+        $hostname = $_SERVER["HTTP_HOST"];
+    } else if (!empty($_ENV["HTTP_HOST"])) {
+        $hostname = $_ENV["HTTP_HOST"];
+    } else if (!empty($_SERVER["SERVER_NAME"])) {
+        $hostname = $_SERVER["SERVER_NAME"];
+    } else if (!empty($_ENV["SERVER_NAME"])) {
+        $hostname = $_ENV["SERVER_NAME"];
+    }
+
+    $date = date("ymdHis");
+
+    $random =  random_string(6);
+
+    return "$hostname+$date+$random+$version";
+    
+}
+
 
 // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
 ?>