This repository has been archived by the owner on May 23, 2024. It is now read-only.
forked from cowboy/jquery-hashchange
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing file for "Bug in Firefox: Remote XMLHttpRequest" example
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?PHP?><? | ||
|
||
// | ||
// Simple PHP JSON/P Echo - "Cowboy" Ben Alman - http://benalman.com/ | ||
// v1.0 - 2/20/2009 | ||
// | ||
|
||
// Show script source if no params are passed | ||
if (count($_GET) == 0) { | ||
highlight_file($_SERVER['SCRIPT_FILENAME']); | ||
die; | ||
} | ||
|
||
// Get request params | ||
$obj = array(); | ||
foreach ($_GET as $key => $value) { | ||
$obj[$key] = $value; | ||
} | ||
foreach ($_POST as $key => $value) { | ||
$obj[$key] = $value; | ||
} | ||
|
||
$json_string = isset($obj['JSON']) ? $obj['JSON'] : null; | ||
$jsonp_callback = isset($obj['callback']) ? $obj['callback'] : null; | ||
|
||
// remove misc unneeded params | ||
unset($obj['_']); | ||
unset($obj['callback']); | ||
unset($obj['JSON']); | ||
|
||
$json = $json_string ? $json_string : json_encode($obj); | ||
$jsonp = $jsonp_callback ? $jsonp_callback . "($json)" : $json; | ||
|
||
|
||
sleep(1); // simulate slow connection :D | ||
|
||
|
||
$is_xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && | ||
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; | ||
|
||
$is_referer = isset($_SERVER["HTTP_REFERER"]); | ||
|
||
if ($is_xhr) { | ||
|
||
header( 'Content-type: application/json' ); | ||
print $jsonp; | ||
|
||
} else if ($is_referer) { | ||
|
||
$params = array(); | ||
foreach ($obj as $key => $value) { | ||
$params[] = urlencode($key) . '=' . urlencode($value); | ||
} | ||
|
||
$url = preg_replace('/\?.*$/', '', $_SERVER["HTTP_REFERER"]); | ||
$url .= '?' . implode('&', $params); | ||
|
||
header( "Location: $url"); | ||
|
||
} else { | ||
|
||
header( 'Content-type: text/plain' ); | ||
|
||
print $jsonp; | ||
|
||
} | ||
|
||
?> |