<?php    

    
function rand_str($size) { // Returns a string of characters consisting of $feed of length $size
        
$feed "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        for (
$x 0$x $size$x ++) {
            
$rand_str .= substr($feedrand(0strlen($feed) - 1), 1);
        }
        return 
$rand_str;
    }
    
    function 
createSessionId() { // Creates new session ids until the created one is not already in use
        
$createdId rand_str(rand(1640));
        
clearstatcache();
        while (
is_dir($createdId))
            
$createdId rand_str(rand(1640));
        return 
$createdId;
    }
    
    
$id createSessionId(); // Assigns a unique session id
    
$minute = (int)(time() / 60); // Derives the minute
    
mkdir("id/$id"); // Creates a directory with the user's session id
    
touch("id/$id/.htsession");
    
$sessFile fopen("id/$id/.htsession""w+"); // Opens (creates) session file for writing (clears)
    
fwrite($sessFile"$username\n$minute"); // Writes the username and time to the session file, id/$id/.htsession
    
fclose($sessFile); // Closes the session file
?>