changeset 357:9823ee8c823e Dev_main

Bug #1464 #1456, PHP server hashes file contents to differentiate file names. Confirmed working on multiple connections with same file contents.
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Fri, 27 Nov 2015 09:27:33 +0000
parents 56003615235b
children 9c4118f24790
files save.php
diffstat 1 files changed, 2 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/save.php	Thu Nov 26 09:59:22 2015 +0000
+++ b/save.php	Fri Nov 27 09:27:33 2015 +0000
@@ -2,8 +2,9 @@
 	header('Access-Control-Allow-Origin: *');
 	header("Content-type: text/xml");
 	$postText = file_get_contents('php://input');
+	$sha1_hash = sha1($postText);
 	$datetime = date('ymdHis');
-	$xmlfile = "save".$datetime."-".generateRandomString(6).".xml";
+	$xmlfile = "save".$datetime."-".$sha1_hash.".xml";
 	$fileHandle = fopen("saves/".$xmlfile, 'w');
 	if ($fileHandle == FALSE)
 	{
@@ -25,15 +26,4 @@
 	// Return JSON confirmation data
 	$xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
 	echo $xml;
-	
-	// Random String generator from http://stackoverflow.com/questions/4356289/php-random-string-generator
-	function generateRandomString($length = 10) {
-    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
-    $charactersLength = strlen($characters);
-    $randomString = '';
-    for ($i = 0; $i < $length; $i++) {
-        $randomString .= $characters[rand(0, $charactersLength - 1)];
-    }
-    return $randomString;
-}
 ?>
\ No newline at end of file