2 ini_set('display_errors', 1);
3 ini_set('display_startup_errors', 1);
4 error_reporting(E_ALL
);
6 $post['ctl00$MainContent$listLanguages'] = "en";
7 $post['listLanguages'] = "en";
8 if (isset($_POST['SearchFirstName'])){
9 //$post['SearchFirstName_field'] = 'ctl00$MainContent$txtSearchFirstName';
10 $post['ctl00$MainContent$txtSearchFirstName'] = $_POST['SearchFirstName'];
11 $post['txtSearchFirstName'] = $_POST['SearchFirstName'];
13 $post['ctl00$MainContent$txtSearchFirstName'] = '';
14 $post['txtSearchFirstName'] = '';
16 if (isset($_POST['SearchLastName'])){
17 //$post['SearchLastName_field'] = 'ctl00$MainContent$txtSearchLastName';
18 $post['ctl00$MainContent$txtSearchLastName'] = $_POST['SearchLastName'];
19 $post['ctl00$MainContent$txtSearchLastName'] = $_POST['SearchLastName'];
21 $post['ctl00$MainContent$txtSearchLastName'] = '';
22 $post['txtSearchLastName'] = '';
24 if (isset($_POST['DOBMonth'])){
25 //$post['DOBMonth_field'] = 'ctl00$MainContent$txtDOBMonth';
26 $post['ctl00$MainContent$txtDOBMonth'] = $_POST['DOBMonth'];
27 $post['txtDOBMonth'] = $_POST['DOBMonth'];
29 $post['ctl00$MainContent$txtDOBMonth'] = '';
30 $post['txtDOBMonth'] = '';
32 if (isset($_POST['DOBDay'])){
33 //$post['DOBDay_field'] = 'ctl00$MainContent$txtDOBDay';
34 $post['ctl00$MainContent$txtDOBDay'] = $_POST['DOBDay'];
35 $post['txtDOBDay'] = $_POST['DOBDay'];
37 $post['ctl00$MainContent$txtDOBDay'] = '';
38 $post['txtDOBDay'] = '';
40 if (isset($_POST['DOBYear'])){
41 //$post['DOBYear_field'] = 'ctl00$MainContent$txtDOBYear';
42 $post['ctl00$MainContent$txtDOBYear'] = $_POST['DOBYear'];
43 $post['txtDOBYear'] = $_POST['DOBYear'];
45 $post['ctl00$MainContent$txtDOBYear'] = '';
46 $post['txtDOBYear'] = '';
48 if (isset($_POST['SearchZipCode'])){
49 //$post['SearchZipCode_field'] = 'ctl00$MainContent$txtSearchZipCode';
50 $post['ctl00$MainContent$txtSearchZipCode'] = $_POST['SearchZipCode'];
51 $post['txtSearchZipCode'] = $_POST['SearchZipCode'];
53 $post['ctl00$MainContent$txtSearchZipCode'] = '';
54 $post['txtSearchZipCode'] = '';
56 if (isset($_POST['SearchHouseNumber'])){
57 //$post['SearchZipCode_field'] = 'ctl00$MainContent$txtSearchZipCode';
58 $post['ctl00$MainContent$txtSearchHouseNumber'] = $_POST['SearchHouseNumber'];
59 $post['txtSearchHouseNumber'] = $_POST['SearchHouseNumber'];
61 $post['ctl00$MainContent$txtSearchHouseNumber'] = '';
62 $post['txtSearchHouseNumber'] = '';
64 if (isset($_POST['SearchMiddleInitial'])){
65 //$post['SearchZipCode_field'] = 'ctl00$MainContent$txtSearchZipCode';
66 $post['ctl00$MainContent$txtSearchMiddleInitial'] = $_POST['SearchMiddleInitial'];
67 $post['txtSearchMiddleInitial'] = $_POST['SearchMiddleInitial'];
69 $post['ctl00$MainContent$txtSearchMiddleInitial'] = '';
70 $post['txtSearchMiddleInitial'] = '';
79 <td
>SearchFirstName
</td
><td
><input name
='SearchFirstName' value
='<?PHP echo $post['txtSearchFirstName
'];?>'></td
>
82 <td
>SearchLastName
</td
><td
><input name
='SearchLastName' value
='<?PHP echo $post['txtSearchLastName
'];?>'></td
>
85 <td
>DOBMonth
</td
><td
><input name
='DOBMonth' value
='<?PHP echo $post['txtDOBMonth
'];?>'></td
>
88 <td
>DOBDay
</td
><td
><input name
='DOBDay' value
='<?PHP echo $post['txtDOBDay
'];?>'></td
>
91 <td
>DOBYear
</td
><td
><input name
='DOBYear' value
='<?PHP echo $post['txtDOBYear
'];?>'></td
>
94 <td
>SearchZipCode
</td
><td
><input name
='SearchZipCode' value
='<?PHP echo $post['txtSearchZipCode
'];?>'></td
>
97 <td
>SearchHouseNumber
*</td
><td
><input name
='SearchHouseNumber' value
='<?PHP echo $post['txtSearchHouseNumber
'];?>'></td
>
100 <td
>SearchMiddleInitial
*</td
><td
><input name
='SearchMiddleInitial' value
='<?PHP echo $post['txtSearchMiddleInitial
'];?>'></td
>
103 <td
>*Optional
</td
><td
><input type
='submit'></td
>
110 function cut_part_out($start,$end,$whole){
111 $parts = explode($start,$whole);
112 $subparts = explode($end,$parts[1]);
117 function getPage($url,$cookie,$post){
118 $url = str_replace('[month]',date('F'),$url); // replace month January through December
119 $url = str_replace('[day]',date('j'),$url); // replace day 1 to 31
120 $url = str_replace('[yesterday]',date('j',strtotime('yesterday')),$url); // replace day 1 to 31
121 $url = str_replace('[year]',date('Y'),$url); // replace year Examples: 1999 or 2003
123 curl_setopt ($curl, CURLOPT_URL
, $url);
124 curl_setopt ($curl, CURLOPT_USERAGENT
, sprintf("McGuire MEPS https://www.md-petition.com/ /%d.0",rand(4,50)));
125 curl_setopt ($curl, CURLOPT_RETURNTRANSFER
, 1);
126 curl_setopt ($curl, CURLOPT_HEADER
, 1);
127 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER
, 0);
128 curl_setopt ($curl, CURLOPT_FOLLOWLOCATION
, true);
130 curl_setopt ($curl, CURLOPT_HTTPHEADER
, array("Cookie: ASP.NET_SessionId=$cookie")); // use cookies
134 'upload_file' => '@file_to_upload.png',
135 'upload_text' => '@text_to_upload'
139 curl_setopt ($curl, CURLOPT_POSTFIELDS
, $post);
141 $html = curl_exec ($curl);
146 // start a session to get a cookie
147 $form['url'] = 'https://voterservices.elections.maryland.gov/VoterSearch';
148 $form['html'] = getPage($form['url'],'','');
150 // extract the cookie from the header (see CURLOPT_HEADER)
151 $cookie = cut_part_out('ASP.NET_SessionId=',';',$form['html']);
152 // extract the form elements we will need to post with our data
153 $post['__VIEWSTATE'] = cut_part_out('id="__VIEWSTATE" value="','"',$form['html']);
154 $post['__VIEWSTATEGENERATOR'] = cut_part_out('id="__VIEWSTATEGENERATOR" value="','"',$form['html']);
155 $post['__VIEWSTATEENCRYPTED'] = cut_part_out('id="__VIEWSTATEENCRYPTED" value="','"',$form['html']);
156 $post['__EVENTVALIDATION'] = cut_part_out('id="__EVENTVALIDATION" value="','"',$form['html']);
157 // Voter Info Form Elements
158 //$post['Languages_field'] = 'ctl00$MainContent$listLanguages';
160 // debug - show full response make sure we have the cookie
161 echo "<li>COOKIE ASP.NET_SessionId $cookie</li>";
162 echo "<li>POST VIEWSTATE $post[__VIEWSTATE]</li>";
163 echo "<li>POST VIEWSTATEGENERATOR $post[__VIEWSTATEGENERATOR]</li>";
164 echo "<li>POST VIEWSTATEENCRYPTED $post[__VIEWSTATEENCRYPTED]</li>";
165 echo "<li>POST EVENTVALIDATION $post[__EVENTVALIDATION]</li>";
169 echo "<hr><hr><hr><h1>Voter Form</h1>";
170 echo htmlspecialchars($form['html']);
174 if ($post['txtSearchFirstName'] != ''){
175 $result['html'] = getPage($form['url'],$cookie,$post);
176 echo "<hr><hr><hr><h1>SBE API RESULTS</h1>";
177 echo htmlspecialchars($result['html']);
179 echo $result['html'];