{"id":1438,"date":"2010-12-27T15:44:00","date_gmt":"2010-12-27T07:44:00","guid":{"rendered":""},"modified":"2013-11-25T18:26:38","modified_gmt":"2013-11-25T10:26:38","slug":"php%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1438.html","title":{"rendered":"PHP\u6700\u4f73\u5b9e\u8df5"},"content":{"rendered":"<p>\u672c\u6587\u7ed9\u51fa\u4e86PHP\u7a0b\u5e8f\u8bbe\u8ba1\u5e38\u89c1\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6cd5\uff0c\u540c\u65f6\u7b80\u5355\u63cf\u8ff0\u4e86PHP\u5e94\u7528\u7a0b\u5e8f\u7684\u67b6\u6784\u3002<\/p>\n<p>1. php.ini\u8bbe\u7f6e<\/p>\n<p>php.ini\u63a7\u5236\u4e86\u89e3\u91ca\u5668\u7684\u884c\u4e3a\uff0c\u4e0b\u9762\u7684\u4e00\u4e9b\u8bbe\u7f6e\u4fdd\u8bc1\u4e86\u4f60\u7684\u7a0b\u5e8f\u6709\u6700\u5927\u7684\u53ef\u79fb\u690d\u6027\u3002<\/p>\n<p>i. short_open_tag<\/p>\n<p>\u8bbe\u4e3a0\uff0c\u5373\u6c38\u8fdc\u4f7f\u7528PHP\u7684\u957f\u6807\u7b7e\u5f62\u5f0f\uff1a&lt;?php echo &#8220;hello world&#8221;; ?&gt;\uff0c\u4e0d\u7528\u77ed\u6807\u7b7e\u5f62\u5f0f&lt;?= &#8220;hello world&#8221; ?&gt;\u3002<\/p>\n<p>ii. asp_tags<\/p>\n<p>\u8bbe\u4e3a0\uff0c\u4e0d\u4f7f\u7528ASP\u6807\u7b7e&lt;% echo &#8220;hello world&#8221;; %&gt;\u3002<\/p>\n<p>iii. magic_quotes_gpc<\/p>\n<p>\u5efa\u8bae\u5728\u811a\u672c\u4e2d\u5305\u542b\u4e00\u4e2a\u5168\u5c40\u6587\u4ef6\uff0c\u8d1f\u8d23\u5728\u8bfb\u53d6$_GET\u3001$_POST\u3001$_COOKIE\u53d8\u91cf\u4e4b\u524d\uff0c\u9996\u5148\u68c0\u67e5\u8fd9\u4e2a\u8bbe\u7f6e\u662f\u5426\u6253\u5f00\uff0c\u5982\u679c\u6253\u5f00\u4e86\uff0c\u8fd9\u5bf9\u8fd9\u4e9b\u53d8\u91cf\u5e94\u7528stripslashes\u51fd\u6570\u3002\uff08\u6ce8\uff1a\u8be5\u8bbe\u7f6e\u5df2\u7ecf\u5728PHP 5.3\u4e2d\u88ab\u5e9f\u9664\u3002\uff09<\/p>\n<p>iv. register_globals<\/p>\n<p>\u4e0d\u8981\u4f9d\u8d56\u8fd9\u4e2a\u8bbe\u7f6e\uff0c\u6c38\u8fdc\u901a\u8fc7\u5168\u5c40\u53d8\u91cf$_GET\u3001$_POST\u3001$_COOKIE\u53bb\u8bfb\u53d6GET\u3001POST\u548cCOOKIE\u7684\u503c\u3002\u4e3a\u4e86\u65b9\u4fbf\u8d77\u89c1\uff0c\u5efa\u8bae\u58f0\u660e$PHP_SELF = $_SERVER[&#8216;PHP_SELF&#8217;]\u3002<\/p>\n<p>v. file_uploads<\/p>\n<p>\u4e0a\u4f20\u6587\u4ef6\u7684\u6700\u5927\u5927\u5c0f\uff0c\u7531\u4e0b\u9762\u7684\u8bbe\u7f6e\u51b3\u5b9a\uff1a<\/p>\n<p>* file_uploads\u5fc5\u987b\u8bbe\u4e3a1\uff08\u9ed8\u8ba4\u503c\uff09\uff0c\u8868\u793a\u5141\u8bb8\u4e0a\u4f20\u3002<\/p>\n<p>* memory_limit\u5fc5\u987b\u7565\u5927\u4e8epost_max_size\u548cupload_max_filesize\u3002<\/p>\n<p>* post_max_size\u548cupload_max_filesize\u8981\u8db3\u591f\u5927\uff0c\u80fd\u6ee1\u8db3\u4e0a\u4f20\u7684\u9700\u8981\u3002<\/p>\n<p>2. \u914d\u7f6e\u6587\u4ef6\uff08configuration file\uff09<\/p>\n<p>\u4f60\u5e94\u8be5\u628a\u4e0e\u5e94\u7528\u7a0b\u5e8f\u76f8\u5173\u7684\u6240\u6709\u914d\u7f6e\uff0c\u5199\u5728\u4e00\u4e2a\u6587\u4ef6\u91cc\u3002\u8fd9\u6837\u4f60\u5c31\u80fd\u5f88\u65b9\u4fbf\u5730\u9002\u5e94\u5f00\u53d1\u73af\u5883\u7684\u53d8\u5316\u3002\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u5305\u542b\u4ee5\u4e0b\u4fe1\u606f\uff1a\u6570\u636e\u5e93\u53c2\u6570\u3001email\u5730\u5740\u3001\u5404\u7c7b\u9009\u9879\u3001debug\u548clogging\u8f93\u51fa\u5f00\u5173\u3001\u5e94\u7528\u7a0b\u5e8f\u5e38\u6570\u3002<\/p>\n<p>3. \u540d\u79f0\u7a7a\u95f4\uff08namespace\uff09<\/p>\n<p>\u9009\u62e9\u7c7b\u548c\u51fd\u6570\u540d\u7684\u65f6\u5019\uff0c\u5fc5\u987b\u5f88\u5c0f\u5fc3\uff0c\u907f\u514d\u51fa\u73b0\u91cd\u540d\u3002\u5c3d\u53ef\u80fd\u4e0d\u8981\u5728\u7c7b\u4ee5\u5916\uff0c\u653e\u7f6e\u5168\u5c40\u6027\u51fd\u6570\uff0c\u7c7b\u5bf9\u5185\u90e8\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u76f8\u5f53\u4e8e\u6709\u4e00\u5c42\u540d\u79f0\u7a7a\u95f4\u4fdd\u62a4\u3002\u5982\u679c\u4f60\u786e\u5b9e\u6709\u5fc5\u8981\u58f0\u660e\u5168\u5c40\u6027\u51fd\u6570\uff0c\u90a3\u4e48\u4f7f\u7528\u4e00\u4e2a\u524d\u7f00\uff0c\u6bd4\u5982dao_factory()\u3001 db_getConnection()\u3001text_parseDate()\u7b49\u7b49\u3002<\/p>\n<p>4. \u6570\u636e\u5e93\u62bd\u8c61\u5c42<\/p>\n<p>PHP\u4e0d\u63d0\u4f9b\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u901a\u7528\u51fd\u6570\uff0c\u6bcf\u79cd\u6570\u636e\u5e93\u90fd\u6709\u4e00\u5957\u81ea\u5df1\u7684\u51fd\u6570\u3002\u4f60\u4e0d\u5e94\u8be5\u76f4\u63a5\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u5426\u5219\u4e00\u65e6\u6539\u7528\u5176\u4ed6\u6570\u636e\u5e93\uff08\u6bd4\u5982\u4eceMySQL \u8f6c\u4e3aOracle\uff09\uff0c\u4f60\u5c31\u6709\u5927\u9ebb\u70e6\u4e86\u3002\u800c\u4e14\uff0c\u6570\u636e\u5e93\u62bd\u8c61\u5c42\u901a\u5e38\u6bd4\u7cfb\u7edf\u672c\u8eab\u7684\u6570\u636e\u5e93\u51fd\u6570\uff0c\u66f4\u6613\u7528\u4e00\u4e9b\u3002<\/p>\n<p>5. &#8220;\u503c\u5bf9\u8c61&#8221;\uff08Value Object, VO\uff09<\/p>\n<p>\u503c\u5bf9\u8c61\uff08VO\uff09\u5728\u5f62\u5f0f\u4e0a\uff0c\u5c31\u50cfC\u8bed\u8a00\u7684struct\u7ed3\u6784\u3002\u5b83\u662f\u4e00\u4e2a\u53ea\u5305\u542b\u5c5e\u6027\u3001\u4e0d\u5305\u542b\u4efb\u4f55\u65b9\u6cd5\uff08\u6216\u53ea\u5305\u542b\u5f88\u5c11\u65b9\u6cd5\uff09\u7684\u7c7b\u3002\u4e00\u4e2a\u503c\u5bf9\u8c61\uff0c\u5c31\u5bf9\u5e94\u4e00\u4e2a\u5b9e\u4f53\u3002\u5b83\u7684\u5c5e\u6027\uff0c\u901a\u5e38\u5e94\u8be5\u4e0e\u6570\u636e\u5e93\u7684\u5b57\u6bb5\u540d\u4fdd\u6301\u76f8\u540c\u3002\u6b64\u5916\uff0c\u8fd8\u5e94\u8be5\u6709\u4e00\u4e2aID\u5c5e\u6027\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass Person {\r\n\r\nvar $id, $first_name, $last_name, $email;\r\n\r\n}\r\n<\/pre>\n<p>6. \u6570\u636e\u8bbf\u95ee\u5bf9\u8c61\uff08Data Access Object, DAO\uff09<\/p>\n<p>\u6570\u636e\u8bbf\u95ee\u5bf9\u8c61\uff08DAO\uff09\u7684\u4f5c\u7528\uff0c\u4e3b\u8981\u662f\u5c06\u6570\u636e\u5e93\u8bbf\u95ee\u4e0e\u5176\u4ed6\u4ee3\u7801\u76f8\u9694\u79bb\u3002DAO\u5e94\u8be5\u662f\u53ef\u4ee5\u53e0\u52a0\uff08stacked\uff09\u7684\uff0c\u8fd9\u6837\u5c31\u6709\u5229\u4e8e\u5c06\u6765\u4f60\u518d\u6dfb\u52a0\u6570\u636e\u5e93\u7f13\u5b58\u3002\u6bcf\u4e00\u4e2a\u503c\u5bf9\u8c61\u7684\u7c7b\uff0c\u90fd\u5e94\u8be5\u6709\u81ea\u5df1\u7684DAO\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass PersonDAO {\r\nvar $conn;\r\n\r\nfunction PersonDAO(&amp;amp;$conn) {\r\n$this-&amp;gt;conn =&amp;amp; $conn;\r\n}\r\n\r\nfunction save(&amp;amp;$vo) {\r\nif ($v-&amp;gt;id == 0) {\r\n$this-&amp;gt;insert($vo);\r\n} else {\r\n$this-&amp;gt;update($vo);\r\n}\r\n}\r\n\r\nfunction get($id) {\r\n#execute select statement\r\n#create new vo and call getFromResult\r\n#return vo\r\n}\r\n\r\nfunction delete(&amp;amp;$vo) {\r\n#execute delete statement\r\n#set id on vo to 0\r\n}\r\n\r\n#-- private functions\r\n\r\nfunction getFromResult(&amp;amp;vo, $result) {\r\n#fill vo from the database result set\r\n}\r\n\r\nfunction update(&amp;amp;$vo) {\r\n#execute update statement here\r\n}\r\n\r\nfunction insert(&amp;amp;$vo) {\r\n#generate id (from Oracle sequence or automatically)\r\n#insert record into db\r\n#set id on vo\r\n}\r\n}\r\n<\/pre>\n<p>DAO\u901a\u5e38\u5e94\u8be5\u90e8\u7f72\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p>* save\uff1a\u63d2\u5165\u6216\u66f4\u65b0\u4e00\u6761\u8bb0\u5f55<br \/>\n* get\uff1a\u53d6\u51fa\u4e00\u6761\u8bb0\u5f55<br \/>\n* delete\uff1a\u5220\u9664\u4e00\u6761\u8bb0\u5f55<\/p>\n<p>\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\uff0c\u6dfb\u52a0\u5176\u4ed6DAO\u65b9\u6cd5\uff0c\u5e38\u89c1\u7684\u4f8b\u5b50\u6709isUsed()\u3001getTop($n)\u3001find($criteria)\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u6240\u6709\u7684DAO\u65b9\u6cd5\u90fd\u5e94\u8be5\u4e0e\u6570\u636e\u5e93\u64cd\u4f5c\u6709\u5173\uff0c\u4e0d\u5e94\u8be5\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\u3002DAO\u53ea\u5e94\u8be5\u5bf9\u4e00\u5f20\u8868\u8fdb\u884c\u57fa\u672c\u7684select \/ insert \/ update\uff0c\u4e0d\u5e94\u8be5\u5305\u542b\u4e1a\u52a1\u903b\u8f91\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0cPersonDAO\u5c31\u4e0d\u5e94\u8be5\u5305\u542b\u5411\u67d0\u4eba\u53d1\u9001Email\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u5199\u4e00\u4e2a\u5de5\u5382\u51fd\u6570\uff0c\u6839\u636e\u4e0d\u540c\u7684\u7c7b\u540d\uff0c\u8fd4\u56de\u76f8\u5e94\u7684DAO\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction dao_getDAO($vo_class) {\r\n\r\n$conn = db_conn('default'); #get a connection from the pool\r\n\r\nswitch ($vo_class) {\r\n\r\ncase &quot;person&quot;: return new PersonDAO($conn);\r\n\r\ncase &quot;newsletter&quot;: return new NewsletterDAO($conn);\r\n\r\n...\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p>7. \u81ea\u52a8\u751f\u6210\u4ee3\u7801<\/p>\n<p>99%\u7684\u503c\u5bf9\u8c61\u548cDAO\u4ee3\u7801\uff0c\u53ef\u4ee5\u6839\u636e\u6570\u636e\u5e93\u6a21\u5f0f\uff08schema\uff09\u81ea\u52a8\u751f\u6210\uff0c\u524d\u63d0\u662f\u4f60\u7684\u8868\u548c\u5217\u4f7f\u7528\u7ea6\u5b9a\u7684\u65b9\u5f0f\u8fdb\u884c\u547d\u540d\u3002\u5982\u679c\u4f60\u4fee\u6539\u6570\u636e\u5e93\u6a21\u5f0f\uff0c\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u4ee3\u7801\u7684\u811a\u672c\u5c06\u5927\u5927\u8282\u7701\u4f60\u7684\u65f6\u95f4\u3002<\/p>\n<p>8. \u4e1a\u52a1\u903b\u8f91<\/p>\n<p>\u4e1a\u52a1\u903b\u8f91\u76f4\u63a5\u53cd\u6620\u4f7f\u7528\u8005\u7684\u9700\u8981\u3002\u5b83\u4eec\u5904\u7406\u503c\u5bf9\u8c61\uff0c\u6839\u636e\u4e1a\u52a1\u9700\u8981\u4fee\u6539\u503c\u5bf9\u8c61\u7684\u5c5e\u6027\uff0c\u4f7f\u7528DAO\u4e0e\u6570\u636e\u5e93\u5c42\u4ea4\u4e92\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass NewsletterLogic {\r\nfunction NewsletterLogic() {\r\n...\r\n}\r\n\r\nfunction subscribePerson(&amp;amp;$person) {\r\n...\r\n}\r\n\r\nfunction unsubscribePerson(&amp;amp;$person) {\r\n...\r\n}\r\n\r\nfunction sendNewsletter(&amp;amp;$newsletter) {\r\n...\r\n}\r\n}\r\n<\/pre>\n<p>9. \u9875\u903b\u8f91\uff08\u63a7\u5236\u5668\uff09<\/p>\n<p>\u5f53\u4e00\u4e2a\u7f51\u9875\u88ab\u8bf7\u6c42\u65f6\uff0c\u9875\u63a7\u5236\u5668\uff08page controller\uff09\u5c31\u4f1a\u8fd0\u884c\uff0c\u7136\u540e\u4ea7\u751f\u8f93\u51fa\u3002\u63a7\u5236\u5668\u7684\u4efb\u52a1\uff0c\u5c31\u662f\u5c06HTTP\u8bf7\u6c42\u8f6c\u5316\u6210\u4e1a\u52a1\u5bf9\u8c61\uff08business object\uff09\uff0c\u7136\u540e\u8c03\u7528\u76f8\u5e94\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u751f\u6210\u5c55\u793a\u8f93\u51fa\u7684\u5bf9\u8c61\u3002<\/p>\n<p>\u9875\u903b\u8f91\u4f9d\u6b21\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff08\u8bf7\u53c2\u7167\u540e\u9762\u7684PageController\u7c7b\u7684\u4ee3\u7801\uff09\uff1a<\/p>\n<p>i. \u5047\u5b9a\u9875\u9762\u8bf7\u6c42\u4e4b\u4e2d\uff0c\u5305\u542b\u4e00\u4e2acmd\u53c2\u6570\u3002<\/p>\n<p>ii. \u6839\u636ecmd\u53c2\u6570\u7684\u503c\uff0c\u6267\u884c\u76f8\u5e94\u7684\u52a8\u4f5c\u3002<\/p>\n<p>iii. \u9a8c\u8bc1\u9875\u9762\u8fd4\u56de\u7684\u503c\uff0c\u751f\u6210\u4e00\u4e2a\u503c\u5bf9\u8c61\u3002<\/p>\n<p>iv. \u9488\u5bf9\u503c\u5bf9\u8c61\uff0c\u6267\u884c\u4e1a\u52a1\u903b\u8f91\u3002<\/p>\n<p>v. \u5982\u679c\u6709\u5fc5\u8981\uff0c\u53ef\u4ee5\u5bfc\u5411\u53e6\u4e00\u4e2a\u9875\u9762\u3002<\/p>\n<p>vi. \u6536\u96c6\u5fc5\u8981\u7684\u6570\u636e\uff0c\u8f93\u51fa\u7ed3\u679c\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u5de5\u5177\u51fd\u6570\uff08utility function\uff09\uff0c\u5904\u7406GET\u6216POST\u503c\uff0c\u5f53\u6709\u7684\u53d8\u91cf\u6ca1\u6709\u8d4b\u503c\u65f6\uff0c\u63d0\u4f9b\u4e00\u4e2a\u9ed8\u8ba4\u503c\u3002\u9875\u903b\u8f91\u4e0d\u5305\u542bHTML\u4ee3\u7801\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass PageController {\r\nvar $person; #$person is used by the HTML page\r\nvar $errs;\r\n\r\nfunction PageController() {\r\n$action = Form::getParameter('cmd');\r\n$this-&amp;gt;person = new Person();\r\n$this-&amp;gt;errs = array();\r\n\r\nif ($action == 'save') {\r\n$this-&amp;gt;parseForm();\r\nif (!this-&amp;gt;validate()) return;\r\n\r\nNewsletterLogic::subscribe($this-&amp;gt;person);\r\n\r\nheader('Location: confirmation.php');\r\nexit;\r\n}\r\n}\r\n\r\nfunction parseForm() {\r\n$this-&amp;gt;person-&amp;gt;name = Form::getParameter('name');\r\n$this-&amp;gt;person-&amp;gt;birthdate = Util::parseDate(Form::getParameter('birthdate');\r\n...\r\n}\r\n\r\nfunction validate() {\r\nif ($this-&amp;gt;person-&amp;gt;name == '') $this-&amp;gt;errs&#x5B;'name'] = FORM_MISSING;\r\n#FORM_MISSING is a constant\r\n...\r\nreturn (sizeof($this-&amp;gt;errs) == 0);\r\n}\r\n}\r\n<\/pre>\n<p>10. \u8868\u73b0\u5c42\uff08Presentation Layer\uff09<\/p>\n<p>\u6700\u9876\u5c42\u7684\u9875\u9762\u5305\u542b\u5b9e\u9645\u7684HTML\u4ee3\u7801\u3002\u8fd9\u4e2a\u9875\u9762\u9700\u8981\u7684\u6240\u6709\u4e1a\u52a1\u5bf9\u8c61\uff08business object\uff09\uff0c\u7531\u9875\u903b\u8f91\u63d0\u4f9b\u3002<\/p>\n<p>\u8fd9\u4e2a\u9875\u9762\u5148\u8bfb\u53d6\u4e1a\u52a1\u5bf9\u8c61\u7684\u5c5e\u6027\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u8f6c\u6362\u6210HTML\u683c\u5f0f\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&amp;lt;?php\r\nrequire_once('control\/ctl_person.inc.php'); #the page controller\r\n$c =&amp;amp; new PageController();\r\n?&amp;gt;\r\n\r\n&amp;lt;html&amp;gt;\r\n&amp;lt;body&amp;gt;\r\n&amp;lt;form action=&quot;&amp;lt;?php echo htmlspecialchars($PHP_SELF) ?&amp;gt;&quot; method=&quot;POST&quot;&amp;gt;\r\n&amp;lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;save&quot;&amp;gt;\r\n&amp;lt;input type=&quot;text&quot; name=&quot;name&quot;\r\nvalue=&quot;&amp;lt;?php echo htmlspecialchars($c-&amp;gt;person-&amp;gt;name); ?&amp;gt;&quot;&amp;gt;\r\n&amp;lt;button type=&quot;submit&quot;&amp;gt;Subscribe&amp;lt;\/button&amp;gt;\r\n&amp;lt;\/form&amp;gt;\r\n&amp;lt;\/body&amp;gt;\r\n&amp;lt;\/html&amp;gt;\r\n<\/pre>\n<p>11. \u672c\u5730\u5316\uff08Localization\uff09<\/p>\n<p>\u672c\u5730\u5316\u610f\u5473\u7740\u8981\u652f\u6301\u591a\u79cd\u8bed\u8a00\uff0c\u8fd9\u4e2a\u6bd4\u8f83\u9ebb\u70e6\uff0c\u4f60\u65e0\u975e\u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u9009\u62e9\uff1a<\/p>\n<p>A) \u51c6\u5907\u591a\u91cd\u9875\u9762\u3002<\/p>\n<p>B) HTML\u9875\u9762\u4e2d\u53bb\u9664\u7279\u5b9a\u8bed\u8a00\u76f8\u5173\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0cA\u65b9\u6cd5\u7528\u5f97\u6bd4\u8f83\u591a\uff0c\u56e0\u4e3aB\u65b9\u6cd5\u4f1a\u4f7f\u5f97HTML\u9875\u9762\u7684\u53ef\u8bfb\u6027\u5f88\u5dee\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u4f60\u53ef\u4ee5\u5148\u5199\u5b8c\u4e00\u79cd\u8bed\u8a00\u7684\u9875\u9762\uff0c\u7136\u540e\u628a\u5b83\u4eec\u8fdb\u884c\u62f7\u8d1d\uff0c\u7528\u67d0\u79cd\u547d\u540d\u6cd5\u533a\u522b\u4e0d\u540c\u8bed\u8a00\u7684\u7248\u672c\uff0c\u6bd4\u5982index_fr.php\u8868\u793aindex.php\u7684\u6cd5\u8bed\u7248\u3002<\/p>\n<p>\u4e3a\u4e86\u4fdd\u5b58\u7528\u6237\u7684\u8bed\u8a00\u9009\u62e9\uff0c\u4f60\u6709\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p>A) \u5c06\u8bed\u8a00\u8bbe\u5b9a\u4fdd\u5b58\u5728\u4e00\u4e2asession\u53d8\u91cf\u6216cookie\u4e4b\u4e2d\uff1b<\/p>\n<p>B) \u4eceHTTP\u5934\u4e2d\u8bfb\u53d6locale\u503c\uff1b<\/p>\n<p>C) \u628a\u8bed\u8a00\u8bbe\u5b9a\u4f5c\u4e3a\u4e00\u4e2a\u53c2\u6570\uff0c\u8ffd\u52a0\u5728\u6bcf\u4e2aURL\u540e\u9762\u3002<\/p>\n<p>\u770b\u4e0a\u53bbA\u65b9\u6cd5\u6bd4C\u65b9\u6cd5\u5bb9\u6613\u5f97\u591a\uff08\u867d\u7136session\u548ccookie\u90fd\u6709\u8fc7\u671f\u7684\u95ee\u9898\uff09\uff0c\u800cB\u65b9\u6cd5\u53ea\u80fd\u4f5c\u4e3aA\u6216C\u7684\u8865\u5145\u3002<\/p>\n<p>\u6700\u540e\u4e0d\u8981\u5fd8\u4e86\uff0c\u6570\u636e\u5e93\u4e2d\u7684\u5b57\u6bb5\u4e5f\u5fc5\u987b\u8fdb\u884c\u672c\u5730\u5316\u3002<\/p>\n<p>12. \u5b89\u88c5\u4f4d\u7f6e<\/p>\n<p>\u6709\u65f6\u5019\u4f60\u9700\u8981\u77e5\u9053\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u5728\u54ea\u91cc\uff0c\u4f46\u662f$_SERVER[&#8216;DOCUMENT_ROOT&#8217;]\u53ea\u662fweb\u670d\u52a1\u5668\u7684\u6839\u76ee\u5f55\uff0c\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u5b89\u88c5\u5728\u5b83\u7684\u67d0\u4e2a\u5b50\u76ee\u5f55\u4e4b\u4e2d\uff0cPHP\u6ca1\u6cd5\u81ea\u52a8\u77e5\u9053\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf$ROOT\uff0c\u5b83\u7684\u503c\u5c31\u662f\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\uff0c\u7136\u540e\u628a\u5b83\u5305\u542b\u5728\u6bcf\u4e00\u4e2a\u811a\u672c\u6587\u4ef6\u4e2d\u3002\u90a3\u4e48\uff0c\u4f60\u8981\u5305\u542b\u67d0\u4e2a\u6587\u4ef6\uff0c\u5c31\u8fd9\u6837\u5199require_once(&#8220;$ROOT\/lib\/base.inc.php&#8221;);\u3002<\/p>\n<p>13. \u76ee\u5f55\u7ed3\u6784<\/p>\n<p>\u9996\u5148\uff0c\u6bcf\u4e2a\u7c7b\u90fd\u5e94\u8be5\u6709\u81ea\u5df1\u7684\u72ec\u7acb\u6587\u4ef6\uff0c\u8fd8\u5fc5\u987b\u6709\u4e00\u5957\u6587\u4ef6\u540d\u7684\u547d\u540d\u89c4\u5219\uff08naming convention\uff09\u3002<\/p>\n<p>\u8f6f\u4ef6\u7684\u76ee\u5f55\u7ed3\u6784\u53ef\u4ee5\u91c7\u7528\u5982\u4e0b\u5f62\u5f0f\uff1a<\/p>\n<p>\/ \u6839\u76ee\u5f55\u3002\u6d4f\u89c8\u5668\u4ece\u8fd9\u4e2a\u9875\u9762\u5f00\u59cb\u8bbf\u95ee\u3002<\/p>\n<p>\/lib\/ \u5305\u542b\u5168\u5c40\u53d8\u91cf\uff08base.inc.php\uff09\u548c\u914d\u7f6e\u6587\u4ef6\uff08config.inc.php\uff09\u3002<\/p>\n<p>\/lib\/common\/ \u5305\u542b\u5176\u4ed6\u9879\u76ee\u4e5f\u53ef\u4ee5\u5171\u7528\u7684\u5e93\uff0c\u6bd4\u5982\u6570\u636e\u5e93\u62bd\u8c61\u5c42\u3002<\/p>\n<p>\/lib\/model\/ \u5305\u542b\u503c\u5bf9\u8c61\u7c7b\u3002<\/p>\n<p>\/lib\/dao\/ \u5305\u542b\u6570\u636e\u8bbf\u95ee\u5bf9\u8c61\uff08DAO\uff09\u7c7b\uff0c\u4ee5\u53caDAO\u5de5\u5382\u51fd\u6570\u3002<\/p>\n<p>\/lib\/logic\/ \u5305\u542b\u4e1a\u52a1\u903b\u8f91\u7c7b\u3002<\/p>\n<p>\/parts\/ \u5305\u542bHTML\u6a21\u677f\u6587\u4ef6\u3002<\/p>\n<p>\/control\/ \u5305\u542b\u9875\u903b\u8f91\u3002\u5bf9\u4e8e\u5927\u578b\u7a0b\u5e8f\u6765\u8bf4\uff0c\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u9762\u53ef\u80fd\u8fd8\u6709\u5b50\u76ee\u5f55\uff08\u6bd4\u5982admin\/\uff0c \/pub\/\uff09\u3002<\/p>\n<p>base.inc.php\u6587\u4ef6\u4e2d\uff0c\u5e94\u8be5\u6309\u7167\u4ee5\u4e0b\u987a\u5e8f\u6dfb\u52a0\u5305\u542b\u6587\u4ef6\uff1a<\/p>\n<p>* \/lib\/common\u4e4b\u4e2d\u7ecf\u5e38\u4f7f\u7528\u7684\u7c7b\uff08\u6bd4\u5982\u6570\u636e\u5e93\u5c42\uff09\u3002<\/p>\n<p>* \u914d\u7f6e\u6587\u4ef6\uff1b<\/p>\n<p>* \/lib\/model\u4e4b\u4e2d\u6240\u6709\u7c7b\uff1b<\/p>\n<p>* \/lib\/dao\u7684\u4e4b\u4e2d\u6240\u6709\u7c7b\u3002<\/p>\n<p>\u81f3\u4e8e\u90a3\u4e9b\u5b58\u653e\u56fe\u7247\u3001\u4e0a\u4f20\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u8fd9\u91cc\u5c31\u7701\u7565\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7ed9\u51fa\u4e86PHP\u7a0b\u5e8f\u8bbe\u8ba1\u5e38\u89c1\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6cd5\uff0c\u540c\u65f6\u7b80\u5355\u63cf\u8ff0\u4e86PHP\u5e94\u7528\u7a0b\u5e8f\u7684\u67b6\u6784\u3002 1. php.ini\u8bbe\u7f6e p [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1438","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1438"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1438\/revisions"}],"predecessor-version":[{"id":5224,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1438\/revisions\/5224"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}