{"id":225,"date":"2021-08-03T13:42:39","date_gmt":"2021-08-03T05:42:39","guid":{"rendered":"http:\/\/blog.nonot.cn\/?p=225"},"modified":"2024-07-08T12:53:11","modified_gmt":"2024-07-08T04:53:11","slug":"php%e5%88%a4%e6%96%ad%e5%9b%be%e7%89%87%e6%98%af%e5%90%a6%e5%ad%98%e5%9c%a8%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2021\/08\/03\/php%e5%88%a4%e6%96%ad%e5%9b%be%e7%89%87%e6%98%af%e5%90%a6%e5%ad%98%e5%9c%a8%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e6%b3%95\/","title":{"rendered":"php\u5224\u65ad\u56fe\u7247\u662f\u5426\u5b58\u5728\u7684\u51e0\u79cd\u65b9\u6cd5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u6211\u4eec\u65e5\u5e38\u7684\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u7528\u5230\u5224\u65ad\u56fe\u7247\u662f\u5426\u5b58\u5728\uff0c\u5b58\u5728\u5219\u663e\u793a\uff0c\u4e0d\u5b58\u5728\u5219\u663e\u793a\u9ed8\u8ba4\u56fe\u7247\uff0c\u90a3\u4e48\u6211\u4eec\u7528\u5230\u7684\u5224\u65ad\u6709\u54ea\u4e9b\u5462\uff1f\u4eca\u5929\u6211\u4eec\u5c31\u6765\u770b\u4e0b\u51e0\u4e2a\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1\u3001getimagesize()\u51fd\u6570<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>getimagesize<\/code>&nbsp;\u51fd\u6570\u5e76\u4e0d\u5c5e\u4e8e GD \u6269\u5c55\u7684\u90e8\u5206\uff0c\u6807\u51c6\u5b89\u88c5\u7684 PHP \u90fd\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\u3002\u53ef\u4ee5\u5148\u770b\u770b\u8fd9\u4e2a\u51fd\u6570\u7684\u6587\u6863\u63cf\u8ff0\uff1a<a href=\"http:\/\/php.net\/manual\/zh\/function.getimagesize.php\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/php.net\/manual\/zh\/function.getimagesize.php<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6307\u5b9a\u7684\u6587\u4ef6\u5982\u679c\u4e0d\u662f\u6709\u6548\u7684\u56fe\u50cf\uff0c\u4f1a\u8fd4\u56de false\uff0c\u8fd4\u56de\u6570\u636e\u4e2d\u4e5f\u6709\u8868\u793a\u6587\u6863\u7c7b\u578b\u7684\u5b57\u6bb5\u3002\u5982\u679c\u4e0d\u7528\u6765\u83b7\u53d6\u6587\u4ef6\u7684\u5927\u5c0f\u800c\u662f\u4f7f\u7528\u5b83\u6765\u5224\u65ad\u4e0a\u4f20\u6587\u4ef6\u662f\u5426\u662f\u56fe\u7247\u6587\u4ef6\uff0c\u770b\u8d77\u6765\u4f3c\u4e4e\u662f\u4e2a\u5f88\u4e0d\u9519\u7684\u65b9\u6848\uff0c\u5f53\u7136\u8fd9\u9700\u8981\u5c4f\u853d\u6389\u53ef\u80fd\u4ea7\u751f\u7684\u8b66\u544a\uff0c\u6bd4\u5982\u4ee3\u7801\u8fd9\u6837\u5199\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$filesize = @getimagesize('\/path\/to\/image.png');\nif ($filesize) {\n    do_upload();\n}\n\n# \u53e6\u5916\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f60\u4e0d\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\u5199\uff1a\n# if ($filesize[2] == 0)\n# \u56e0\u4e3a $filesize[2] \u53ef\u80fd\u662f 1 \u5230 16 \u4e4b\u95f4\u7684\u6574\u6570\uff0c\u4f46\u5374\u7edd\u5bf9\u4e0d\u5bf9\u662f0\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u5982\u679c\u4f60\u4ec5\u4ec5\u662f\u505a\u4e86\u8fd9\u6837\u7684\u9a8c\u8bc1\uff0c\u90a3\u4e48\u5f88\u4e0d\u5e78\uff0c\u4f60\u6210\u529f\u7684\u5728\u4ee3\u7801\u91cc\u79cd\u4e0b\u4e86\u4e00\u4e2a webshell \u7684\u9690\u60a3\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5206\u6790\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u5148\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a\u51fd\u6570\u7684\u539f\u578b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static void php_getimagesize_from_stream(php_stream *stream, zval **info, INTERNAL_FUNCTION_PARAMETERS)\n{\n    ...\n    itype = php_getimagetype(stream, NULL TSRMLS_CC);\n    switch( itype) {\n        ...\n    }\n    ...\n}\n\nstatic void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) {\n    ...\n    php_getimagesize_from_stream(stream, info, INTERNAL_FUNCTION_PARAM_PASSTHRU);\n    php_stream_close(stream);\n}\n\nPHP_FUNCTION(getimagesize)\n{\n    php_getimagesize_from_any(INTERNAL_FUNCTION_PARAM_PASSTHRU, FROM_PATH);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9650\u4e8e\u7bc7\u5e45\u4e0a\u9762\u9690\u85cf\u4e86\u4e00\u4e9b\u7ec6\u8282\uff0c\u73b0\u5728\u4ece\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\u6211\u4eec\u77e5\u9053\u4e24\u4ef6\u4e8b\u60c5\u5c31\u591f\u4e86\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u6700\u7ec8\u5904\u7406\u7684\u51fd\u6570\u662f&nbsp;<code>php_getimagesize_from_stream<\/code><\/li><li>\u8d1f\u8d23\u5224\u65ad\u6587\u4ef6\u7c7b\u578b\u7684\u51fd\u6570\u662f&nbsp;<code>php_getimagetype<\/code><\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\u770b\u4e00\u4e0b&nbsp;<code>php_getimagetype<\/code>&nbsp;\u7684\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)\n{\n    ...\n    if (!memcmp(filetype, php_sig_gif, 3)) {\n        return IMAGE_FILETYPE_GIF;\n    } else if (!memcmp(filetype, php_sig_jpg, 3)) {\n        return IMAGE_FILETYPE_JPEG;\n    } else if (!memcmp(filetype, php_sig_png, 3)) {\n        ...\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53bb\u6389\u4e86\u4e00\u4e9b\u7ec6\u8282\uff0c<code>php_sig_gif<\/code>&nbsp;<code>php_sig_png<\/code>&nbsp;\u7b49\u662f\u5728\u6587\u4ef6\u5934\u90e8\u5b9a\u4e49\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'};\n...\nPHPAPI const char php_sig_png[8] = {(char) 0x89, (char) 0x50, (char) 0x4e, (char) 0x47,\n                                    (char) 0x0d, (char) 0x0a, (char) 0x1a, (char) 0x0a};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u770b\u51fa\u6765 image type \u662f\u6839\u636e\u6587\u4ef6\u6d41\u7684\u524d\u51e0\u4e2a\u5b57\u8282\uff08\u6587\u4ef6\u5934\uff09\u6765\u5224\u65ad\u7684\u3002\u90a3\u4e48\u65e2\u7136\u5982\u6b64\uff0c\u6211\u4eec\u53ef\u4e0d\u53ef\u4ee5\u6784\u9020\u4e00\u4e2a\u7279\u6b8a\u7684 PHP \u6587\u4ef6\u6765\u7ed5\u8fc7\u8fd9\u4e2a\u5224\u65ad\u5462\uff1f\u4e0d\u5982\u6765\u5c1d\u8bd5\u4e00\u4e0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u627e\u4e00\u4e2a\u5341\u516d\u8fdb\u5236\u7f16\u8f91\u5668\u6765\u5199\u4e00\u4e2a\u7684 PHP \u8bed\u53e5\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\u00a0phpinfo();\u00a0?><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u51e0\u4e2a\u5b57\u7b26\u7684\u5341\u516d\u8fdb\u5236\u7f16\u7801\uff08UTF-8\uff09\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>3C3F\u00a07068\u00a07020\u00a07068\u00a07069\u00a06E66\u00a06F28\u00a0293B\u00a0203F\u00a03E<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u6784\u9020\u4e00\u4e0b\uff0c\u628a PNG \u6587\u4ef6\u7684\u5934\u5b57\u8282\u52a0\u5728\u524d\u9762\u53d8\u6210\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>8950\u00a04E47\u00a00D0A\u00a01A0A\u00a03C3F\u00a07068\u00a07020\u00a07068\u00a07069\u00a06E66\u00a06F28\u00a0293B\u00a0203F\u00a03E<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u4fdd\u5b58\u6210&nbsp;<code>.php<\/code>&nbsp;\u540e\u7f00\u7684\u6587\u4ef6\uff08\u6ce8\u610f\u4e0a\u9762\u662f\u6587\u4ef6\u7684\u5341\u516d\u8fdb\u5236\u503c\uff09\uff0c\u6bd4\u5982 test.php\u3002\u6267\u884c\u4e00\u4e0b&nbsp;<code>php test.php<\/code>&nbsp;\u4f60\u4f1a\u53d1\u73b0\u5b8c\u5168\u53ef\u4ee5\u6267\u884c\u6210\u529f\u3002\u90a3\u4e48\u80fd\u7528&nbsp;<code>getimagesize<\/code>&nbsp;\u8bfb\u53d6\u5b83\u7684\u6587\u4ef6\u4fe1\u606f\u5417\uff1f\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5199\u5165\u4ee3\u7801\u8bd5\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nprint_r(getimagesize('test.php'));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Array\n(\n    [0] => 1885957734\n    [1] => 1864902971\n    [2] => 3\n    [3] => width=\"1885957734\" height=\"1864902971\"\n    [bits] => 32\n    [mime] => image\/png\n)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6210\u529f\u8bfb\u53d6\u51fa\u6765\uff0c\u5e76\u4e14\u6587\u4ef6\u4e5f\u88ab\u6b63\u5e38\u8bc6\u522b\u4e3a PNG \u6587\u4ef6\uff0c\u867d\u7136\u5bbd\u548c\u9ad8\u7684\u503c\u90fd\u5927\u7684\u6709\u70b9\u79bb\u8c31\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\u4f60\u5e94\u8be5\u660e\u767d\u4e3a\u4ec0\u4e48\u4e0a\u6587\u8bf4\u8fd9\u91cc\u7559\u4e0b\u4e86\u4e00\u4e2a webshell \u7684\u9690\u60a3\u7684\u5427\u3002\u5982\u679c\u8fd9\u91cc\u53ea\u6709\u8fd9\u6837\u7684\u4e0a\u4f20\u5224\u65ad\uff0c\u800c\u4e14\u4e0a\u4f20\u4e4b\u540e\u7684\u6587\u4ef6\u662f\u53ef\u4ee5\u8bbf\u95ee\u7684\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u5165\u53e3\u6ce8\u5165\u4efb\u610f\u4ee3\u7801\u6267\u884c\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u90a3\u4e48\u4e3a\u4ec0\u4e48\u4e0a\u9762\u7684\u6587\u4ef6\u53ef\u4ee5 PHP \u662f\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\u7684\u5462\uff1f\u7528&nbsp;<a href=\"http:\/\/php.net\/manual\/zh\/function.token-get-all.php\" target=\"_blank\" rel=\"noreferrer noopener\">token_get_all<\/a>&nbsp;\u51fd\u6570\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nprint_r(token_get_all(file_get_contents('test.php')));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u663e\u793a\u6b63\u5e38\u7684\u8bdd\u4f60\u80fd\u770b\u5230\u8f93\u51fa\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u89e3\u6790\u5668\u4ee3\u53f7\u662f 312\uff0c\u901a\u8fc7&nbsp;<a href=\"http:\/\/php.net\/manual\/zh\/function.token-name.php\" target=\"_blank\" rel=\"noreferrer noopener\">token_name<\/a>&nbsp;\u83b7\u53d6\u5230\u7684\u540d\u79f0\u4f1a\u662f T_INLINE_HTML\uff0c\u4e5f\u5c31\u662f\u8bf4\u6587\u4ef6\u5934\u90e8\u7684\u4fe1\u606f\u88ab\u5f53\u6210\u6b63\u5e38\u7684\u5185\u5d4c\u7684 HTML \u4ee3\u7801\u88ab\u5ffd\u7565\u6389\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u4f1a\u6709\u4e00\u4e2a\u5927\u7684\u79bb\u8c31\u7684\u5bbd\u548c\u9ad8\uff0c\u770b\u4e00\u4e0b&nbsp;<code>php_handle_png<\/code>&nbsp;\u51fd\u6570\u7684\u5b9e\u73b0\u5c31\u80fd\u77e5\u9053\uff0c\u8fd9\u4e9b\u4fe1\u606f\u4e5f\u662f\u901a\u8fc7\u8bfb\u53d6\u7279\u5b9a\u7684\u6587\u4ef6\u5934\u7684\u4f4d\u6765\u83b7\u53d6\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\uff0c\u5bf9\u4e8e\u6b63\u5e38\u7684\u56fe\u7247\u6587\u4ef6\uff0cgetimagesize \u5b8c\u5168\u53ef\u4ee5\u80dc\u4efb\uff0c\u4f46\u662f\u5bf9\u4e8e\u4e00\u4e9b\u6709\u5fc3\u6784\u9020\u7684\u6587\u4ef6\u7ed3\u6784\u5374\u4e0d\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5904\u7406\u7528\u6237\u4e0a\u4f20\u7684\u6587\u4ef6\u65f6\uff0c\u5148\u7b80\u5355\u7c97\u66b4\u7684\u5224\u65ad\u6587\u4ef6\u6269\u5c55\u540d\u5e76\u5bf9\u6587\u4ef6\u540d\u505a\u4e00\u4e0b\u5904\u7406\uff0c\u4fdd\u8bc1\u5728\u670d\u52a1\u5668\u4e0a\u4e0d\u662f php \u6587\u4ef6\u90fd\u4e0d\u80fd\u76f4\u63a5\u6267\u884c\u4e5f\u662f\u4e00\u79cd\u6709\u6548\u7684\u65b9\u5f0f\u3002\u7136\u540e\u53ef\u4ee5\u4f7f\u7528 getimagesize \u505a\u4e00\u4e9b\u8f85\u52a9\u5904\u7406\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2\u3001file_exists()\u51fd\u6570<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">file_exists() \u51fd\u6570\u68c0\u67e5\u6587\u4ef6\u6216\u76ee\u5f55\u662f\u5426\u5b58\u5728\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6307\u5b9a\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u5b58\u5728\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">eg:&nbsp;file_exists(path);\u5176\u4e2d\u7684\u53c2\u6570path\u5fc5\u987b\u662f\u8def\u5f84\uff0c\u4e0d\u80fd\u662furl\u4e0d\u7136\u4f1a\u4e00\u76f4\u8fd4\u56defalse;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u6587\u4ef6\u7684\u4efb\u4f55\u4e0a\u7ea7\u76ee\u5f55\uff0c\u53ea\u6709\u5199\u6743\u9650\u65f6\u62a5\u6587\u4ef6\u4e0d\u5b58\u5728;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u6587\u4ef6\u7684\u4efb\u4f55\u4e0a\u7ea7\u76ee\u5f55\uff0c\u53ea\u6709\u8bfb\u6743\u9650\u65f6\u4e5f\u62a5\u6587\u4ef6\u4e0d\u5b58\u5728;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u800c\u5f53\u6240\u6709\u4e0a\u7ea7\u76ee\u5f55\u90fd\u6709\u6267\u884c\u6743\u9650\u7684\u65f6\u5019\uff0c\u62a5\u6587\u4ef6\u662f\u5b58\u5728\u7684\uff0c\u4e00\u5207\u90fd\u6b63\u5e38\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf4\u660efile_exists\uff08\uff09\u5728\u5224\u65ad\u6587\u4ef6\u662f\u5426\u5b58\u5728\u7684\u65f6\u5019\u662f\u9012\u5f52\u5224\u65ad\u6bcf\u4e2a\u76ee\u5f55\u662f\u4e0d\u662f\u6709\u6267\u884c\u6743\u9650\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3\u3001file_get_contents()\u51fd\u6570<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">file_get_contents \u2014&nbsp;\u5c06\u6574\u4e2a\u6587\u4ef6\u8bfb\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u5931\u8d25\uff0c<strong>file_get_contents()<\/strong>&nbsp;\u5c06\u8fd4\u56de&nbsp;<strong><code>FALSE<\/code><\/strong>\u3002&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u679c\u8981\u6253\u5f00\u6709\u7279\u6b8a\u5b57\u7b26\u7684 URL \uff08\u6bd4\u5982\u8bf4\u6709\u7a7a\u683c\uff09\uff0c\u5c31\u9700\u8981\u4f7f\u7528&nbsp;<a>urlencode()<\/a>&nbsp;\u8fdb\u884c URL \u7f16\u7801\u3002&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u6b64\u51fd\u6570\u5982\u679c\u8bf7\u6c42\u6bd4\u8f83\u591a\uff0c\u6587\u4ef6\u6bd4\u8f83\u5927\uff0c\u90a3\u4e48\u53ef\u80fd\u4f1a\u8d85\u65f6\u672a\u54cd\u5e94\uff0c\u5bfc\u81f4\u670d\u52a1\u5668\u6302\u6389<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u8bbe\u7f6efile_get_contents\u51fd\u6570\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u53ef\u4ee5\u7528resource $context\u7684timeout\u53c2\u6570\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$opts = array(\n \u3000\u3000'http'=>array(\n \u3000\u3000\u3000\u3000'method'=>\"GET\",\n\u3000\u3000\u3000\u3000 'timeout'=>10,\n\u3000\u3000 )\n );\n $context = stream_context_create($opts);\n $html =file_get_contents('http:\/\/www.example.com', false, $context);\necho $html;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4\u3001curl\u65b9\u6cd5<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u73b0\u7684\u529f\u80fd\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u5b9e\u73b0\u8fdc\u7a0b\u83b7\u53d6\u548c\u91c7\u96c6\u5185\u5bb9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u5b9e\u73b0PHP \u7f51\u9875\u7248\u7684FTP\u4e0a\u4f20\u4e0b\u8f7d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u5b9e\u73b0\u6a21\u62df\u767b\u9646\uff1a\u53bb\u4e00\u4e2a\u90ae\u4ef6\u7cfb\u7edf\uff0ccurl\u53ef\u4ee5\u6a21\u62dfcookies<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5b9e\u73b0\u63a5\u53e3\u5bf9\u63a5\uff08API\uff09\uff0c\u6570\u636e\u4f20\u8f93\u7b49\uff1a\u901a\u8fc7\u4e00\u4e2a\u5e73\u53f0\u53d1\u9001\u77ed\u4fe1\u554a\uff0c\u6293\u53d6\u548c\u4f20\u9012\u6240\u4f20\u8f93\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5\u3001\u5b9e\u73b0\u6a21\u62dfCookie\u7b49\uff1a\u767b\u9646\u7684\u72b6\u6001\u4e0b\u624d\u53ef\u4ee5\u64cd\u4f5c\u4e00\u4e9b\u5c5e\u6027\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5982\u4f55\u4f7f\u7528CURL\u529f\u80fd<\/strong>\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9ed8\u8ba4\u60c5\u51b5\u52a0PHP\u662f\u4e0d\u652f\u6301CURL\u7684\uff0c\u9700\u8981\u5728php.ini\u4e2d\u5f00\u542f\u8be5\u529f\u80fd<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">;extension=php_curl.dll\u524d\u9762\u7684\u5206\u53f7\u53bb\u6389<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1&nbsp; \u6574\u4e2a\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u7b2c\u4e00\u6b65\u662f\u7528cur_init()\u51fd\u6570\u8fdb\u884c\u521d\u59cb\u5316<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u7528curl_setopt\uff08\uff09\u51fd\u6570\u8fdb\u884c\u8bbe\u7f6e\u9009\u9879\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3.\u8bbe\u7f6e\u540e\uff0c\u8fdb\u884c\u6267\u884c\u4e8b\u52a1 curl_exec($curl);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4 \u6700\u540e\u5173\u95edcurl_close();<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u517c\u5bb9get\u548cpost\u65b9\u6cd5\u7684curl\uff1b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function curl($url, $type = 'get', $post_data = null, $second = 30)\n{\n    $ch = curl_init();\n    \/\/\u8bbe\u7f6e\u8d85\u65f6\n    curl_setopt($ch, CURLOPT_TIMEOUT, $second);\n    curl_setopt($ch, CURLOPT_URL, $url);\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); \/\/\n    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); \/\/\n    \/\/\u8bbe\u7f6eheader\n    curl_setopt($ch, CURLOPT_HEADER, false);\n    \/\/\u8981\u6c42\u7ed3\u679c\u4e3a\u5b57\u7b26\u4e32\u4e14\u8f93\u51fa\u5230\u5c4f\u5e55\u4e0a\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n    if ('post' == $type) {\n        curl_setopt($ch, CURLOPT_POST, 1); \/\/\u5f00\u542fPOST\n        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); \/\/POST\u6570\u636e\n    }\n    $output = curl_exec($ch);\n    curl_close($ch);\n    return $output; \/\/\u8fd4\u56de\u6216\u8005\u663e\u793a\u7ed3\u679c\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6211\u4eec\u65e5\u5e38\u7684\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u7528\u5230\u5224\u65ad\u56fe\u7247\u662f\u5426\u5b58\u5728\uff0c\u5b58\u5728\u5219\u663e\u793a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=225"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":1211,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/225\/revisions\/1211"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}