|
187 | 187 | $status = array(); |
188 | 188 |
|
189 | 189 | if ( $url_query_param != null ) { |
190 | | - $url = $_GET[$url_query_param]; |
| 190 | + $url = isset($_GET[$url_query_param]) ? $_GET[$url_query_param] : null; |
191 | 191 | } else if ( $url_header != null ) { |
192 | | - $url = $_SERVER[$url_header]; |
| 192 | + $url = isset($_SERVER[$url_header]) ? $_SERVER[$url_header] : null; |
193 | 193 | } else { |
194 | 194 | $url = null; |
195 | 195 | } |
|
218 | 218 | if ( isset( $cors_allow_headers ) ) { |
219 | 219 | header( 'Access-Control-Allow-Headers: '.strtolower($cors_allow_headers) ); |
220 | 220 | } |
221 | | - if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ) { |
| 221 | + if ( isset($_SERVER['REQUEST_METHOD']) && |
| 222 | + ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') ) { |
222 | 223 | // We're done - don't proxy CORS OPTIONS request |
223 | 224 | exit(); |
224 | 225 | } |
|
227 | 228 | $ch = curl_init( $url ); |
228 | 229 |
|
229 | 230 | // Pass on request method, regardless of what it is |
230 | | - curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD'] ); |
| 231 | + curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, |
| 232 | + isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET' ); |
231 | 233 |
|
232 | 234 | // Pass on content, regardless of request method |
233 | 235 | if ( isset($_SERVER['CONTENT_LENGTH'] ) && $_SERVER['CONTENT_LENGTH'] > 0 ) { |
|
239 | 241 | foreach ( $_COOKIE as $key => $value ) { |
240 | 242 | $cookie[] = $key . '=' . $value; |
241 | 243 | } |
242 | | - if ( $_GET['send_session'] ) { |
| 244 | + if ( isset($_GET['send_session']) ) { |
243 | 245 | $cookie[] = SID; |
244 | 246 | } |
245 | 247 | $cookie = implode( '; ', $cookie ); |
|
262 | 264 | } |
263 | 265 | if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) { |
264 | 266 | array_push($headers, $_SERVER['HTTP_X_FORWARDED_FOR'].", ".$_SERVER['HTTP_X_USER_AGENT'] ); |
265 | | - } else { |
| 267 | + } else if (isset($_SERVER['REMOTE_ADDR'])) { |
266 | 268 | array_push($headers, "X-Forwarded-For: ".$_SERVER['REMOTE_ADDR'] ); |
267 | 269 | } |
268 | 270 |
|
|
290 | 292 | } |
291 | 293 |
|
292 | 294 | // Split header text into an array. |
293 | | -$header_text = preg_split( '/[\r\n]+/', $header ); |
| 295 | +$header_text = isset($header) ? preg_split( '/[\r\n]+/', $header ) : array(); |
294 | 296 |
|
295 | | -if ( $_GET['mode'] == 'native' ) { |
| 297 | +if ( isset($_GET['mode']) && $_GET['mode'] == 'native' ) { |
296 | 298 | if ( !$enable_native ) { |
297 | 299 | $contents = 'ERROR: invalid mode'; |
298 | 300 | $status['http_code'] = 400; |
|
325 | 327 | $data = array(); |
326 | 328 |
|
327 | 329 | // Propagate all HTTP headers into the JSON data object. |
328 | | - if ( $_GET['full_headers'] ) { |
| 330 | + if ( isset($_GET['full_headers']) ) { |
329 | 331 | $data['headers'] = array(); |
330 | 332 |
|
331 | 333 | foreach ( $header_text as $header ) { |
|
337 | 339 | } |
338 | 340 |
|
339 | 341 | // Propagate all cURL request / response info to the JSON data object. |
340 | | - if ( $_GET['full_status'] ) { |
| 342 | + if ( isset($_GET['full_status']) ) { |
341 | 343 | $data['status'] = $status; |
342 | 344 | } else { |
343 | 345 | $data['status'] = array(); |
|
349 | 351 | $data['contents'] = $decoded_json ? $decoded_json : $contents; |
350 | 352 |
|
351 | 353 | // Generate appropriate content-type header. |
352 | | - $is_xhr = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; |
| 354 | + $is_xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && |
| 355 | + (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); |
353 | 356 | header( 'Content-type: application/' . ( $is_xhr ? 'json' : 'x-javascript' ) ); |
354 | 357 |
|
355 | 358 | // Get JSONP callback. |
356 | | - $jsonp_callback = $enable_jsonp && isset($_GET['callback']) ? $_GET['callback'] : null; |
| 359 | + $jsonp_callback = ($enable_jsonp && isset($_GET['callback'])) ? $_GET['callback'] : null; |
357 | 360 |
|
358 | 361 | // Generate JSON/JSONP string |
359 | 362 | $json = json_encode( $data ); |
|
0 commit comments