Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function toMid($user, $pass) {
- /* Takes a ucid and password as args
- Builds a curl req to the middle-end
- Returns the response
- Making:
- curl -L 'https://aevitepr2.njit.edu/MyHousing/login.cfm' \
- -H 'Content-Type: application/x-www-form-urlencoded' \
- -H 'Upgrade-Insecure-Requests: 1'\
- --data 'ucid=[ucid]&pass=[pass]'
- */
- $login = array(
- "ucid" => $user,
- "pass" => $pass
- );
- $Mid_url = 'https://web.njit.edu/~md537/mid.php';
- $headers = [
- 'Content-Type: application/json; charset=utf-8'
- //'Host: web.njit.edu',
- ];
- // echo json_encode($login);
- $ch = curl_init($Mid_url); //Init curl
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_POST, true);
- // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirect to new housing page
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($login)); // concat ucid/pass
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return results to stdout instead of echo
- $result = curl_exec($ch); // send the curl, return result (actually html page after redir)
- echo "curl errors?:\n";
- echo curl_error($ch);
- curl_close($ch);
- return $result;
- }
- /* get data from index.thml */
- // $data = json_decode($HTTP_RAW_POST_DATA);
- $ucid_POST = 'useranme';//$data->ucid;
- $pass_POST = 'password';//$data->pass;
- /* get response from mid */
- $result = toMid($ucid_POST, $pass_POST);
- echo $result;
- // $result = json_decode($result, 1);
- echo "decoded data\n";
- var_dump((json_decode($result))); // this is null
- // echo json_decode($result);
- // $ucid_Response = $result->njitucid;
- // $njit_Response = $result->njitsuccess;
- /* send this to index.html */
- $to_frt = array(
- 'response' => array(
- // 'njitucid' => $ucid_Response,
- // 'njitsuccess' => $njit_Response,
- 'dbucid' => $ucid_POST,
- 'dbsuccess' => '0',
- 'debug' => $result
- )
- );
- // header('Content-Type: application/json;charset=utf-8');
- // echo json_encode($to_frt);
- echo "SUCCESS";
- http_response_code(200);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement