/** * Submits an HTTP POST to a reCAPTCHA server * @param string $host * @param string $path * @param array $data * @param int port * @return array response */ function _recaptcha_http_post($host, $path, $data, $port = 80) { $req = _recaptcha_qsencode($data); $proxy_host = "proxy.iiit.ac.in"; $proxy_port = "8080"; $http_request = "POST http://{$host}{$path} HTTP/1.0\r\n"; $http_request .= "Host: {$host}\r\n"; $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; $http_request .= "Content-Length: " . strlen($req) . "\r\n"; $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; $http_request .= "\r\n"; $http_request .= $req; $response = ''; if (false == ($fs = @fsockopen($proxy_host, $proxy_port, $errno, $errstr, 10))) { die('Could not open socket aah'); } fwrite($fs, $http_request); while (!feof($fs)) { $response .= fgets($fs, 1160); } // One TCP-IP packet fclose($fs); $response = explode("\r\n\r\n", $response, 2); return $response; }
function verifCode($decryptedTabIdMdp) { if (file_exists("C:\\wamp64\\www\\Web\\" . $decryptedTabIdMdp->identifiant) == true) { //Si oui on ouvre le dossier et on recupere le mot de passe. $handle = fopen("C:\\wamp64\\www\\Web\\" . $decryptedTabIdMdp->identifiant . "\\Confg.txt", "r+"); fgets($handle); $Code = fgets($handle); $Code = explode(":", $Code); $Code = $Code[1]; fclose($handle); $Code = dechiffrementdata($Code, $decryptedTabIdMdp->IV); //On verifie le mot de passe if ($Code == $decryptedTabIdMdp->code) { // Si la comparraison est ok on renvoie vrai $ok = "vrai\\\\" . $Code; } else { // Si la comparraison n'est pas correcte on renvoie faux $Anwser = 'null'; $ok = "faux\\\\" . $Anwser; } return $ok; } else { $Anwser = 'null'; $ok = "faux\\\\" . $Anwser; } }
/** * Constructor. * * @param Horde_Vcs_Base $rep A repository object. * @param string $dn Path to the directory. * @param array $opts Any additional options: * * @throws Horde_Vcs_Exception */ public function __construct(Horde_Vcs_Base $rep, $dn, $opts = array()) { parent::__construct($rep, $dn, $opts); $cmd = $rep->getCommand() . ' ls ' . escapeshellarg($rep->sourceroot . $this->_dirName); $dir = proc_open($cmd, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes); if (!$dir) { throw new Horde_Vcs_Exception('Failed to execute svn ls: ' . $cmd); } if ($error = stream_get_contents($pipes[2])) { proc_close($dir); throw new Horde_Vcs_Exception($error); } /* Create two arrays - one of all the files, and the other of all the * dirs. */ $errors = array(); while (!feof($pipes[1])) { $line = chop(fgets($pipes[1], 1024)); if (!strlen($line)) { continue; } if (substr($line, 0, 4) == 'svn:') { $errors[] = $line; } elseif (substr($line, -1) == '/') { $this->_dirs[] = substr($line, 0, -1); } else { $this->_files[] = $rep->getFile($this->_dirName . '/' . $line); } } proc_close($dir); }
function test_instam($key) { // returns array, or FALSE // snap(basename(__FILE__) . __LINE__, $key_val); // http://www.instamapper.com/api?action=getPositions&key=4899336036773934943 $url = "http://www.instamapper.com/api?action=getPositions&key={$key}"; $data = ""; if (function_exists("curl_init")) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); } else { // not CURL if ($fp = @fopen($url, "r")) { while (!feof($fp) && strlen($data) < 9000) { $data .= fgets($fp, 128); } fclose($fp); } else { // print "-error 1"; // @fopen fails return FALSE; } } /* InstaMapper API v1.00 1263013328977,bold,1236239763,34.07413,-118.34940,25.0,0.0,335 1088203381874,CABOLD,1236255869,34.07701,-118.35262,27.0,0.4,72 */ // dump($data); $ary_data = explode("\n", $data); return $ary_data; }
public function send_mail() { $talk = array(); if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) { fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n"); $talk["hello"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "auth login\r\n"); $talk["res"] = fgets($SMTPIN, 1024); fputs($SMTPIN, $this->SmtpUser . "\r\n"); $talk["user"] = fgets($SMTPIN, 1024); fputs($SMTPIN, $this->SmtpPass . "\r\n"); $talk["pass"] = fgets($SMTPIN, 256); fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n"); $talk["From"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n"); $talk["To"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "DATA\r\n"); $talk["data"] = fgets($SMTPIN, 1024); //Construct Headers $headers = "MIME-Version: 1.0" . $this->newLine; $headers .= "Content-type: text/html; charset=iso-8859-1" . $this->newLine; $headers .= "From: <" . $this->from . ">" . $this->newLine; $headers .= "To: <" . $this->to . ">" . $this->newLine; $headers .= "Bcc: {$this->newLine}"; $headers .= "Subject: " . $this->subject . $this->newLine; fputs($SMTPIN, $headers . "\r\n\r\n" . $this->body . "\r\n.\r\n"); $talk["send"] = fgets($SMTPIN, 256); //CLOSE CONNECTION AND EXIT ... fputs($SMTPIN, "QUIT\r\n"); fclose($SMTPIN); } return $talk; }
private function convert_file($source, $dest) { // Узнаем какая кодировка у файла $teststring = file_get_contents($source, null, null, null, 1000000); // Кодировка - UTF8 if (preg_match('//u', $teststring)) { // Просто копируем файл return copy($source, $dest); } else { // Конвертируем в UFT8 if (!($src = fopen($source, "r"))) { return false; } if (!($dst = fopen($dest, "w"))) { return false; } while (($line = fgets($src, 4096)) !== false) { $line = $this->win_to_utf($line); fwrite($dst, $line); } fclose($src); fclose($dst); return true; } }
/** * url 为服务的url地址 * query 为请求串 */ private function sock_post($url, $query) { $data = ""; $info = parse_url($url); $fp = fsockopen($info["host"], 80, $errno, $errstr, 30); if (!$fp) { return $data; } $head = "POST " . $info['path'] . " HTTP/1.0\r\n"; $head .= "Host: " . $info['host'] . "\r\n"; $head .= "Referer: http://" . $info['host'] . $info['path'] . "\r\n"; $head .= "Content-type: application/x-www-form-urlencoded\r\n"; $head .= "Content-Length: " . strlen(trim($query)) . "\r\n"; $head .= "\r\n"; $head .= trim($query); $write = fputs($fp, $head); $header = ""; while ($str = trim(fgets($fp, 4096))) { $header .= $str; } while (!feof($fp)) { $data .= fgets($fp, 4096); } return $data; }
public function testLifetime() { $cache = $this->_getCacheDriver(); // Test save $cache->save('test_key', 'testing this out', 10); // Test contains to test that save() worked $this->assertTrue($cache->contains('test_key')); // Test fetch $this->assertEquals('testing this out', $cache->fetch('test_key')); // access private methods $getFilename = new \ReflectionMethod($cache, 'getFilename'); $getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId'); $getFilename->setAccessible(true); $getNamespacedId->setAccessible(true); $id = $getNamespacedId->invoke($cache, 'test_key'); $filename = $getFilename->invoke($cache, $id); $data = ''; $lifetime = 0; $resource = fopen($filename, "r"); if (false !== ($line = fgets($resource))) { $lifetime = (int) $line; } while (false !== ($line = fgets($resource))) { $data .= $line; } $this->assertNotEquals(0, $lifetime, 'previous lifetime could not be loaded'); // update lifetime $lifetime = $lifetime - 20; file_put_contents($filename, $lifetime . PHP_EOL . $data); // test expired data $this->assertFalse($cache->contains('test_key')); $this->assertFalse($cache->fetch('test_key')); }
function SendMail() { if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) { fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n"); $talk["hello"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "auth login\r\n"); $talk["res"] = fgets($SMTPIN, 1024); fputs($SMTPIN, $this->SmtpUser . "\r\n"); $talk["user"] = fgets($SMTPIN, 1024); fputs($SMTPIN, $this->SmtpPass . "\r\n"); $talk["pass"] = fgets($SMTPIN, 256); fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n"); $talk["From"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n"); $talk["To"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "DATA\r\n"); $talk["data"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "To: <" . $this->to . ">\r\nFrom: <" . $this->from . ">\r\nSubject:" . $this->subject . "\r\n\r\n\r\n" . $this->body . "\r\n.\r\n"); $talk["send"] = fgets($SMTPIN, 256); //CLOSE CONNECTION AND EXIT ... fputs($SMTPIN, "QUIT\r\n"); fclose($SMTPIN); // } return $talk; }
/** * Purge URL coming from stdin */ private function doPurge() { $stdin = $this->getStdin(); $urls = array(); while (!feof($stdin)) { $page = trim(fgets($stdin)); if (preg_match('%^https?://%', $page)) { $urls[] = $page; } elseif ($page !== '') { $title = Title::newFromText($page); if ($title) { $url = $title->getInternalURL(); $this->output("{$url}\n"); $urls[] = $url; if ($this->getOption('purge')) { $title->invalidateCache(); } } else { $this->output("(Invalid title '{$page}')\n"); } } } $this->output("Purging " . count($urls) . " urls\n"); $this->sendPurgeRequest($urls); }
function jyxo_bot($q = "", $d = "mm", $ereg = ".", $notereg = "", $cnt = 10000000000000, $page = 1, $pmax = 2, $o = "nocls") { $i = 0; $results = ""; $results[$i] = ""; //$q = str_replace(" ", "+", $q); $q = urlencode($q); for (; $page <= $pmax; $page++) { $request = "http://jyxo.cz/s?q={$q}&d={$d}&o={$o}&cnt={$cnt}&page={$page}"; $fp = fopen($request, "r") or die(" !!! Cannot connect !!!"); while (!feof($fp)) { $line = fgets($fp); if (eregi("<div class='r'>", $line) && ereg(" class=ri", $line)) { $line = explode("<!--m--><div class='r'><A HREF=\"", $line); $line = $line[1]; $line = explode("\" class=ri", $line); $line = trim($line[0]); $line = urldecode($line); if (@eregi($ereg, $line) && !@eregi($notereg, $line) && !in_array($line, $results)) { echo "{$line}\n"; //Output //echo("$i:$line\n"); //Indexed Output //echo("<a href=\"$line\">$line</a><br />\n"); //XHTML Output $results[$i] = $line; $i++; } } } fclose($fp); } echo "\nTotal: {$i}\n"; //Sumary Output return $results; }
/** * _loadIni * * @param void * * @return void **/ protected function _loadIni() { if(file_exists($this->_mFilePath)){ $key = null; $file = fopen($this->_mFilePath, 'r'); for($lineNum=1; $line=fgets($file);$lineNum++){ if(substr($line,1,1)==';'||substr($line,1,1)=='#'||substr($line,1,2)=='//'){ continue; } elseif(preg_match('/\[(.*)\]/', $line, $str)){ if($this->_mSectionFlag===true){ $key = $str[1]; $this->_mConfig[$key] = array(); } } elseif(preg_match('/(.*)=(.*)/', $line, $str)){ if(preg_match('/^\"(.*)\"$/', $str[2], $body)||preg_match('/^\'(.*)\'$/', $str[2], $body)){ $str[2] = $body[1]; } if($this->_mSectionFlag===true){ $this->_mConfig[$key][$str[1]] = $str[2]; } else{ $this->_mConfig[$str[1]] = $str[2]; } } } } }
function cli_read() { $handle = fopen("php://stdin", "r"); $line = trim(fgets($handle)); fclose($handle); return $line; }
/** * Retrieve all options array * * @return array */ public function getAllOptions() { $taxonomyPath = Mage::getBaseDir() . self::TAXONOMY_FILE_PATH; $lang = Mage::getStoreConfig('general/locale/code', Mage::app()->getRequest()->getParam('store', 0)); $taxonomyFile = $taxonomyPath . "taxonomy-with-ids." . $lang . ".txt"; if (!file_exists($taxonomyFile)) { $taxonomyFile = $taxonomyPath . "taxonomy-with-ids.en_US.txt"; } if (is_null($this->_options)) { $this->_options = array(); $this->_options[0] = array('value' => 0, 'label' => "0 Other"); if (($fh = fopen($taxonomyFile, "r")) !== false) { $line = 0; while (($category = fgets($fh)) !== false) { $line++; if ($line === 1) { continue; } // skip first line $option = explode(' - ', $category); $this->_options[] = array('value' => $option[0], 'label' => $category); } } } return $this->_options; }
private function transmit($command, $expect = NULL) { fwrite($this->stdio, $command); usleep(80000); while ($line = fgets($this->stdio)) { $cmdresult .= trim($line); } if ($expect) { $i = 250000; while ($i <= 2000000 && strpos($cmdresult, $expect) === FALSE) { //echo "USLEEP: " . $i . "\n"; usleep($i); while ($line = fgets($this->stdio)) { $cmdresult .= trim($line); } $i *= 2; // backoff wait time } if ($i > 2000000 && strpos($cmdresult, $expect) === FALSE) { $retarr['error'] = 1; } else { $retarr['error'] = 0; } } else { $retarr['error'] = 0; } $retarr['unfiltered'] = $cmdresult; $retarr['result'] = self::iii_filter($cmdresult); return $retarr; }
function getClient() { $client = new Google_Client(); $client->setApplicationName(APPLICATION_NAME); $client->setScopes(SCOPES); $client->setAuthConfigFile(CLIENT_SECRET); $client->setAccessType('offline'); // Load previously authorized credentials from a file. $credentialsPath = expandHomeDirectory(CREDENTIAL_PATH); if (file_exists($credentialsPath)) { $accessToken = file_get_contents($credentialsPath); } else { // Request authorization from the user. $authUrl = $client->createAuthUrl(); printf("Open the following link in your browser:\n\n\t%s\n\n", $authUrl); print 'Enter verification code: '; $authCode = trim(fgets(STDIN)); // Exchange authorization code for an access token. $accessToken = $client->authenticate($authCode); // Store the credentials to disk. if (!file_exists(dirname($credentialsPath))) { mkdir(dirname($credentialsPath), 0700, true); } file_put_contents($credentialsPath, $accessToken); printf("Credentials saved to %s\n", $credentialsPath); } $client->setAccessToken($accessToken); // Refresh the token if it's expired. if ($client->isAccessTokenExpired()) { $client->refreshToken($client->getRefreshToken()); file_put_contents($credentialsPath, $client->getAccessToken()); } return $client; }
public function ask_options($question, $options, $default_index = 0) { while (TRUE) { echo $question; for ($i = 0; $i < count($options); $i++) { echo $i + 1 . ') ' . $options[$i] . "\n"; } echo '[default: ' . $options[$default_index] . "]\n"; $tmp = trim(fgets(STDIN)); try { if (strlen($tmp) > 0) { if (is_numeric($tmp)) { if ($tmp >= 1 and $tmp <= count($options)) { return $options[$tmp - 1]; } else { throw new InputValidation_InvalidInputException('Please enter a number between 1 and ' . count($options) . '!'); } } else { throw new InputValidation_InvalidInputException('Please enter a number!'); } } else { return $options[$default_index]; } } catch (InputValidation_InvalidInputException $e) { echo $e->getMessage() . "\n"; } } }
public static function input($prefix = '') { if (static::readline_support()) { return readline($prefix); } return fgets(STDIN); }
protected function handshake($connect) { $info = array(); $line = fgets($connect); $header = explode(' ', $line); $info['method'] = $header[0]; $info['uri'] = $header[1]; //считываем заголовки из соединения while ($line = rtrim(fgets($connect))) { if (preg_match('/\\A(\\S+): (.*)\\z/', $line, $matches)) { $info[$matches[1]] = $matches[2]; } else { break; } } $address = explode(':', stream_socket_get_name($connect, true)); //client address $info['ip'] = $address[0]; $info['port'] = $address[1]; if (empty($info['Sec-WebSocket-Key'])) { return false; } //websocket header $SecWebSocketAccept = base64_encode(pack('H*', sha1($info['Sec-WebSocket-Key'] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'))); $upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . "Upgrade: websocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Accept:{$SecWebSocketAccept}\r\n\r\n"; fwrite($connect, $upgrade); return $info; }
function bacaFile($namafile) { global $dir, $mysqli; $file = fopen(getcwd() . "/" . $namafile, "r"); $baris = fgets($file); while (($baris = fgets($file)) == !FALSE) { $data = explode(",", $baris); if (count($data) > 3) { $strAngkot = $data[0]; $strSQL = "SELECT * FROM angkot WHERE angkot_name = '{$strAngkot}'"; $rst = $mysqli->query($strSQL); $rows = $rst->fetch_array(); if (count($rows) == 0) { $strSQL = "INSERT INTO angkot SET angkot_name = '{$strAngkot}', angkot_desc = '{$strAngkot}', angkot_price = '4000'"; $rst = $mysqli->query($strSQL); $angkot_id = $mysqli->insert_id; } else { $angkot_id = $rows[0]; } $strJalan = $data[1]; $latitude = $data[2]; $longitude = $data[3]; $strSQL = "INSERT INTO rute SET angkot_id = '{$angkot_id}', rute_name = '{$strJalan}', latitude = '{$latitude}', longitude = '{$longitude}'"; $rst = $mysqli->query($strSQL); } } }
function sendMemcacheCommand($server, $port, $command) { $s = @fsockopen($server, $port); if (!$s) { die("Cant connect to:" . $server . ':' . $port); } fwrite($s, $command . "\r\n"); $buf = ''; while (!feof($s)) { $buf .= fgets($s, 256); if (strpos($buf, "END\r\n") !== false) { // stat says end break; } if (strpos($buf, "DELETED\r\n") !== false || strpos($buf, "NOT_FOUND\r\n") !== false) { // delete says these break; } if (strpos($buf, "OK\r\n") !== false) { // flush_all says ok break; } } fclose($s); return parseMemcacheResults($buf); }
/** * Iterate over given file handler and write a set of INSERT statements for * each line * * @param ressource $_fileHandler * @return void */ protected function textToSQL($_fileHandler) { while (($buffer = fgets($_fileHandler)) !== false) { $results = $this->splitLine($buffer); $this->writeSQL($results); } }
function http_send($_url, $_body) { $errno = 0; $errstr = ''; $timeout = 10; $fp = fsockopen(_IP_, _PORT_, $errno, $errstr, $timeout); if (!$fp) { return FALSE; } $_head = "POST /" . $_url . " HTTP/1.1\r\n"; $_head .= "Host: " . _IP_ . ":" . _PORT_ . "\r\n"; $_head .= "Content-Type: Text/plain\r\n"; if (!$_body) { $body_len = 0; } else { $body_len = strlen($_body); } $send_pkg = $_head . "Content-Length:" . $body_len . "\r\n\r\n" . $_body; ilog(iLOG_INFO, " -----> http_send url: " . $_url); ilog(iLOG_INFO, " -----> http_send body: " . $_body); if (fputs($fp, $send_pkg) === FALSE) { return FALSE; } //设置3s超时 stream_set_timeout($fp, 3); while (!feof($fp)) { ilog(iLOG_INFO, " -----> rsp: " . fgets($fp, 128)); } if ($fp) { fclose($fp); } return TRUE; }
function send_request_via_fsockopen1($host, $path, $content) { $posturl = "ssl://" . $host; $header = "Host: {$host}\r\n"; $header .= "User-Agent: PHP Script\r\n"; $header .= "Content-Type: text/xml\r\n"; $header .= "Content-Length: " . strlen($content) . "\r\n"; $header .= "Connection: close\r\n\r\n"; $fp = fsockopen($posturl, 443, $errno, $errstr, 30); if (!$fp) { $response = false; } else { error_reporting(E_ERROR); fputs($fp, "POST {$path} HTTP/1.1\r\n"); fputs($fp, $header . $content); fwrite($fp, $out); $response = ""; while (!feof($fp)) { $response = $response . fgets($fp, 128); } fclose($fp); error_reporting(E_ALL ^ E_NOTICE); } return $response; }
/** * Gets an OAuth2 credential. * @param AdWordsUser $user the user that contains the client ID and secret * @return array the user's OAuth 2 credentials */ function GetOAuth2Credential(AdWordsUser $user) { $redirectUri = NULL; $offline = TRUE; // Get the authorization URL for the OAuth2 token. // No redirect URL is being used since this is an installed application. A web // application would pass in a redirect URL back to the application, // ensuring it's one that has been configured in the API console. // Passing true for the second parameter ($offline) will provide us a refresh // token which can used be refresh the access token when it expires. $OAuth2Handler = $user->GetOAuth2Handler(); $authorizationUrl = $OAuth2Handler->GetAuthorizationUrl($user->GetOAuth2Info(), $redirectUri, $offline); // In a web application you would redirect the user to the authorization URL // and after approving the token they would be redirected back to the // redirect URL, with the URL parameter "code" added. For desktop // or server applications, spawn a browser to the URL and then have the user // enter the authorization code that is displayed. printf("Log in to your AdWords account and open the following URL:\n%s\n\n", $authorizationUrl); print "After approving the token enter the authorization code here: "; $stdin = fopen('php://stdin', 'r'); $code = trim(fgets($stdin)); fclose($stdin); print "\n"; // Get the access token using the authorization code. Ensure you use the same // redirect URL used when requesting authorization. $user->SetOAuth2Info($OAuth2Handler->GetAccessToken($user->GetOAuth2Info(), $code, $redirectUri)); // The access token expires but the refresh token obtained for offline use // doesn't, and should be stored for later use. return $user->GetOAuth2Info(); }
/** * ask * * @return void */ public function ask() { $args = func_get_args(); call_user_func_array(array($this, 'notify'), $args); $answer = strtolower(trim(fgets(STDIN))); return $answer; }
function PostRequest($url, $referer, $_data, $addheader = null) { $data = null; while (list($n, $v) = each($_data)) { $data .= '&' . $n . '=' . rawurlencode($v); } $data = substr($data, 1); $url = parse_url($url); if ($url['scheme'] != 'http') { die("Only HTTP-Request are supported"); } $host = $url['host']; $path = $url['path']; $fp = fsockopen($host, 80); fputs($fp, "POST {$path} HTTP/1.1\r\n"); fputs($fp, "Host: {$host}\r\n"); fputs($fp, "Referer: {$referer}\r\n"); fputs($fp, "User-Agent: BotTool (http://testhh.pytalhost.com)\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: " . strlen($data) . "\r\n"); if ($addheader != '') { fputs($fp, $addheader); } fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = null; while (!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); $result = explode("\r\n\r\n", $result, 2); $header = isset($result[0]) ? $result[0] : ''; $content = isset($result[1]) ? $result[1] : ''; return array($header, $content); }
function sendit($param) { $prefix = $_POST['prefix']; $data = $_POST['sql_text']; $host = $_POST['hostname']; $page = isset($_POST['dir']) ? '/' . $_POST['dir'] : ''; $page .= '/modules.php?name=Search'; $method = $_POST['method']; $ref_text = $_POST['ref_text']; $user_agent = $_POST['user_agent']; $result = ''; $sock = fsockopen($host, 80, $errno, $errstr, 50); if (!$sock) { die("{$errstr} ({$errno})\n"); } fputs($sock, "{$method} /{$page} HTTP/1.0\r\n"); fputs($sock, "Host: {$host}" . "\r\n"); fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($sock, "Content-length: " . strlen($data) . "\r\n"); fputs($sock, "Referer: {$ref_text}" . "\r\n"); fputs($sock, "User-Agent: {$user_agent}" . "\r\n"); fputs($sock, "Accept: */*\r\n"); fputs($sock, "\r\n"); fputs($sock, "{$data}\r\n"); fputs($sock, "\r\n"); while (!feof($sock)) { $result .= fgets($sock, 8192); } fclose($sock); return $result; }
/** * Prompts user for a configuration $option and returns the resulting input. * * @param $option {String} * The name of the option to configure. * @param $default {String} Optional, default: <none> * The default value to use if no answer is given. * @param $comment {String} Optional, default: $option * Help text used when prompting the user. Also used as a comment in * the configuration file. * @param $secure {Boolean} Optional, default: false * True if user input should not be echo'd back to the screen as it * is entered. Useful for passwords. * @param $unknown {Boolean} Optional, default: false * True if the configuration option is not a well-known option and * a warning should be printed. * * @return {String} * The configured value for the requested option. */ function configure($option, $default = null, $comment = '', $secure = false, $unknown = false) { global $NO_PROMPT; if ($NO_PROMPT) { return $default; } // check if windows static $isWindows = null; if ($isWindows === null) { $isWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; } if ($unknown) { // Warn user about an unknown configuration option being used. print "\nThis next option ({$option}) is an unknown configuration" . " option, which may mean it has been deprecated or removed.\n\n"; } // Make sure we have good values for I/O. $help = $comment !== null && $comment !== '' ? $comment : $option; // Prompt for and read the configuration option value printf("%s [%s]: ", $help, $default === null ? '<none>' : $default); if ($secure && !$isWindows) { system('stty -echo'); } $value = trim(fgets(STDIN)); if ($secure && !$isWindows) { system('stty echo'); print "\n"; } // Check the input if ($value === '' && $default !== null) { $value = $default; } // Always return the value return $value; }