Commit | Line | Data |
---|---|---|
183344e4 | 1 | <?PHP |
e20f7315 PM |
2 | ini_set('display_errors', 1); |
3 | ini_set('display_startup_errors', 1); | |
4 | error_reporting(E_ALL); | |
9f5b3b38 | 5 | |
9f5b3b38 PM |
6 | function cut_part_out($start,$end,$whole){ |
7 | $parts = explode($start,$whole); | |
8 | $subparts = explode($end,$parts[1]); | |
9 | $out = $subparts[0]; | |
10 | return $out; | |
11 | } | |
12 | ||
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 | |
18 | $curl = curl_init(); | |
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); | |
25 | if ($cookie != ''){ | |
26 | curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Cookie: ASP.NET_SessionId=$cookie")); // use cookies | |
27 | } | |
28 | /* | |
29 | $postfields = array( | |
30 | 'upload_file' => '@file_to_upload.png', | |
31 | 'upload_text' => '@text_to_upload' | |
32 | ); | |
33 | */ | |
34 | if ($post != ''){ | |
35 | curl_setopt ($curl, CURLOPT_POSTFIELDS, $post); | |
36 | } | |
37 | $html = curl_exec ($curl); | |
38 | curl_close ($curl); | |
39 | return $html; | |
40 | } | |
41 | ||
79ab6eac PM |
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; | |
8eeb49e5 | 48 | $post['txtSearchFirstName'] = $SearchFirstName; |
79ab6eac PM |
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']); | |
73 | /* | |
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>"; | |
79 | echo "<pre>"; | |
80 | echo print_r($post); | |
81 | echo "</pre>"; | |
82 | */ | |
6a5ac174 | 83 | $result['html'] = getPage($form['url'],$cookie,$post); |
79ab6eac PM |
84 | //echo "<h1>STEP 2: SBE RESULTS</h1>"; |
85 | $return['debug'] = htmlspecialchars($result['html']); | |
86 | $return['html'] = $result['html']; | |
87 | return $return; | |
88 | } | |
89 | ||
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']) | |
92 | echo $voter['html']; | |
6a5ac174 PM |
93 | } |
94 | ?> | |
79ab6eac PM |
95 | <form method='POST'> |
96 | <table> | |
97 | <tr> | |
98 | <td>SearchFirstName</td><td><input name='SearchFirstName'></td> | |
99 | </tr> | |
100 | <tr> | |
101 | <td>SearchLastName</td><td><input name='SearchLastName'></td> | |
102 | </tr> | |
103 | <tr> | |
104 | <td>DOBMonth</td><td><input name='DOBMonth'></td> | |
105 | </tr> | |
106 | <tr> | |
107 | <td>DOBDay</td><td><input name='DOBDay'></td> | |
108 | </tr> | |
109 | <tr> | |
110 | <td>DOBYear</td><td><input name='DOBYear'></td> | |
111 | </tr> | |
112 | <tr> | |
113 | <td>SearchZipCode</td><td><input name='SearchZipCode'></td> | |
114 | </tr> | |
115 | <tr> | |
116 | <td>SearchHouseNumber*</td><td><input name='SearchHouseNumber'></td> | |
117 | </tr> | |
118 | <tr> | |
119 | <td>SearchMiddleInitial*</td><td><input name='SearchMiddleInitial'></td> | |
120 | </tr> | |
121 | <tr> | |
122 | <td>*Optional</td><td><input type='submit'></td> | |
123 | </tr> | |
124 | </table> | |
125 | </form> | |
126 | */ | |
127 | ||
128 | ?> |