2 ini_set('display_errors', 1);
3 ini_set('display_startup_errors', 1);
4 error_reporting(E_ALL
);
6 function cut_part_out($start,$end,$whole){
7 $parts = explode($start,$whole);
8 $subparts = explode($end,$parts[1]);
13 function getPage($url,$cookie,$post){
14 $url = str_replace('[month]',date('F'),$url); // replace month January through December
15 $url = str_replace('[day]',date('j'),$url); // replace day 1 to 31
16 $url = str_replace('[yesterday]',date('j',strtotime('yesterday')),$url); // replace day 1 to 31
17 $url = str_replace('[year]',date('Y'),$url); // replace year Examples: 1999 or 2003
19 curl_setopt ($curl, CURLOPT_URL
, $url);
20 curl_setopt ($curl, CURLOPT_USERAGENT
, sprintf("McGuire MEPS https://www.md-petition.com/ /%d.0",rand(4,50)));
21 curl_setopt ($curl, CURLOPT_RETURNTRANSFER
, 1);
22 curl_setopt ($curl, CURLOPT_HEADER
, 1);
23 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER
, 0);
24 curl_setopt ($curl, CURLOPT_FOLLOWLOCATION
, true);
26 curl_setopt ($curl, CURLOPT_HTTPHEADER
, array("Cookie: ASP.NET_SessionId=$cookie")); // use cookies
30 'upload_file' => '@file_to_upload.png',
31 'upload_text' => '@text_to_upload'
35 curl_setopt ($curl, CURLOPT_POSTFIELDS
, $post);
37 $html = curl_exec ($curl);
42 function md_voter_lookup($SearchFirstName,$SearchLastName,$DOBMonth,$DOBDay,$DOBYear,$SearchZipCode,$SearchHouseNumber,$SearchMiddleInitial){
43 $post['ctl00$MainContent$btnSearch'] = "Search";
44 $post['btnSearch'] = "Search";
45 $post['ctl00$MainContent$listLanguages'] = "en";
46 $post['listLanguages'] = "en";
47 $post['ctl00$MainContent$txtSearchFirstName'] = $SearchFirstName;
48 $post['txtSearchFirstName'] = $SearchFirstName;
49 $post['ctl00$MainContent$txtSearchLastName'] = $SearchLastName;
50 $post['txtSearchLastName'] = $SearchLastName;
51 $post['ctl00$MainContent$txtDOBMonth'] = $DOBMonth;
52 $post['txtDOBMonth'] = $DOBMonth;
53 $post['ctl00$MainContent$txtDOBDay'] = $DOBDay;
54 $post['txtDOBDay'] = $DOBDay;
55 $post['ctl00$MainContent$txtDOBYear'] = $DOBYear;
56 $post['txtDOBYear'] = $DOBYear;
57 $post['ctl00$MainContent$txtSearchZipCode'] = $SearchZipCode;
58 $post['txtSearchZipCode'] = $SearchZipCode;
59 $post['ctl00$MainContent$txtSearchHouseNumber'] = $SearchHouseNumber;
60 $post['txtSearchHouseNumber'] = $SearchHouseNumber;
61 $post['ctl00$MainContent$txtSearchMiddleInitial'] = $SearchMiddleInitial;
62 $post['txtSearchMiddleInitial'] = $SearchMiddleInitial;
63 // start a session to get a cookie
64 $form['url'] = 'https://voterservices.elections.maryland.gov/VoterSearch';
65 $form['html'] = getPage($form['url'],'','');
66 // extract the cookie from the header (see CURLOPT_HEADER)
67 $cookie = cut_part_out('ASP.NET_SessionId=',';',$form['html']);
68 // extract the form elements we will need to post with our data
69 $post['__VIEWSTATE'] = cut_part_out('id="__VIEWSTATE" value="','"',$form['html']);
70 $post['__VIEWSTATEGENERATOR'] = cut_part_out('id="__VIEWSTATEGENERATOR" value="','"',$form['html']);
71 $post['__VIEWSTATEENCRYPTED'] = cut_part_out('id="__VIEWSTATEENCRYPTED" value="','"',$form['html']);
72 $post['__EVENTVALIDATION'] = cut_part_out('id="__EVENTVALIDATION" value="','"',$form['html']);
74 echo "<li>COOKIE ASP.NET_SessionId $cookie</li>";
75 echo "<li>POST VIEWSTATE $post[__VIEWSTATE]</li>";
76 echo "<li>POST VIEWSTATEGENERATOR $post[__VIEWSTATEGENERATOR]</li>";
77 echo "<li>POST VIEWSTATEENCRYPTED $post[__VIEWSTATEENCRYPTED]</li>";
78 echo "<li>POST EVENTVALIDATION $post[__EVENTVALIDATION]</li>";
83 $result['html'] = getPage($form['url'],$cookie,$post);
84 //echo "<h1>STEP 2: SBE RESULTS</h1>";
85 $return['debug'] = htmlspecialchars($result['html']);
86 $return['html'] = $result['html'];
90 if (isset($_POST['SearchFirstName'])){
91 $voter = md_voter_lookup($_POST['SearchFirstName'],$_POST['SearchLastName'],$_POST['DOBMonth'],$_POST['DOBDay'],$_POST['DOBYear'],$_POST['SearchZipCode'],$_POST['SearchHouseNumber'],$_POST['SearchMiddleInitial'])
98 <td
>SearchFirstName
</td
><td
><input name
='SearchFirstName'></td
>
101 <td
>SearchLastName
</td
><td
><input name
='SearchLastName'></td
>
104 <td
>DOBMonth
</td
><td
><input name
='DOBMonth'></td
>
107 <td
>DOBDay
</td
><td
><input name
='DOBDay'></td
>
110 <td
>DOBYear
</td
><td
><input name
='DOBYear'></td
>
113 <td
>SearchZipCode
</td
><td
><input name
='SearchZipCode'></td
>
116 <td
>SearchHouseNumber
*</td
><td
><input name
='SearchHouseNumber'></td
>
119 <td
>SearchMiddleInitial
*</td
><td
><input name
='SearchMiddleInitial'></td
>
122 <td
>*Optional
</td
><td
><input type
='submit'></td
>