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 // start a session to get a cookie
43 $form['url'] = 'https://voterservices.elections.maryland.gov/VoterSearch';
44 $form['html'] = getPage($form['url'],'','');
46 // extract the cookie from the header (see CURLOPT_HEADER)
47 $cookie = cut_part_out('ASP.NET_SessionId=',';',$form['html']);
48 // extract the form elements we will need to post with our data
49 $post['__VIEWSTATE'] = cut_part_out('id="__VIEWSTATE" value="','"',$form['html']);
50 $post['__VIEWSTATEGENERATOR'] = cut_part_out('id="__VIEWSTATEGENERATOR" value="','"',$form['html']);
51 $post['__VIEWSTATEENCRYPTED'] = cut_part_out('id="__VIEWSTATEENCRYPTED" value="','"',$form['html']);
52 $post['__EVENTVALIDATION'] = cut_part_out('id="__EVENTVALIDATION" value="','"',$form['html']);
53 // Voter Info Form Elements
54 //$post['Languages_field'] = 'ctl00$MainContent$listLanguages';
55 $post['ctl00$MainContent$listLanguages'] = "en";
56 $post['listLanguages'] = "en";
57 if (isset($_POST['SearchFirstName'])){
58 //$post['SearchFirstName_field'] = 'ctl00$MainContent$txtSearchFirstName';
59 $post['ctl00$MainContent$txtSearchFirstName'] = $_POST['SearchFirstName'];
60 $post['txtSearchFirstName'] = $_POST['SearchFirstName'];
62 $post['ctl00$MainContent$txtSearchFirstName'] = '';
63 $post['txtSearchFirstName'] = '';
65 if (isset($_POST['SearchLastName'])){
66 //$post['SearchLastName_field'] = 'ctl00$MainContent$txtSearchLastName';
67 $post['ctl00$MainContent$txtSearchLastName'] = $_POST['SearchLastName'];
68 $post['ctl00$MainContent$txtSearchLastName'] = $_POST['SearchLastName'];
70 $post['ctl00$MainContent$txtSearchLastName'] = '';
71 $post['txtSearchLastName'] = '';
73 if (isset($_POST['DOBMonth'])){
74 //$post['DOBMonth_field'] = 'ctl00$MainContent$txtDOBMonth';
75 $post['ctl00$MainContent$txtDOBMonth'] = $_POST['DOBMonth'];
76 $post['txtDOBMonth'] = $_POST['DOBMonth'];
78 $post['ctl00$MainContent$txtDOBMonth'] = '';
79 $post['txtDOBMonth'] = '';
81 if (isset($_POST['DOBDay'])){
82 //$post['DOBDay_field'] = 'ctl00$MainContent$txtDOBDay';
83 $post['ctl00$MainContent$txtDOBDay'] = $_POST['DOBDay'];
84 $post['txtDOBDay'] = $_POST['DOBDay'];
86 $post['ctl00$MainContent$txtDOBDay'] = '';
87 $post['txtDOBDay'] = '';
89 if (isset($_POST['DOBYear'])){
90 //$post['DOBYear_field'] = 'ctl00$MainContent$txtDOBYear';
91 $post['ctl00$MainContent$txtDOBYear'] = $_POST['DOBYear'];
92 $post['txtDOBYear'] = $_POST['DOBYear'];
94 $post['ctl00$MainContent$txtDOBYear'] = '';
95 $post['txtDOBYear'] = '';
97 if (isset($_POST['SearchZipCode'])){
98 //$post['SearchZipCode_field'] = 'ctl00$MainContent$txtSearchZipCode';
99 $post['ctl00$MainContent$txtSearchZipCode'] = $_POST['SearchZipCode'];
100 $post['txtSearchZipCode'] = $_POST['SearchZipCode'];
102 $post['ctl00$MainContent$txtSearchZipCode'] = '';
103 $post['txtSearchZipCode'] = '';
105 if (isset($_POST['SearchHouseNumber'])){
106 //$post['SearchZipCode_field'] = 'ctl00$MainContent$txtSearchZipCode';
107 $post['ctl00$MainContent$txtSearchHouseNumber'] = $_POST['SearchHouseNumber'];
108 $post['txtSearchHouseNumber'] = $_POST['SearchHouseNumber'];
110 $post['ctl00$MainContent$txtSearchHouseNumber'] = '';
111 $post['txtSearchHouseNumber'] = '';
113 if (isset($_POST['SearchMiddleInitial'])){
114 //$post['SearchZipCode_field'] = 'ctl00$MainContent$txtSearchZipCode';
115 $post['ctl00$MainContent$txtSearchMiddleInitial'] = $_POST['SearchMiddleInitial'];
116 $post['txtSearchMiddleInitial'] = $_POST['SearchMiddleInitial'];
118 $post['ctl00$MainContent$txtSearchMiddleInitial'] = '';
119 $post['txtSearchMiddleInitial'] = '';
121 // debug - show full response make sure we have the cookie
122 echo "<li>COOKIE ASP.NET_SessionId $cookie</li>";
123 echo "<li>POST VIEWSTATE $post[__VIEWSTATE]</li>";
124 echo "<li>POST VIEWSTATEGENERATOR $post[__VIEWSTATEGENERATOR]</li>";
125 echo "<li>POST VIEWSTATEENCRYPTED $post[__VIEWSTATEENCRYPTED]</li>";
126 echo "<li>POST EVENTVALIDATION $post[__EVENTVALIDATION]</li>";
130 echo "<hr><hr><hr><h1>Voter Form</h1>";
131 echo htmlspecialchars($form['html']);
133 //echo $form['html'];
138 <td
>SearchFirstName
</td
><td
><input name
='SearchFirstName'></td
>
141 <td
>SearchLastName
</td
><td
><input name
='SearchLastName'></td
>
144 <td
>DOBMonth
</td
><td
><input name
='DOBMonth'></td
>
147 <td
>DOBDay
</td
><td
><input name
='DOBDay'></td
>
150 <td
>DOBYear
</td
><td
><input name
='DOBYear'></td
>
153 <td
>SearchZipCode
</td
><td
><input name
='SearchZipCode'></td
>
156 <td
>SearchHouseNumber
*</td
><td
><input name
='SearchHouseNumber'></td
>
159 <td
>SearchMiddleInitial
*</td
><td
><input name
='SearchMiddleInitial'></td
>
162 <td
>*Optional
</td
><td
><input type
='submit'></td
>
167 if ($post['txtSearchFirstName'] != ''){
168 $result['html'] = getPage($form['url'],$cookie,$post);
169 echo "<hr><hr><hr><h1>SBE API RESULTS</h1>";
170 echo htmlspecialchars($result['html']);
172 echo $result['html'];