-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcross-domain.php
61 lines (54 loc) · 1.75 KB
/
cross-domain.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Transport for Cross-domain AJAX calls
*
* This is an implementation of a transport channel for utilizing cross-domain
* AJAX calls. This script is passed the data through AJAX along with two special
* hidden field containing the acttion URL and the http method (GET/POST). It then
* sends the form fields to that URL and returns the response.
*
* @package CrossDomainAjax
* @category CURL
* @author Md Emran Hasan <[email protected]>
* @link http://www.phpfour.com
*/
// The actual form action
//header( 'Content-Type: text/html; charset=ISO-8859-1');
header( 'Content-Type: text/html; charset=utf-8');
$action = $_REQUEST['url'];
// Submission method
$method = $_REQUEST['method'];
// Query string
$fields = '';
// Prepare the fields for query string, don't include the action URL OR method
if (count($_REQUEST) > 2){
foreach ($_REQUEST as $key => $value){
if ($key != 'url' || $key != 'method'){
$fields .= '&' . $key . '=' . rawurlencode($value) ;
}
}
}
// Strip the last comma
$fields = substr($fields, 0, strlen($fields) - 1);
// Initiate cURL
$ch = curl_init();
// Do we need to POST of GET ?
if (strtoupper($method) == 'POST'){
curl_setopt($ch, CURLOPT_URL, $action);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
} else {
curl_setopt($ch, CURLOPT_URL, $action . $fields);
}
// Follow redirects and return the transfer
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// Get result and close cURL
$result = curl_exec($ch);
// Return the response
echo $result;
//error_log(curl_getinfo ($ch, CURLINFO_EFFECTIVE_URL ) );
//error_log(curl_error($method));
// error_log($result);
curl_close($ch);
?>