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

  • SEARCH
  • Home
  • 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 8553105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:34:30+00:00 2026-06-11T14:34:30+00:00

I am using the example function given in this post : <?php function do_post_request($url,

  • 0

I am using the example function given in this post:

<?php
function do_post_request($url, $data, $optional_headers = null)
{
  $params = array('http' => array(
              'method' => 'POST',
              'content' => $data
            ));
  if ($optional_headers !== null) {
    $params['http']['header'] = $optional_headers;
  }
  $ctx = stream_context_create($params);
  $fp = @fopen($url, 'rb', false, $ctx);
  if (!$fp) {
    throw new Exception("Problem with $url, $php_errormsg");
  }
  $response = @stream_get_contents($fp);
  if ($response === false) {
    throw new Exception("Problem reading data from $url, $php_errormsg");
  }
  return $response;
}
?>

I also tried a similar approach using file_get_contents(), like this:

$options = array(
  'http'=>array(
    'method'=>"POST",
    'header'=>
      "Accept-language: en\r\n".
      "Content-type: application/x-www-form-urlencoded\r\n",
    'content'=>http_build_query(
        array(
            'arg1'=>'arg_data_1',
            'oper'=>'get_data',
            'arg2'=>'arg_data_2',
            'id_number'=>'7862'
        ),'','&'
    )
));

$context = stream_context_create($options);
$refno = file_get_contents('/path/to/script/script.php',false,$context);

var_dump($refno);

With both these scripts, the response from the server script is the same, and it is the TEXT of the script.php. The code of the server script is never begin executed, and the text content (the PHP code) of the script is being returned to the original script.

A little strange that it doesn’t return all the text, but just certain pieces… I tried making a test script (test.php) that just contains:

<?php
echo '{"a":1,"b":2,"c":3,"d":4,"e":5}';
?>

but that doesn’t return anything from the POST request, so I didn’t include that. The script.php is a must longer script that does a lot of logic and MySQL queries then returns a JSON object.

The desired output will be to have the PHP code execute and return a JSON object (the way it works with ajax).

What am I doing wrong?

  • 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-06-11T14:34:31+00:00Added an answer on June 11, 2026 at 2:34 pm

    You are trying access script localy.
    You must call it like any other external script like

    $refno = file_get_contents('http://yourhost/path/to/script/script.php',false,$context);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code for the .ajax() call: $.ajax({ type: POST, url: http://ws.geonames.org/searchJSON, dataType:
I've been trying to get this really simple example of using AJAX with JQuery
I am passing a multidimensional array back to a .php file using json, jquery,
Given the following HTML structure: <div class=wrapper> <div class=top> <a href=http://example.com class=link>click here</a> </div>
For a given SQL stored proc or function, I'm trying to obtain its input
So - I've been using this method of file uploading for a bit, but
This is my ajax function: function ajax_call(call_method,data_to_send) { logger(function ajax_call. var data_to_send: ); logger(data_to_send);
Hi, i have been having some problems using JSON data in flash builder lately
I've looked at this post which addresses how to loop over arrays that aren't
This seems to be quite a common theme and a few people have given

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.