I need to remotely submit/process a form on an external website and get the results back on my site. The user can NOT be aware of this interaction.
I am able to get the data using HTML PHP/ Simple_Html_Dom
<?php
require "DOM/simple_html_dom.php";
$html = file_get_html('website.com/pricing');
foreach ($html->find('div[id=Price]') as $result)
{
echo $result->innertext;
}
?>
It is returning, PRICE as N/A. I need to be able to pass the values of the fields. I was hoping to pass them as hidden values such as <input type="hidden" name="QTY" value="100" />
What is the proper syntax and/or how do I accomplish this task?
I tried:
$html->load('<html><body
<form action="website.com/..." method="post" name="Pricing" >
#all hidden fields & values
</form></body></html>')
Any ideas? Thanks for the help. Ideally I am trying to recreate the form on my page and fetch the results of the query in real-time using AJAX.
–MORE DATA–
This page is using sessions: (How does this affect POST?)
{
"headers": {
"Date": "Mon, 24 Sep 2012 19:23:58 GMT",
"Server": "Apache",
"Set-Cookie": "JSESSIONID=01987F6C188624B08885FE26644300DA.worker2; Path=/g",
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"P3P": "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"",
"Vary": "Accept-Encoding",
"Connection": "close",
"Transfer-Encoding": "chunked",
"Content-Type": "text/html;charset=UTF-8"
},
You cannot access or amend data coming via AJAX that are from another domain. There is a same domain policy in force for such requests, so various types of hacks are prevented (like sniffing someone’s browser for their bank account details).
If you cannot control pages in question, you are (as your research suggested) left with an option of a PHP Proxy. This, however has the downside of not being able to process JavaScript itself, making all dynamic fields in the remote form invisible to your PHP script.
With regards to cookies, cURL should process cookies automatically for you. Check out the curl_setopt() manual for information about cURL settings.