{"id":902,"date":"2009-08-19T01:00:00","date_gmt":"2009-08-18T16:00:00","guid":{"rendered":"https:\/\/ecoop.net\/memo\/2009-08-19-1.html"},"modified":"2026-08-10T14:45:49","modified_gmt":"2026-08-10T05:45:49","slug":"2009-08-19-1","status":"publish","type":"post","link":"https:\/\/www.ecoop.net\/memo\/archives\/2009-08-19-1.html","title":{"rendered":"PHP\u306esession_regeneration_id \u3068\u30bb\u30c3\u30b7\u30e7\u30f3\u30d5\u30a3\u30af\u30b7\u30a8\u30fc\u30b7\u30e7\u30f3\u5bfe\u7b56"},"content":{"rendered":"<p>\nCSRF \u5bfe\u7b56\u306e\u3046\u3061\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u30d5\u30a3\u30af\u30bb\u30fc\u30b7\u30e7\u30f3\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u4f7f\u308f\u308c\u308b<br \/>\nsession_regenerate_id() \u95a2\u6570\u306b\u3064\u3044\u3066\u3001ITPro\u3067\u9593\u9055\u3044(\u306b\u306a\u308b\u5834\u5408\u304c\u3042\u308b)\u8a18\u4e8b\u3092\u898b\u3064\u3051\u305f\u306e\u3067\u30e1\u30e2\u3002<br \/>\n&nbsp;<br \/>\n<a href=\"http:\/\/itpro.nikkeibp.co.jp\/article\/COLUMN\/20070111\/258496\/\">\u95a2\u6570\u306e\u77e5\u3089\u308c\u3056\u308b\u5f15\u6570\uff08print_r\u95a2\u6570\u3001session_regenerate_id\u95a2\u6570\uff09[<\/a>\u3088\u308a<\/p>\n<blockquote><p>\u540c\u3058\u3088\u3046\u306b\u3001PHP 5.1\u304b\u3089\u306fsession_regenerate_id\u95a2\u6570\u306b\u3082\u7b2c1\u5f15\u6570\u304c\u6307\u5b9a\u3055\u308c\u307e\u3057\u305f\u3002\u7b2c1\u5f15\u6570\u3092true\u306b\u6307\u5b9a\u3059\u308b\u3068\u3001\u53e4\u304f\u306a\u3063\u305f\u30bb\u30c3\u30b7\u30e7\u30f3\u306f\u524a\u9664\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n&nbsp;<br \/>\n\u3082\u3068\u3082\u3068\u30bb\u30c3\u30b7\u30e7\u30f3\u56fa\u5b9a\u653b\u6483\u3092\u9632\u3050\u305f\u3081\u306b\u7528\u610f\u3055\u308c\u305f\u95a2\u6570\u3067\u306f\u306a\u304f\u3001PHP 5.1 \u307e\u3067\u306e\u540c\u95a2\u6570\u306b\u306f\u53e4\u3044\u30bb\u30c3\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308b\u6a5f\u80fd\u304c\u7121\u304b\u3063\u305f\u305f\u3081\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u56fa\u5b9a\u653b\u6483\u3078\u306e\u5bfe\u7b56\u3068\u3057\u3066\u306f\u4e0d\u5341\u5206\u3067\u3057\u305f\u3002<br \/>\n&nbsp;<br \/>\n\u4eca\u5f8c\u306f\u3001session_regenerate_id\u95a2\u6570\u306e\u5f15\u6570\u306b\u5fc5\u305atrue\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\u307e\u305f\u3001\u305d\u308c\u307e\u3067\u306ePHP\u3067\u4f7f\u3046\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u56fa\u5b9a\u653b\u6483\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \n<\/p><\/blockquote>\n<p>\u306e\u3088\u3046\u306b\u3001session_regenerate_id() \u306e\u7b2c\u4e00\u5f15\u6570\u306b true \u3092\u5e38\u306b\u6307\u5b9a\u3059\u3079\u304d\u3068\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u304c\u3001session_regenerate_id(true) \u306f\u3080\u3084\u307f\u306b\u4f7f\u3063\u3066\u306f\u306a\u308a\u307e\u305b\u3093\u3002<br \/>\n&nbsp;<br \/>\n\u30b7\u30e7\u30c3\u30d4\u30f3\u30b0\u30ab\u30fc\u30c8\u306a\u3069\u9650\u5b9a\u7684\u306a\u7528\u9014\u3067\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u554f\u984c\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u5e38\u306b\u30ed\u30b0\u30a4\u30f3\u304c\u5fc5\u8981\u306a\u30b5\u30a4\u30c8\u306a\u3069\u3067\u975e\u540c\u671f\u3067\u8907\u6570\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u5b9f\u884c\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u5834\u5408\u3001\u53e4\u3044\u30bb\u30c3\u30b7\u30e7\u30f3\u304c\u524a\u9664\u3055\u308c\u308b\u3068\u554f\u984c\u306b\u306a\u308a\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n&nbsp;<br \/>\n\u305f\u3068\u3048\u3070\u540c\u3058 HTML \u5185\u306b\u8a8d\u8a3c\u304c\u5fc5\u8981\u306a\u753b\u50cf\u306a\u3069\u306e\u57cb\u3081\u8fbc\u307f\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u8907\u6570\u3042\u3063\u305f\u308a AJAX \u3067\u8a8d\u8a3c\u304c\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u5834\u5408\u3001\u4e00\u3064\u306e\u30bb\u30c3\u30b7\u30e7\u30f3ID\u3067\u8907\u6570\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u884c\u3046\u305f\u3081\u30012\u30ea\u30af\u30a8\u30b9\u30c8\u76ee\u4ee5\u964d\u3082\u53e4\u3044\u30bb\u30c3\u30b7\u30e7\u30f3\u3067\u8a8d\u8a3c\u3059\u308b\u3053\u3068\u306b\u306a\u308b\u304b\u3089\u3067\u3059\u3002<br \/>\n&nbsp;<br \/>\n\u4ee3\u66ff\u6848\u3068\u3057\u3066\u3001session_regenerate_id(false) \u3068 session_write_close() \u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u53e4\u3044\u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u307f\u6709\u52b9\u671f\u9593\u3092\u8a2d\u5b9a\u3057\u3066\u3084\u308b\u3068\u3088\u3044\u3001\u3068<a href=\"http:\/\/jp2.php.net\/manual\/ja\/function.session-regenerate-id.php\">session_regenrate_id\u306e\u30b3\u30e1\u30f3\u30c8\u6b04<\/a>\u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3057\u305f\u3002<br \/>\n&nbsp;<br \/>\n\u5b9f\u88c5\u4f8b:\n<\/p>\n<blockquote><p>\/\/ \u30e6\u30fc\u30b6\u304c\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u305f\u30bb\u30c3\u30b7\u30e7\u30f3ID\u304b\u3089\u30bb\u30c3\u30b7\u30e7\u30f3\u60c5\u5831\u3092\u30ed\u30fc\u30c9\u3059\u308b\u3002<br \/>\nsession_start(); <br \/>\n\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n\/\/ \u4ee5\u4e0b\u30bb\u30c3\u30b7\u30e7\u30f3\u30d5\u30a3\u30af\u30bb\u30fc\u30b7\u30e7\u30f3\u5bfe\u7b56<br \/>\nif(isset($_SESSION[&#8216;expire&#8217;]) &amp;&amp; $_SESSION[&#8216;expire&#8217;] < time()){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ \u904e\u53bb\u306b session_regenerate_id() \u3067\u7f6e\u304d\u63db\u3048\u3089\u308c\u305f\u53e4\u3044\u30bb\u30c3\u30b7\u30e7\u30f3\u306b\u3088\u308b\u30a2\u30af\u30bb\u30b9\u3002<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ \u6709\u52b9\u671f\u9650\u3092\u904e\u304e\u3066\u3044\u308c\u3070\u30bb\u30c3\u30b7\u30e7\u30f3\u60c5\u5831\u3092\u30af\u30ea\u30a2\u3059\u308b\u3002<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$_SESSION = array();<br \/>\n}<br \/>\n&nbsp;<br \/>\n\/\/ \u53e4\u3044\u30bb\u30c3\u30b7\u30e7\u30f3\u306f2\u5206\u9593\u3067\u6d88\u3048\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3002<br \/>\n$_SESSION[&#8216;expire&#8217;] = time() + (2*60); <br \/>\n\/\/ \u6709\u52b9\u671f\u9650\u3092\u8a18\u9332\u3059\u308b\u305f\u3081\u3001\u4e00\u65e6\u660e\u793a\u7684\u306b\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u9589\u3058\u3001$_SESSION \u306e\u4e2d\u8eab\u3092\u53e4\u3044\u30bb\u30c3\u30b7\u30e7\u30f3ID\u3067\u4fdd\u5b58\u3059\u308b\u3002<br \/>\nsession_write_close();<br \/>\n&nbsp;<br \/>\n\/\/ \u9589\u3058\u305f\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u958b\u304d\u306a\u304a\u3059\u3002<br \/>\nsession_start();<br \/>\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3ID\u3092\u66f4\u65b0\u3057\u3001$_SESSION \u3092\u53e4\u3044\u30bb\u30c3\u30b7\u30e7\u30f3ID\u304b\u3089\u5207\u308a\u96e2\u3059\u3002<br \/>\nsession_regenerate_id();<br \/>\n\/\/ \u65b0\u3057\u3044\u30bb\u30c3\u30b7\u30e7\u30f3ID \u306f\u6709\u52b9\u671f\u9650\u306a\u3057\u3002<br \/>\nunset($_SESSION[&#8216;expire&#8217;]);<br \/>\n\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u30d5\u30a3\u30af\u30bb\u30fc\u30b7\u30e7\u30f3\u5bfe\u7b56\u3053\u3053\u307e\u3067\u3002<br \/>\n\/\/ \u3042\u3068\u306f\u901a\u5e38\u901a\u308a\u3002<br \/>\n$_SESSION[&#8216;user_id&#8217;] = &#8220;1234&#8221;;\n<\/p><\/blockquote>\n<p>&nbsp;<br \/>\n\u307e\u305f\u3001session_regenerate_id() \u3060\u3051\u3067\u306f\u30bb\u30c3\u30b7\u30e7\u30f3\u6240\u6709\u8005\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u3088\u308b XSRF \u306f\u9632\u3050\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u305f\u3081\u3001\u3053\u3061\u3089(\u958b\u767a\u8005\u306e\u305f\u3081\u306e\u6b63\u3057\u3044CSRF\u5bfe\u7b56)\u3092\u53c2\u8003\u306b\u30ef\u30f3\u30bf\u30a4\u30e0\u30c8\u30fc\u30af\u30f3\u7b49\u3082\u9069\u5b9c\u7d44\u307f\u5408\u308f\u305b\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSRF \u5bfe\u7b56\u306e\u3046\u3061\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u30d5\u30a3\u30af\u30bb\u30fc\u30b7\u30e7\u30f3\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u4f7f\u308f\u308c\u308b session_regenerate_id() \u95a2\u6570\u306b\u3064\u3044\u3066\u3001ITPro\u3067\u9593\u9055\u3044(\u306b\u306a\u308b\u5834\u5408\u304c\u3042\u308b)\u8a18\u4e8b\u3092\u898b\u3064\u3051\u305f\u306e\u3067\u30e1\u30e2\u3002 &nbsp; \u95a2\u6570\u306e\u77e5 &hellip; <a href=\"https:\/\/www.ecoop.net\/memo\/archives\/2009-08-19-1.html\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">PHP\u306esession_regeneration_id \u3068\u30bb\u30c3\u30b7\u30e7\u30f3\u30d5\u30a3\u30af\u30b7\u30a8\u30fc\u30b7\u30e7\u30f3\u5bfe\u7b56<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[32],"class_list":["post-902","post","type-post","status-publish","format-standard","hentry","category-web-dev","tag-php"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/comments?post=902"}],"version-history":[{"count":1,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/902\/revisions"}],"predecessor-version":[{"id":1793,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/902\/revisions\/1793"}],"wp:attachment":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/media?parent=902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/categories?post=902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/tags?post=902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}