annotate php/keygen.php @ 2457:d26623bd65e0

Removed browser caching for PHP servers
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 02 Aug 2016 11:22:51 +0100
parents 760719986df3
children 8536e978ab6f
rev   line source
nicholas@2224 1 <?php
nicholas@2457 2 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
nicholas@2457 3 header("Cache-Control: post-check=0, pre-check=0", false);
nicholas@2457 4 header("Pragma: no-cache");
nicholas@2224 5 // This checks the key sent by the JavaScript against the current bunch of saves
nicholas@2224 6 // XML Saves location - assumes it will be saves/
nicholas@2224 7 $saves = glob("../saves/*.xml");
nicholas@2224 8
nicholas@2224 9 $key_requested = $_GET['key'];
nicholas@2224 10
nicholas@2224 11 $xml_good = "<response><state>OK</state><key>".$key_requested."</key></response>";
nicholas@2224 12 $xml_bad = "<response><state>NO</state><key>".$key_requested."</key></response>";
nicholas@2224 13 $xml_error = "<response><state>ERROR</state><key>".$key_requested."</key></response>";
nicholas@2224 14 if (is_array($saves))
nicholas@2224 15 {
nicholas@2224 16 foreach($saves as $filename) {
nicholas@2224 17 $xml_string = file_get_contents($filename, FILE_TEXT);
nicholas@2224 18 $xml_object = simplexml_load_string($xml_string);
nicholas@2224 19 if ($xml_object != false) {
nicholas@2224 20 if (isset($value['key']))
nicholas@2224 21 {
nicholas@2224 22 if ($value['key'] == $key_requested) {
nicholas@2224 23 echo $xml_bad;
nicholas@2224 24 return;
nicholas@2224 25 }
nicholas@2224 26 }
nicholas@2224 27 }
nicholas@2224 28 }
nicholas@2224 29 echo $xml_good;
nicholas@2224 30 // TODO:
nicholas@2224 31 // Generate the XML Base file and save it
nicholas@2224 32 $doc_struct = new SimpleXMLElement('<waetresult/>');
nicholas@2224 33 $doc_struct->addAttribute("key",$key_requested);
nicholas@2224 34 // Add start time
nicholas@2224 35 // Add IP Address information
nicholas@2224 36 // Save the file
nicholas@2224 37 $doc_struct->asXML("saves/save-".$key_requested.".xml");
nicholas@2224 38 return;
nicholas@2224 39 } else {
nicholas@2224 40 echo $xml_error;
nicholas@2224 41 return;
nicholas@2224 42 }
nicholas@2224 43 ?>