0

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?

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that's brilliant. Just need somewhere to host it now :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.