Beta Decay Beta Decay - 3 months ago 8
HTML Question

Using a PHP (or JS) script to click an external button

I would like to write a PHP script which, when run, sets the values of the drop down menus on the page here and then submits these values by pressing the 'Fetch Button'.

This should link to another page (http://voyager.gsfc.nasa.gov/cgi-bin/heliopause_all), the contents of which I would like the PHP script to return.

I have not attempted this, since I have very limited PHP knowledge, so I ask whether this would be possible and what I would have to learn about PHP to do this?

-- Edit --



Looking at the source code, would this be possible with simply a POST request from JavaScript?

Answer

First idea I have had. Make a POST with curl to: http://voyager.gsfc.nasa.gov/cgi-bin/heliopause_all

with these POST-Parameters

average:6hour
syear:9999
smonth:9999
sday:9999
eyear:9999
emonth:9999
eday:9999
sat:1
mnemonic:IPGH
duration:3-months
outputType:list
timeFormat:ISO

The last step is to parse the response.

Code:

<?php

$url = 'http://voyager.gsfc.nasa.gov/cgi-bin/heliopause_all';
$parameters_str = '';
$parameters = array(
    'average'=>'6hour',
    'syear'=>'9999',
    'smonth'=>'9999',
    'sday'=>'9999',
    'eyear'=>'9999',
    'emonth'=>'9999',
    'eday'=>'9999',
    'sat'=>'1',
    'mnemonic'=>'IPGH',
    'duration'=>'3-months',
    'outputType'=>'list',
    'timeFormat'=>'ISO'
);

foreach ($parameters as $k => $v) {
    $parameters_str .= $k . '=' . $v . '&';
}
rtrim($parameters_str, '&');


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, count($parameters));
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters_str);
curl_setopt($ch, CURLOPT_HEADER, false);


$result = curl_exec($ch);

curl_close($ch);

echo $result;
Comments