Hi,
I am sending a HTTP post request to external url and if it is successfull - the client server returns OK:12345 on web page.
Now 12345 is an id and this is what i need to capture and store it as a variable to be used in my second script. Is there any way i can save this id as a variable or something.
Thank You.
http post response - id capture
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: http post response - id capture
Found this example in the php manual.
Hth.
Code: Select all
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.example.com/');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
// Another example, let's get a web page into a string. See also file_get_contents().
$html = implode('', file('http://www.example.com/'));
// Using the optional flags parameter since PHP 5
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: http post response - id capture
Thanks for your reply.
But this doesn't really help.
Basically what exactly happening is -
I submit a form with couple of hidden input fields (including url field where i need them to response i.e. http://www.xyz.com/response.php) to http://abc.com
Now http://abc.com checks the input data and if it's fine they create a ID and sends back the response to http://www.xyz.com with OK:12345
Now i want to capture this OK:12345 from my site i.e. http://www.xyz.com/response.php but i can't think of any way in php which can capture that -
The way that you mentioned just return the source code of that page but it doesn't display the response.
Any suggestions ?
But this doesn't really help.
Basically what exactly happening is -
I submit a form with couple of hidden input fields (including url field where i need them to response i.e. http://www.xyz.com/response.php) to http://abc.com
Now http://abc.com checks the input data and if it's fine they create a ID and sends back the response to http://www.xyz.com with OK:12345
Now i want to capture this OK:12345 from my site i.e. http://www.xyz.com/response.php but i can't think of any way in php which can capture that -
The way that you mentioned just return the source code of that page but it doesn't display the response.
Any suggestions ?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: http post response - id capture
What does your ID look like on the page, paste the code / result. The code below retrieves information from a page.
Code: Select all
<?php
// Read 14 characters starting from the 21st character
$section = file_get_contents('./people.txt', NULL, NULL, 20, 14);
var_dump($section);
?> “Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: http post response - id capture
From what you've described so far I think you could be facing a same origin policy issue. Use HTTP live headers (firefox plugin) and see what data actually gets sent and if any data actually gets sent back.
What social experiment said can be used here. Just format the URL being sent with the appropriate key/values, if the second page is using GET and there is no other output on the second page other than the result. If there is other output then you would have to parse the data being sent back, but that's just not good practice if you can avoid it.
What social experiment said can be used here. Just format the URL being sent with the appropriate key/values, if the second page is using GET and there is no other output on the second page other than the result. If there is other output then you would have to parse the data being sent back, but that's just not good practice if you can avoid it.