aboutsummaryrefslogtreecommitdiffstats
path: root/test/data/ajax/echo/index.php
blob: a03fe4b0d39ff6f76f0728bbf75cdbbbe85b22e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

	$requestArray = "REQUEST";
	
	if ( isset( $_REQUEST["requestArray"] ) ) {
		$requestArray = $_REQUEST["requestArray"];
	}
	
	$requestArray =& ${"_$requestArray"};

	$response = array(
		"status" => "200",
		"statusText" => "",
		"contentType" => "text/plain",
		"content" => "",
		"callback" => "",
		"delay" => 0
	);

	foreach( $response as $field => &$value ) {
		if ( isset( $requestArray[ $field ] ) ) {
			$value = $requestArray[ $field ];
		}
	}
	
	if ( is_array( $response["content"] ) ) {
		$response["content"] = http_build_query( $response["content"] );
	}
	
	if ( !$response["callback"] && preg_match( '/index.php\/([^\/\?&]+)/', $_SERVER["REQUEST_URI"], $match ) ) {
		$response["callback"] = $match[ 1 ];
	}

	header("HTTP/1.1 $response[status] $response[statusText]");
	header("Content-Type: $response[contentType]");

	if ( $response["delay"] ) {
		sleep( $response["delay"] );
	}

	echo $response["callback"]
		? "$response[callback](" . json_encode("$response[content]") . ");"
		: "$response[content]";