Update maryland_voter.php
[clinton/MarylandElectronicPetitionSignature.git] / api / maryland_voter.php
CommitLineData
183344e4 1<?PHP
e20f7315
PM
2ini_set('display_errors', 1);
3ini_set('display_startup_errors', 1);
4error_reporting(E_ALL);
5
183344e4
PM
6function getPage($url){
7 $url = str_replace('[month]',date('F'),$url); // replace month January through December
8 $url = str_replace('[day]',date('j'),$url); // replace day 1 to 31
9 $url = str_replace('[yesterday]',date('j',strtotime('yesterday')),$url); // replace day 1 to 31
10 $url = str_replace('[year]',date('Y'),$url); // replace year Examples: 1999 or 2003
11 $curl = curl_init();
12 curl_setopt ($curl, CURLOPT_URL, $url);
13 curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("McGuire MEPS https://www.md-petition.com/ /%d.0",rand(4,50)));
14 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
15 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
16 curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true);
b4e176d1
PM
17 curl_setopt ($curl, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt'); // save cookies
18 //curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Cookie: ASP.NET_SessionId=true")); // use cookies
183344e4
PM
19 $html = curl_exec ($curl);
20 curl_close ($curl);
21 return $html;
22}
e20f7315 23
b4e176d1 24$form['cookies_file'] = dirname(__FILE__) . '/cookie.txt';
183344e4
PM
25$form['url'] = 'https://voterservices.elections.maryland.gov/VoterSearch';
26$form['html'] = getPage($form['url']);
e20f7315 27
b4e176d1
PM
28$cookies = '';
29if (file_exists($form['cookies_file'])) {
30 ob_start();
31 readfile($form['cookies_file']);
32 $cookies = ob_get_clean();
33}
34echo '<h1>Cookies</h1>'.$cookies;
183344e4
PM
35echo '<h1>RAW</h1>'.htmlspecialchars($form['html']).'<hr>';
36echo $form['html'];