Commits

Anonymous committed 1bffee2

Start

Comments (0)

Files changed (4)

Empty file added.

+RewriteEngine On
+
+RewriteRule ^matches/([0-9]{2}).(xml|json)$ matches.php?id=$1&type=$2
+RewriteRule ^countries/([a-z]{3}).(xml|json)$ counties.php?shortcode=$1&type=$2
+<?php
+//ini_set("display_errors",false) ;
+
+$method = $_SERVER['REQUEST_METHOD'];
+
+if ( isset($_GET['shortcode']) && !empty($_GET['shortcode']) ) {
+	$shortcode = $_GET['shortcode'];
+}
+else {
+	$shortcode = 'undefined';
+}
+
+if ( isset($_GET['type']) && !empty($_GET['type']) ) {
+	$type = $_GET['type'];
+}
+else {
+	$type = 'xml';
+}
+
+switch ( $method ) {
+	case 'GET':
+
+		switch( $type ) {
+			case 'xml':
+				header( "content-type: text/xml; charset=utf-8" );
+				echo '<country><id>1234</id></country>';
+			 break;
+		}
+	
+	 break;
+	
+	case 'PUT':
+		if ( isset($_GET['id']) && !empty($_GET['id']) && ctype_xdigit($_GET['id']) ) {
+			$id = $_GET['id'];
+		}	
+		
+		$inputSocket = fopen("php://input", "r");
+		$inputData = '';
+		
+		while ($data = fread($inputSocket, 1024) ) {
+			$inputData .= $data;
+		}
+		fclose($inputSocket);
+		
+		//$readData = simplexml_load_string($inputData);
+		if ( file_exists('reviews/'.$id.'.xml') ) {
+			$isNewFile = true;
+		} else {
+			$isNewFile = false;
+		}
+		// schrijf bestand.
+		$handle = fopen('reviews/'.$id.'.xml', 'w');
+		if ( fwrite($handle, $inputData) ) {
+			if ($isNewFile) {
+				header('http/1.0 201 Created');
+			} else {
+				header('http/1.0 204');
+			}
+			
+			header( "content-type: text/xml; charset=utf-8" );
+			echo '<detailUrls><xml>http://localhost/str6/reviews/'.$id.'.xml</xml><html>http://localhost/str6/reviews/'.$id.'.html</html><detailUrls>';	
+		}
+		else {
+			header('http/1.0 500 Internal Server Error');
+		}
+		fclose($handle);			
+	 break;
+	 
+	case 'HEAD':
+		header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
+		header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
+	 break;
+	 
+	case 'OPTIONS':
+		header('Allow: OPTIONS, HEAD, GET, PUT');
+	 break;
+}
+?>
+<?php
+//ini_set("display_errors",false) ;
+
+$method = $_SERVER['REQUEST_METHOD'];
+
+if ( isset($_GET['id']) && !empty($_GET['id']) && ctype_xdigit($_GET['id']) ) {
+	$id = $_GET['id'];
+}
+else {
+	$id = 'undefined';
+}
+
+if ( isset($_GET['type']) && !empty($_GET['type']) ) {
+	$type = $_GET['type'];
+}
+else {
+	$type = 'xml';
+}
+
+switch ( $method ) {
+	case 'GET':
+
+		switch( $type ) {
+			case 'xml':
+				header( "content-type: text/xml; charset=utf-8" );
+				echo '<match><id>3154</id></match>';
+			 break;
+		}
+	
+	 break;
+	
+	case 'PUT':
+		if ( isset($_GET['id']) && !empty($_GET['id']) && ctype_xdigit($_GET['id']) ) {
+			$id = $_GET['id'];
+		}	
+		
+		$inputSocket = fopen("php://input", "r");
+		$inputData = '';
+		
+		while ($data = fread($inputSocket, 1024) ) {
+			$inputData .= $data;
+		}
+		fclose($inputSocket);
+		
+		//$readData = simplexml_load_string($inputData);
+		if ( file_exists('reviews/'.$id.'.xml') ) {
+			$isNewFile = true;
+		} else {
+			$isNewFile = false;
+		}
+		// schrijf bestand.
+		$handle = fopen('reviews/'.$id.'.xml', 'w');
+		if ( fwrite($handle, $inputData) ) {
+			if ($isNewFile) {
+				header('http/1.0 201 Created');
+			} else {
+				header('http/1.0 204');
+			}
+			
+			header( "content-type: text/xml; charset=utf-8" );
+			echo '<detailUrls><xml>http://localhost/str6/reviews/'.$id.'.xml</xml><html>http://localhost/str6/reviews/'.$id.'.html</html><detailUrls>';	
+		}
+		else {
+			header('http/1.0 500 Internal Server Error');
+		}
+		fclose($handle);			
+	 break;
+	 
+	case 'HEAD':
+		header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
+		header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
+	 break;
+	 
+	case 'OPTIONS':
+	default:
+		header('Allow: OPTIONS, HEAD, GET, PUT');
+	 break;
+}
+?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.