{"id":183187,"date":"2024-05-08T21:38:53","date_gmt":"2024-05-08T13:38:53","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/183187.html"},"modified":"2024-05-08T21:39:27","modified_gmt":"2024-05-08T13:39:27","slug":"php-%e7%bd%91%e7%ab%99%e6%b3%a8%e5%86%8c%e7%99%bb%e5%bd%95%e5%8a%9f%e8%83%bd%e7%9a%84%e5%8e%9f%e7%90%86%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/183187.html","title":{"rendered":"PHP \u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u7684\u539f\u7406\u662f\u4ec0\u4e48"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27073657\/64c12dc6-92a3-4eea-b9df-8712aa202bf3.webp\" alt=\"PHP \u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u7684\u539f\u7406\u662f\u4ec0\u4e48\" \/><\/p>\n<p><p>\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u662f\u4efb\u4f55\u7f51\u7ad9\u7684\u6838\u5fc3\u7ec4\u4ef6\u4e4b\u4e00\uff0c<strong>\u5b83\u57fa\u4e8e\u7528\u6237\u8ba4\u8bc1\u4e0e\u4f1a\u8bdd\u7ba1\u7406\u673a\u5236<\/strong>\u3002\u5728PHP\u7f51\u7ad9\u4e2d\uff0c\u6ce8\u518c\u529f\u80fd\u7684\u6838\u5fc3\u5728\u4e8e\u63a5\u6536\u7528\u6237\u63d0\u4ea4\u7684\u4fe1\u606f\u3001\u6821\u9a8c\u8fd9\u4e9b\u4fe1\u606f\u7684\u6709\u6548\u6027\u3001\u5e76\u5c06\u5176\u5b89\u5168\u5730\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u3002\u800c\u767b\u5f55\u529f\u80fd\u5219\u6d89\u53ca\u5230\u7528\u6237\u8eab\u4efd\u7684\u6821\u9a8c\u3001\u767b\u5f55\u72b6\u6001\u7684\u5efa\u7acb\u548c\u7ef4\u62a4\u3002\u66f4\u5177\u4f53\u5730\u8bf4\uff0c\u8fd9\u901a\u5e38\u5305\u62ec\u4e00\u7cfb\u5217\u6b65\u9aa4\uff1a\u7528\u6237\u8f93\u5165\u51ed\u636e\u3001\u7cfb\u7edf\u9a8c\u8bc1\u51ed\u636e\u6b63\u786e\u6027\u3001\u521b\u5efa\u4f1a\u8bdd\u548c\/\u6216\u4ee4\u724c\u4ee5\u4fdd\u6301\u7528\u6237\u72b6\u6001\uff0c\u5e76\u5728\u7528\u6237\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u4f20\u9012\u8fd9\u4e9b\u4fe1\u606f\u4ee5\u786e\u8ba4\u548c\u4fdd\u6301\u7528\u6237\u767b\u5f55\u72b6\u6001\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u7528\u6237\u6ce8\u518c\u6d41\u7a0b<\/h3>\n<\/p>\n<p><h4>\u6570\u636e\u6536\u96c6\u4e0e\u9a8c\u8bc1<\/h4>\n<\/p>\n<p><p>\u7528\u6237\u901a\u5e38\u4f1a\u5728\u6ce8\u518c\u754c\u9762\u8f93\u5165\u81ea\u5df1\u7684\u90ae\u7bb1\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\u8fd9\u4e9b\u4fe1\u606f\u9996\u5148\u4f1a\u5728\u5ba2\u6237\u7aef\uff08\u6bd4\u5982\u6d4f\u89c8\u5668\uff09\u4e2d\u8fdb\u884c\u521d\u6b65\u7684\u683c\u5f0f\u9a8c\u8bc1\uff0c\u5982\u68c0\u67e5\u90ae\u7bb1\u683c\u5f0f\u3001\u5bc6\u7801\u5f3a\u5ea6\u7b49\u3002\u901a\u8fc7\u5ba2\u6237\u7aef\u9a8c\u8bc1\u540e\uff0c\u6570\u636e\u4f1a\u88ab\u53d1\u9001\u5230\u670d\u52a1\u5668\u3002<\/p>\n<\/p>\n<p><h4>\u6570\u636e\u7684\u670d\u52a1\u5668\u7aef\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u670d\u52a1\u5668\u6536\u5230\u6570\u636e\u540e\uff0c\u4f1a\u518d\u6b21\u8fdb\u884c\u9a8c\u8bc1\uff0c\u5305\u62ec\u68c0\u6d4b\u7528\u6237\u540d\u662f\u5426\u552f\u4e00\u3001\u5bc6\u7801\u662f\u5426\u7b26\u5408\u5b89\u5168\u6807\u51c6\u7b49\u3002\u5982\u679c\u4fe1\u606f\u9a8c\u8bc1\u901a\u8fc7\uff0c\u670d\u52a1\u5668\u5219\u4f1a\u5c06\u7528\u6237\u6570\u636e\u5b58\u50a8\u5230\u6570\u636e\u5e93\u4e2d\u3002<strong>\u5728\u5b58\u50a8\u5bc6\u7801\u65f6\uff0c\u4f1a\u5148\u5bf9\u5bc6\u7801\u8fdb\u884c\u52a0\u5bc6\u5904\u7406<\/strong>\uff0c\u901a\u5e38\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570\uff0c\u8fd9\u662f\u51fa\u4e8e\u5b89\u5168\u8003\u8651\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u7528\u6237\u767b\u5f55\u6d41\u7a0b<\/h3>\n<\/p>\n<p><h4>\u51ed\u636e\u63d0\u4ea4\u4e0e\u9a8c\u8bc1<\/h4>\n<\/p>\n<p><p>\u767b\u5f55\u65f6\uff0c\u7528\u6237\u8f93\u5165\u5176\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u8fd9\u4e9b\u4fe1\u606f\u5c06\u88ab\u53d1\u9001\u5230\u670d\u52a1\u5668\u8fdb\u884c\u9a8c\u8bc1\u3002\u670d\u52a1\u5668\u4f1a\u5728\u6570\u636e\u5e93\u4e2d\u67e5\u627e\u5339\u914d\u7684\u7528\u6237\u540d\uff0c\u7136\u540e\u5c06\u63d0\u4ea4\u7684\u5bc6\u7801\u548c\u6570\u636e\u5e93\u4e2d\u5b58\u50a8\u7684\u52a0\u5bc6\u5bc6\u7801\u8fdb\u884c\u6bd4\u5bf9\u3002<\/p>\n<\/p>\n<p><h4>\u4f1a\u8bdd\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>\u4e00\u65e6\u9a8c\u8bc1\u6210\u529f\uff0c\u670d\u52a1\u5668\u4f1a\u5efa\u7acb\u4e00\u6761\u4f1a\u8bdd\u6216\u751f\u6210\u4e00\u4e2a\u4ee4\u724c\u3002<strong>\u4f1a\u8bdd\u662f\u5728\u670d\u52a1\u5668\u4e0a\u5b58\u50a8\u7528\u6237\u72b6\u6001\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u800c\u4ee4\u724c\uff08\u5982JWT\uff09\u5219\u662f\u5c06\u7528\u6237\u72b6\u6001\u5d4c\u5165\u5230\u7528\u6237\u7aef\u7684\u65b9\u6cd5\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4fdd\u6301\u7528\u6237\u767b\u5f55\u72b6\u6001<\/h3>\n<\/p>\n<p><h4>Cookie\u4e0eSession<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u4fdd\u6301\u7528\u6237\u7684\u767b\u5f55\u72b6\u6001\uff0c\u7f51\u7ad9\u53ef\u80fd\u4f1a\u4f7f\u7528Cookie\u548cSession\u3002\u670d\u52a1\u5668\u4f1a\u53d1\u9001\u4e00\u4e2aSession ID\u7ed9\u6d4f\u89c8\u5668\uff0c\u6d4f\u89c8\u5668\u4f1a\u5c06\u8fd9\u4e2aID\u5b58\u50a8\u5728Cookie\u4e2d\uff0c\u5e76\u5728\u968f\u540e\u7684\u8bf7\u6c42\u4e2d\u5c06\u5176\u56de\u4f20\u7ed9\u670d\u52a1\u5668\u3002<strong>\u670d\u52a1\u5668\u5229\u7528\u8fd9\u4e2aSession ID\u6765\u67e5\u627e\u5bf9\u5e94\u7684Session\u4fe1\u606f\uff0c\u4ece\u800c\u8bc6\u522b\u7528\u6237\u8eab\u4efd<\/strong>\u3002<\/p>\n<\/p>\n<p><h4>Token-Based Authentication<\/h4>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4ee4\u724c\u57fa\u8ba4\u8bc1\uff0c\u6bd4\u5982\u4f7f\u7528JSON Web Tokens (JWT)\u3002\u8fd9\u4e9b\u4ee4\u724c\u88ab\u52a0\u5bc6\u5e76\u5305\u542b\u7528\u6237\u8eab\u4efd\u4fe1\u606f\uff0c\u5f53\u7528\u6237\u518d\u6b21\u8bbf\u95ee\u7f51\u7ad9\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u53d1\u9001\u8fd9\u4e2aJWT\uff0c\u670d\u52a1\u5668\u901a\u8fc7\u89e3\u5bc6\u4ee4\u724c\u6765\u9a8c\u8bc1\u7528\u6237\u8eab\u4efd\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5b89\u5168\u6027\u8003\u8651<\/h3>\n<\/p>\n<p><h4>\u5bc6\u7801\u7684\u5b89\u5168\u5b58\u50a8<\/h4>\n<\/p>\n<p><p>\u5bc6\u7801\u7edd\u5bf9\u4e0d\u80fd\u4ee5\u660e\u6587\u5f62\u5f0f\u5b58\u50a8\uff0c\u901a\u5e38\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570\u8fdb\u884c\u52a0\u5bc6\u3002\u4e3a\u4e86\u8fdb\u4e00\u6b65\u63d0\u9ad8\u5b89\u5168\u6027\uff0c\u53ef\u4ee5\u6dfb\u52a0\u201c\u76d0\u503c\u201d\u6765\u589e\u5f3a\u52a0\u5bc6\u5f3a\u5ea6\u3002<\/p>\n<\/p>\n<p><h4>\u6570\u636e\u4f20\u8f93\u5b89\u5168<\/h4>\n<\/p>\n<p><p>\u5728\u7528\u6237\u63d0\u4ea4\u4fe1\u606f\u548c\u670d\u52a1\u5668\u56de\u4f20Session ID\u6216JWT\u65f6\uff0c\u5e94\u4f7f\u7528HTTPS\u6765\u4fdd\u62a4\u6570\u636e\u4e0d\u88ab\u622a\u83b7\u3002HTTPS\u5229\u7528SSL\/TLS\u52a0\u5bc6\uff0c\u786e\u4fdd\u8fd9\u4e9b\u4f20\u8f93\u7684\u6570\u636e\u7684\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<p><h4>XSS\u4e0eCSRF\u9632\u5fa1<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u9632\u6b62\u8de8\u7ad9\u811a\u672c\u653b\u51fb\uff08XSS\uff09\u548c\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\uff08CSRF\uff09\uff0c\u9700\u8981\u5bf9\u8f93\u5165\u8fdb\u884c\u9a8c\u8bc1\u548c\u6e05\u7406\uff0c\u5bf9\u8f93\u51fa\u8fdb\u884c\u9002\u5f53\u7684\u7f16\u7801\uff0c\u4ee5\u53ca\u5229\u7528\u4e00\u4e9bHTTP\u5934\u90e8\u8bbe\u7f6e\u5982<code>SameSite<\/code>\u5c5e\u6027\u6765\u589e\u52a0\u5b89\u5168\u9632\u62a4\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u95ee\u9898\uff1a<\/strong>PHP\u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u662f\u5982\u4f55\u5b9e\u73b0\u7684\uff1f<br \/><strong>\u7b54\u6848\uff1a<\/strong>        <\/p>\n<ul>\n<li>\n<p><strong>\u95ee\u9898\uff1a<\/strong>PHP\u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u7684\u539f\u7406\u662f\u4ec0\u4e48\uff1f<br \/><strong>\u7b54\u6848\uff1a<\/strong>PHP\u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u7684\u539f\u7406\u4e3b\u8981\u662f\u57fa\u4e8e\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u4ea4\u4e92\u3002\u5f53\u7528\u6237\u5728\u7f51\u7ad9\u4e0a\u6ce8\u518c\u65f6\uff0c\u6ce8\u518c\u4fe1\u606f\u5c06\u88ab\u5b58\u50a8\u5728\u670d\u52a1\u5668\u7684\u6570\u636e\u5e93\u4e2d\u3002\u5f53\u7528\u6237\u5c1d\u8bd5\u767b\u5f55\u65f6\uff0c\u670d\u52a1\u5668\u5c06\u9a8c\u8bc1\u63d0\u4f9b\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u4e0e\u6570\u636e\u5e93\u4e2d\u5b58\u50a8\u7684\u4fe1\u606f\u8fdb\u884c\u5339\u914d\u3002\u5982\u679c\u5339\u914d\u6210\u529f\uff0c\u5219\u5c06\u7528\u6237\u8df3\u8f6c\u5230\u767b\u5f55\u540e\u7684\u9875\u9762\uff1b\u5982\u679c\u5339\u914d\u5931\u8d25\uff0c\u5219\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4f9d\u8d56\u4e8ePHP\u7f16\u7a0b\u8bed\u8a00\u548c\u6570\u636e\u5e93\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5b58\u50a8\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u4ec0\u4e48\u662fPHP\u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u7684\u5e38\u7528\u6280\u672f\uff1f<br \/>\n<strong>\u7b54\u6848\uff1a<\/strong>PHP\u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u5e38\u7528\u7684\u6280\u672f\u5305\u62ec\u4f7f\u7528HTML\u8868\u5355\u548cPHP\u811a\u672c\u6765\u6536\u96c6\u548c\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u3002\u5728\u5b58\u50a8\u7528\u6237\u4fe1\u606f\u65b9\u9762\uff0c\u5e38\u7528\u7684\u6280\u672f\u5305\u62ec\u4f7f\u7528MySQL\u6570\u636e\u5e93\u6765\u50a8\u5b58\u7528\u6237\u6ce8\u518c\u4fe1\u606f\u3002\u6b64\u5916\uff0c\u4e3a\u4e86\u63d0\u9ad8\u5b89\u5168\u6027\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u52a0\u5bc6\u7b97\u6cd5\u6765\u4fdd\u62a4\u5bc6\u7801\u3002\u9875\u9762\u91cd\u5b9a\u5411\u548c\u4f1a\u8bdd\u7ba1\u7406\u4e5f\u662f\u7528\u4e8e\u5904\u7406\u7528\u6237\u767b\u5f55\u72b6\u6001\u548c\u8df3\u8f6c\u7684\u5e38\u7528\u6280\u672f\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u95ee\u9898\uff1a<\/strong>PHP\u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u7684\u5f00\u53d1\u9700\u8981\u638c\u63e1\u54ea\u4e9b\u77e5\u8bc6\uff1f<br \/>\n<strong>\u7b54\u6848\uff1a<\/strong>\u8981\u5f00\u53d1PHP\u7f51\u7ad9\u6ce8\u518c\u767b\u5f55\u529f\u80fd\uff0c\u4f60\u9700\u8981\u638c\u63e1HTML\u548cCSS\u7b49\u524d\u7aef\u6280\u672f\uff0c\u4e86\u89e3\u57fa\u672c\u7684PHP\u7f16\u7a0b\u8bed\u8a00\u77e5\u8bc6\uff0c\u5e76\u719f\u6089MySQL\u6570\u636e\u5e93\u7684\u4f7f\u7528\u3002\u6b64\u5916\uff0c\u4e86\u89e3Web\u5b89\u5168\u548c\u7528\u6237\u9a8c\u8bc1\u7684\u57fa\u672c\u539f\u5219\u4e5f\u662f\u5f88\u91cd\u8981\u7684\u3002\u719f\u6089\u4f1a\u8bdd\u7ba1\u7406\u548c\u52a0\u5bc6\u7b97\u6cd5\u7b49\u76f8\u5173\u6280\u672f\uff0c\u4e5f\u6709\u52a9\u4e8e\u63d0\u9ad8\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u7684\u5b89\u5168\u6027\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u6ce8\u518c\u767b\u5f55\u529f\u80fd\u662f\u4efb\u4f55\u7f51\u7ad9\u7684\u6838\u5fc3\u7ec4\u4ef6\u4e4b\u4e00\uff0c\u5b83\u57fa\u4e8e\u7528\u6237\u8ba4\u8bc1\u4e0e\u4f1a\u8bdd\u7ba1\u7406\u673a\u5236\u3002\u5728PHP\u7f51\u7ad9\u4e2d\uff0c\u6ce8\u518c\u529f\u80fd\u7684\u6838\u5fc3\u5728\u4e8e\u63a5\u6536\u7528\u6237 [&hellip;]","protected":false},"author":3,"featured_media":183197,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/183187"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=183187"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/183187\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/183197"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=183187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=183187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=183187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}