0

I've looked everywhere but can't find what I need so hence why I'm posting this question.

I'm looking for code for a PHP proxy to help me effectively do cross-domain jquery requests but have these requirements:

  1. Must be PHP
  2. Cannot use cURL -- my server config doesn't support it. Presumably this leaves fopen() but I'm open to alternatives.
  3. Must support both GET and POST requests
  4. Support both responses for either XML and JSON

I'e searched high and low for a solution but always find solutions that use cURL or doesn't support POST.

I'm currently using this which doesn't work for POST:

header('Content-type: application/json');

$daurl = $_GET['url'];

$handle = fopen($daurl, "r");

if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
fclose($handle);
}

2 Answers 2

1

file_get_contents(). See Example #4 at the linked page (PHP online docs) on how to do 'custom' requests using streams for POST and arbitrary HTTP headers.

Sign up to request clarification or add additional context in comments.

1 Comment

I looked up the example, but not sure how to get it to work with POST.
0

in other for you to get quick answer, you first need to do some work yourself, then when you get stuck, you can post it here. The question is too broad to be answered. you are requesting for a complete solution, you won't get it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.