0

I need to send HTTP POST data to a webpage. My host is missing some extensions (I'm not sure which ones). I tried cURL and fopen, neither of them work.

What are other ways to send data?

Edit: By the way, I can send $_GET data as well. So as long as I can open a url (eg. file_get_contents), it's works.

Leo Jiang
  • 24,497
  • 49
  • 154
  • 284

2 Answers2

1

Checkout the very powerful PHP stream functions.

However, if the file/stream and cURL functions are disabled - then make them on the frontend using AJAX requests. jQuery is good at this as long as the data isn't sensitive.

I built an entire blog system using just jQuery JSONP requests on the frontend since I wanted to move the load to the user instead of my server.

Community
  • 1
  • 1
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
0

This may work. The context is not really needed, but allows you to set custom timeout and user-agent.

/* Set up array with options for the context used by file_get_contents(). */
$opts = array(
  'http'=>array(
    'method'  => 'GET',
    'timeout' => 4,
    'header'  => "Accept-language: en\r\n" .
                 "User-Agent: Some UA\r\n"
  )
);

/* Create context. */
$context = stream_context_create($opts);

/* Make the request */
$response = @file_get_contents('http://example.com/?foo=bar', null, $context);

if($response === false) {
  /* Could not make request. */
}

You can use http_build_query() to build your query string from an array.

Audun Larsen
  • 958
  • 5
  • 7