Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6319655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:50:35+00:00 2026-05-24T15:50:35+00:00

Ok I am trying to access some JSON using a PHP proxy as I

  • 0

Ok I am trying to access some JSON using a PHP proxy as I have been told is the only way to do a cross domain access when you don’t control the sites policies.

Here is the code below I am trying to use as a php proxy as shared by a fellow stackoverflow user:

function curl_download($Url){

    // is cURL installed yet?
    if (!function_exists('curl_init')){
        die('Sorry cURL is not installed!');
    }

    // OK cool - then let's create a new cURL resource handle
    $ch = curl_init();

    // Now set some options (most are optional)

    // Set URL to download
    curl_setopt($ch, CURLOPT_URL, $Url);

    // Set a referer
    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");

    // User agent
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");

    // Include header in result? (0 = yes, 1 = no)
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // Should cURL return or print out the data? (true = return, false = print)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    // Download the given URL, and return output
    $output = curl_exec($ch);

    // Close the cURL resource, and free system resources
    curl_close($ch);

    return $output;
}

problem is when I replace $URL with http://www.nfl.com/liveupdate/scorestrip/ss.json nothing seems to happen. I am not really sure how to use this PHP proxy though either as I don’t ever do this type of thing.

Am I suppose to create this in a seperate php file and then send a request to this code? I am kind of against the wall on what exactly to do here to make it so I can access the json from the site above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:50:36+00:00Added an answer on May 24, 2026 at 3:50 pm

    Am I suppose to create this in a seperate php file and then send a request to this code?

    Yes. The code above should resend your request made from JS to a remote service on another domain. Which is what does the trick – enables crossdomain POST requests from JS.

    <?php
    
    $server_url = "http://example.com/";
    
    $options = array
    (
        CURLOPT_HEADER         => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_TIMEOUT        => 60,
        CURLOPT_CONNECTTIMEOUT => 0,
        CURLOPT_HTTPGET        => 1
    );
    
    $service = $_GET["service"];
    
    $request_headers = Array();
    foreach($_SERVER as $i=>$val) {
            if (strpos($i, 'HTTP_') === 0) {
                    $name = str_replace(array('HTTP_', '_'), array('', '-'), $i);
                    if ($name != 'HOST')
                    {
                        $request_headers[] = "{$name}: {$val}";
                    }
            }
    }
    
    $options[CURLOPT_HTTPHEADER] = $request_headers;
    
    switch (strtolower($_SERVER["REQUEST_METHOD"]))
    {
    
        case "post":
            $options[CURLOPT_POST] = true;
            $url = "{$server_url}/services/".$service;
    
            $options[CURLOPT_POSTFIELDS] = file_get_contents("php://input");
    
            break;
        case "get":
    
            unset($_GET["service"]);
    
            $querystring = "";
            $first = true;
            foreach ($_GET as $key => $val)
            {
                if (!$first) $querystring .= "&";
                $querystring .= $key."=".$val;
                $first = false;
            }
    
            $url = "{$server_url}/services/".$service."?".$querystring;
    
            break;
        default:
            throw new Exception("Unsupported request method.");
            break;
    
    }
    
    $options[CURLOPT_URL] = $url;
    
    $curl_handle = curl_init();
    
    curl_setopt_array($curl_handle,$options);
    $server_output = curl_exec($curl_handle);
    curl_close($curl_handle);
    
    $response = explode("\r\n\r\n",$server_output);
    $headers = explode("\r\n",$response[0]);
    
    foreach ($headers as $header)
    {
        if ( !preg_match(';^transfer-encoding:;ui', Trim($header))  )
        {
            header($header);
        }
    }
    
    echo $response[1]; 
    

    This is a slightly modified version of the script I use, unfortunately not well documented.

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to access some data from Google maps. the only way possible is
I am trying to use Python's ctypes library to access some methods in the
I am trying to access Outlook 2007 from C#. I have installed the PIA
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
I'm having a problem trying to return a specific record using jQuery and JSON.
I'm trying to use some data from a PlanPlusOnline account. They only provide a
I'm trying to get some json data from a remote website. I run my
I am trying to get some profile information in my Facebook via PHP as
$.post('testeUpdate.php', 'autocomplete', function(dadosResposta) { $('#ns-nome').val(dadosResposta.nsName); $('#ns-endereco').val(dadosResposta.nsAddress); }, json); I'm trying to understand this. So,
I'm trying to access JSON data with jQuery and grab a specific set of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.