function generate_otp($email, $mobile) { $resendOtp = true; $url = 'http://10.135.81.82:14280/il/sendOtp'; $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $parameters = array("user" => array("email" => $email, "mobile" => $mobile)); $json = json_encode($parameters); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($json))); $response = curl_exec($curl); $result = json_decode($response, true); $headers = get_headers_from_curl_response($response); return strpos($headers['http_code'], "200") || strpos($headers['http_code'], "202") ? 'Y' : 'N'; }
/** * Run the cURL requests in one place * so we can catch errors etc */ function run_curl_request($curl) { $out['response'] = curl_exec($curl); $out['error'] = curl_errno($curl); if (!$out['error']) { // no error $out['info'] = curl_getinfo($curl); $out['headers'] = get_headers_from_curl_response($out); $out['body'] = trim(substr($out['response'], $out['info']["header_size"])); } else { // we are in error $out['error_message'] = curl_error($curl); } // we close it down after it has been run curl_close($curl); return (object) $out; }
require_once "functions.php"; define("TTS_URL", "http://speech.ssn.edu.in/synthesise.php"); define("DOWNLOAD_URL", "http://speech.ssn.edu.in/wav/"); define("MP3_CONVERTOR", "http://labs.ashwanthkumar.in/ffmpeg/"); $gender = $_POST['gender']; $text = $_POST['text']; $fields = array('options' => urlencode($gender), 'word' => urlencode($text)); $fields_string = ""; foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); // POST TO TTS Server $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, TTS_URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); $response = curl_exec($ch); curl_close($ch); $headers = get_headers_from_curl_response($response); $contentLength = $headers["Content-Length"]; parse_str(parse_url($headers["Location"], PHP_URL_QUERY)); $audioLink = MP3_CONVERTOR . "?stream=true&url=" . urlencode(DOWNLOAD_URL . $name); $result = array("url" => $audioLink, "debug" => array("response" => $response, "gender" => $gender, "text" => $text, "headers" => $headers)); // Returns the urls to download the voices in a JSON header('Content-Type: application/json'); echo json_encode($result);
$UnSubData['RETURL'] = 'success.php'; $UnSubData['FLRETURL'] = 'error.php'; $UnSubData['OTHER1'] = ''; $UnSubData['OTHER2'] = ''; $pString = ''; //print_r($_SERVER['HTTP_HOST']); foreach ($UnSubData as $key => $value) { $pString .= $key . '=' . $value . '&'; } $pString = rtrim($pString, '&'); // print_r($current_url); // echo "<br/>"; $u = $curlObj->executePostCurlHeader($current_url, 1, $pString); $Data = array('Response' => $output, 'MSISDN' => $msisdn, 'OPERATOR' => $opr, 'Transactionid' => $TransId, 'PricePoint' => $cpevent, 'CMode' => $operator, 'Fail Return url' => $ErrorUrl, 'CMODE' => $cmode); //log files to be theres $headers = get_headers_from_curl_response($u['Content']); // print_r($headers); } //include 'header.php'; ?> <tr> <td> <p><center><?php echo $headers['resDesc']; ?> </center></p> </td> </tr> <?php //include 'footer.php'; } else {
public function proxyCodeDxRequest() { $user = User::getIndex(Session::get('user_uid')); // check viewer // $viewerInstance = ViewerInstance::where('proxy_url', '=', Request::segment(1))->first(); if ($viewerInstance) { // get virtual machine info // $vm_ip = $viewerInstance->vm_ip_address; $content = Request::instance()->getContent(); $tfh = tmpfile(); fwrite($tfh, $content); $uri = stream_get_meta_data($tfh)['uri']; $url = "https://{$vm_ip}" . $_SERVER['REQUEST_URI']; $req = "curl -X {$_SERVER['REQUEST_METHOD']} '{$url}' "; if (isset($_COOKIE['JSESSIONID'])) { $req .= " -H 'Cookie: JSESSIONID={$_COOKIE['JSESSIONID']}' "; } $req .= " -H 'Host: {$vm_ip}' "; foreach (getallheaders() as $key => $value) { if (strtolower($key) == 'origin') { $req .= " -H " . escapeshellarg("Origin: {$value}"); } if (strtolower($key) == 'accept-encoding') { $req .= " -H " . escapeshellarg("Accept-Encoding: {$value}"); } if (strtolower($key) == 'accept-language') { $req .= " -H " . escapeshellarg("Accept-Language: {$value}"); } if (strtolower($key) == 'content-type') { $req .= " -H " . escapeshellarg("Content-Type: {$value}"); } if (strtolower($key) == 'accept') { $req .= " -H " . escapeshellarg("Accept: {$value}"); } if (strtolower($key) == 'cache-control') { $req .= " -H " . escapeshellarg("Cache-Control: {$value}"); } if (strtolower($key) == 'x-requested-with') { $req .= " -H " . escapeshellarg("X-Requested-With: {$value}"); } if (strtolower($key) == 'connection') { $req .= " -H " . escapeshellarg("Connection: {$value}"); } if (strtolower($key) == 'referer') { $req .= " -H " . escapeshellarg("Referer: {$value}"); } } $req .= " -H 'AUTHORIZATION: SWAMP " . strtolower($user->username) . "' "; $req .= " -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36' "; $req .= " --data-binary @{$uri} "; $req .= " --compressed --insecure -i"; $response = `{$req}`; fclose($tfh); function get_headers_from_curl_response($headerContent) { $headers = array(); // split the string on every "double" new line. // foreach (explode("\r\n", $headerContent) as $i => $line) { if ($i === 0) { $headers['http_code'] = $line; } else { if (strpos($line, ': ') !== false) { list($key, $value) = explode(': ', $line); $headers[$key][] = $value; } } } return $headers; } $values = preg_split("/\\R\\R/", $response, 2); $header = isset($values[0]) ? $values[0] : ''; $body = isset($values[1]) ? $values[1] : ''; preg_match('|HTTP/\\d\\.\\d\\s+(\\d+)\\s+.*|', $header, $match); $status = $match[1]; $headers = get_headers_from_curl_response($header); $response = Response::make($body ? $body : '', $status); if (isset($headers) && array_key_exists('Content-Type', $headers)) { $response->header('Content-Type', $headers['Content-Type'][0]); } // handle 301 / 302 redirect locations // if (in_array($status, array('301', '302'))) { if (isset($headers) && array_key_exists('Location', $headers)) { $response->header('Location', $headers['Location'][0]); } } // set JSESSIONID when present // if (array_key_exists('Set-Cookie', $headers)) { foreach ($headers['Set-Cookie'] as $setcookie) { $response->header('Set-Cookie', $setcookie); } } return $response; } }