Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a case of multiple header sets (redirect) #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions ba-simple-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Script: Simple PHP Proxy: Get external HTML, JSON and more!
//
// *Version: 1.6, Last updated: 1/24/2009*
// *Version: 1.6.1, Last updated: 2/12/2023*
//
// Project Home - http://benalman.com/projects/php-simple-proxy/
// GitHub - http://github.com/cowboy/php-simple-proxy/
Expand Down Expand Up @@ -142,7 +142,7 @@

// ############################################################################

$url = $_GET['url'];
$url = @$_GET['url'];

if ( !$url ) {

Expand All @@ -164,12 +164,12 @@
curl_setopt( $ch, CURLOPT_POSTFIELDS, $_POST );
}

if ( $_GET['send_cookies'] ) {
if ( @$_GET['send_cookies'] ) {
$cookie = array();
foreach ( $_COOKIE as $key => $value ) {
$cookie[] = $key . '=' . $value;
}
if ( $_GET['send_session'] ) {
if ( @$_GET['send_session'] ) {
$cookie[] = SID;
}
$cookie = implode( '; ', $cookie );
Expand All @@ -181,9 +181,9 @@
curl_setopt( $ch, CURLOPT_HEADER, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt( $ch, CURLOPT_USERAGENT, $_GET['user_agent'] ? $_GET['user_agent'] : $_SERVER['HTTP_USER_AGENT'] );
curl_setopt( $ch, CURLOPT_USERAGENT, @$_GET['user_agent'] ? $_GET['user_agent'] : $_SERVER['HTTP_USER_AGENT'] );

list( $header, $contents ) = preg_split( '/([\r\n][\r\n])\\1/', curl_exec( $ch ), 2 );
list( $header, $contents ) = array_slice(preg_split( '/([\r\n][\r\n])\\1/', curl_exec( $ch )), -2, 2);

$status = curl_getinfo( $ch );

Expand All @@ -193,7 +193,7 @@
// Split header text into an array.
$header_text = preg_split( '/[\r\n]+/', $header );

if ( $_GET['mode'] == 'native' ) {
if ( @$_GET['mode'] == 'native' ) {
if ( !$enable_native ) {
$contents = 'ERROR: invalid mode';
$status = array( 'http_code' => 'ERROR' );
Expand All @@ -214,7 +214,7 @@
$data = array();

// Propagate all HTTP headers into the JSON data object.
if ( $_GET['full_headers'] ) {
if ( @$_GET['full_headers'] ) {
$data['headers'] = array();

foreach ( $header_text as $header ) {
Expand All @@ -226,7 +226,7 @@
}

// Propagate all cURL request / response info to the JSON data object.
if ( $_GET['full_status'] ) {
if ( @$_GET['full_status'] ) {
$data['status'] = $status;
} else {
$data['status'] = array();
Expand All @@ -238,11 +238,11 @@
$data['contents'] = $decoded_json ? $decoded_json : $contents;

// Generate appropriate content-type header.
$is_xhr = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
$is_xhr = strtolower(@$_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
header( 'Content-type: application/' . ( $is_xhr ? 'json' : 'x-javascript' ) );

// Get JSONP callback.
$jsonp_callback = $enable_jsonp && isset($_GET['callback']) ? $_GET['callback'] : null;
$jsonp_callback = $enable_jsonp && isset($_GET['callback']) ? @$_GET['callback'] : null;

// Generate JSON/JSONP string
$json = json_encode( $data );
Expand Down