I am attempting to log in to a remote site, then redirect to a new page once the log-in is successful. On that page, I want to select from a few drop-downs (including one date-range) and then generate a report.
Right now, I have a script which can log in to the site - but I can't figure out how to iterate through the drop-downs. Any suggestions?
$url = 'example.co.za/login';
$vars = array('username'=>'', 'password'=>'');
$login = getUrl($url, 'post', $vars);
$remotePage = getUrl($remotePageUrl);
function getUrl($login)
{
$ch = curl_init();
if ($method == 'post')
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookies.txt');
$buffer = curl_exec($ch);
print_r($buffer3);
curl_close($ch);
return $buffer;
}
When submitting a form programmatically, you don't need to "select" from a dropdown. You can treat it like any other input field and pass a value for the form element. But you should pass one of the values in the dropdown, since that's what the server is expecting to receive.
For a dropdown like this:
<select name="weekday">
<option value="Sunday">Sunday</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
</select>
You can do a POST just like you do with the login form:
$vars = array("weekday" => "Friday");
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.