I want to know what is necessary to create a PHP script that can interact with a website like a normal browser. The website would be rich in Ajax, so the PHP script needs to know how to handle Javascript functions and maintain an continuous connection with the website.
views:
75answers:
4
+1
A:
You're seeking what's called an HTTP client. PHP has one called cURL. See this example:
<?php $ch = curl_init("http://www.example.com/"); $fp = fopen("example_homepage.txt", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); ?>
cURL doesn't do Javascript however. If you need to evaluate Javascript, that's a far taller order and I might suggest you look at Google's V8 Javascript engine, but it's a C++ project.
cletus
2009-12-06 04:38:58
Even though cURL is great, it doesn't do JavaScript.
Mikael S
2009-12-06 04:43:27
+1
A:
What you are looking for would amount to creating a full-fledged browser, complete with Javascript interpreter, in PHP. That is never, ever going to happen. You will have to split whatever you want to achieve into parts, and try to implement those in PHP.
Pekka
2009-12-06 04:45:11
A:
There's no way for PHP to inteperate Javascript function calls on a website. PHP runs in the background, Javascript runs in the foreground. They are completely different things.
Jessedc
2009-12-06 06:03:10