{"id":4871,"date":"2023-08-09T21:51:29","date_gmt":"2023-08-09T12:51:29","guid":{"rendered":"http:\/\/www.lining-moon.casa\/andplus.co.jp_230822_230809\/?p=4871"},"modified":"2026-02-25T11:11:31","modified_gmt":"2026-02-25T02:11:31","slug":"post-4871","status":"publish","type":"post","link":"https:\/\/code-plus.jp\/gp\/post-4871\/","title":{"rendered":"$_SESSION\uff08\u30bb\u30c3\u30b7\u30e7\u30f3\uff09\u3092JavaScript\u5909\u6570\u306b\u5909\u63db\u3057\u3066\u3001\u30bf\u30b0\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u306e\u30c8\u30ea\u30ac\u30fc\u5024\u3068\u3057\u3066\u4f7f\u7528\u3059\u308b"},"content":{"rendered":"<h3>1. PHP\u300c$_SESSION\u300d\u306e\u8a18\u9332\u65b9\u6cd5<\/h3>\r\n<p>\u30bb\u30c3\u30b7\u30e7\u30f3\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3092\u8a2a\u308c\u308b\u3068\u304d\u306b\u30b5\u30fc\u30d0\u30fc\u4e0a\u3067\u4e00\u6642\u7684\u306b\u60c5\u5831\u3092\u4fdd\u5b58\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f\u3067\u3059\u3002\u3053\u306e\u60c5\u5831\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3092\u9589\u3058\u308b\u304b\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u304c\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3059\u308b\u307e\u3067\u4fdd\u6301\u3055\u308c\u307e\u3059\u3002<\/p>\r\n<p><\/p>\r\n<pre class=\"language-php\"><code>\r\n&lt;?php \/\/\uff08function.php\uff09\r\n\r\n\/* $_SESSION\uff08\u30bb\u30c3\u30b7\u30e7\u30f3\uff09 \u958b\u59cb\r\n\u0fd0\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u2740\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u0f04 *\/\r\n\/\/\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570 $global_session_params \u3092\u5b9a\u7fa9\r\nglobal $global_session_params;\r\n$global_session_params = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'ancestor', 'referrer', 'ref_name', 'edomain']; \/\/\u4fdd\u5b58\u3057\u305f\u3044\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u914d\u5217\u306b\u8ffd\u52a0\r\n\r\nfunction init_session_start() {\r\n  global $global_session_params; \/\/\u3053\u306e\u95a2\u6570\u5185\u3067\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e\u5ba3\u8a00\r\n\r\n  if (session_status() !== PHP_SESSION_ACTIVE) {\r\n    session_start();\r\n  }\r\n\r\n  \/\/$global_session_params \u3092\u3001\u305d\u308c\u305e\u308c\u30bb\u30c3\u30b7\u30e7\u30f3 $_SESSION[$param] \u306b\u8a18\u61b6\r\n  foreach ($global_session_params as $param) {\r\n    if (isset($_GET[$param])) {\r\n      $_SESSION[$param] = sanitize_input($_GET[$param]);\r\n    }\r\n  }\r\n}\r\n\r\n\/\/\u30b5\u30cb\u30bf\u30a4\u30ba\u95a2\u6570\r\nfunction sanitize_input($data) {\r\n  return htmlspecialchars(stripslashes(trim($data)), ENT_QUOTES, 'UTF-8');\r\n}\r\nadd_action('init', 'init_session_start');\r\n<\/code><\/pre>\r\n<p><\/p>\r\n<p><\/p>\r\n<p><\/p>\r\n<h3>2. JavaScript\u5909\u6570\u3078\u306e\u5909\u63db\u65b9\u6cd5<\/h3>\r\n<p>\u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u5024\u3092JavaScript\u5909\u6570\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u3067\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3084\u5916\u90e8\u30c4\u30fc\u30eb\uff08\u4f8b\uff1aGoogle\u30bf\u30b0\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\uff09\u3067\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\r\n<p><\/p>\r\n<pre class=\"language-php\"><code>\r\n&lt;?php\r\n\/** \uff08header.php\uff09\r\n****************************************\/\r\n?&gt;\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"ja\"&gt;\r\n\r\n&lt;head&gt;\r\n\u301c\u301c\u301c\u301c\r\n&lt;?php wp_head(); ?&gt;\r\n\u301c\u301c\u301c\u301c\r\n&lt;\/head&gt;\r\n\r\n&lt;?php\r\n\/\/JS\u5909\u6570 $_SESSION_param = \"\u30bb\u30c3\u30b7\u30e7\u30f3\u5024\" \u3092\u305d\u308c\u305e\u308c\u4ee3\u5165\r\nglobal $global_session_params; \/\/\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u5185\u3067\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e\u5ba3\u8a00\r\nforeach ($global_session_params as $param) {\r\n  if (isset($_SESSION[$param])) {\r\n    \/\/JavaScript\u306e\u6587\u5b57\u5217\u30ea\u30c6\u30e9\u30eb\u3068\u3057\u3066\u30a8\u30b9\u30b1\u30fc\u30d7\r\n    $js_value = json_encode($_SESSION[$param]);\r\n    echo \"&lt;script&gt;var \\$_SESSION_{$param} = {$js_value};&lt;\/script&gt;\";\r\n  }\r\n}\r\n?&gt;\r\n\r\n&lt;body&gt;\r\n\u301c\u301c\u301c\u301c\r\n\r\n<\/code><\/pre>\r\n<p><\/p>\r\n<p><\/p>\r\n<h3>3. \u30bf\u30b0\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u3067\u306e\u4f7f\u7528\u4f8b<\/h3>\r\n<p>Google\u30bf\u30b0\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u3067\u306f\u3001\u5909\u6570\u3092\u4f5c\u6210\u3057\u3066\u30c8\u30ea\u30ac\u30fc\u306e\u6761\u4ef6\u3068\u3057\u3066\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u3001\u5909\u6570\u3068\u3057\u3066<code>$_SESSION_utm_source<\/code>\u3092\u4f7f\u7528\u3057\u3066\u3001\u305d\u306e\u5024\u304cgoogle\u3092\u542b\u3080\u5834\u5408\u306b\u30c8\u30ea\u30ac\u30fc\u3092\u767a\u706b\u3055\u305b\u308b\u4f8b\u3067\u3059\u3002<\/p>\r\n<p><\/p>\r\n<p>\u30bf\u30b0\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u306e\u300c\u5909\u6570\u300d\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u65b0\u3057\u3044\u5909\u6570\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\r\n\u5909\u6570\u306e\u30bf\u30a4\u30d7\u3068\u3057\u3066\u300cJavaScript\u5909\u6570\u300d\u3092\u9078\u629e\u3057\u307e\u3059\u3002<br \/>\r\n\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u540d\u3068\u3057\u3066<code>$_SESSION_utm_source<\/code>\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\r\n<p>\u3053\u306e\u5909\u6570\u3092\u30c8\u30ea\u30ac\u30fc\u306e\u6761\u4ef6\u3068\u3057\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\r\n<p><span class=\"is-padding-xxs is-outlined\" style=\"border: 1px solid hsla(0, 0%, 44%, 1);\"><img decoding=\"async\" src=\"http:\/\/www.lining-moon.casa\/andplus.co.jp_230822\/wp-content\/uploads\/91bb1b072da09891b6cdc0b641dc40c0-1.png\" alt=\"\" width=\"936\" height=\"614\" class=\"alignnone size-full wp-image-4878\" \/><\/span><\/p>\r\n<p>\u4f8b\uff1a{{$_SESSION_utm_source}} [\u542b\u3080] google \u7b49<\/p>\r\n<p><\/p>\r\n<p>\u3053\u306e\u8a18\u4e8b\u306f\u3001<code>$_SESSION<\/code>\u3092JavaScript\u5909\u6570\u306b\u5909\u63db\u3057\u3066\u3001\u30bf\u30b0\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u306e\u30c8\u30ea\u30ac\u30fc\u3068\u3057\u3066\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3092\u7c21\u5358\u306b\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u3002\u5177\u4f53\u7684\u306a\u5b9f\u88c5\u3084\u8a73\u7d30\u306a\u8a2d\u5b9a\u306b\u3064\u3044\u3066\u306f\u3001\u95a2\u9023\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3084\u30ea\u30bd\u30fc\u30b9\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>","protected":false},"excerpt":{"rendered":"1. PHP\u300c$_SESSION\u300d\u306e\u8a18\u9332\u65b9\u6cd5 \u30bb\u30c3\u30b7\u30e7\u30f3\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3092\u8a2a\u308c\u308b\u3068\u304d\u306b\u30b5\u30fc\u30d0\u30fc\u4e0a\u3067\u4e00\u6642\u7684\u306b\u60c5\u5831\u3092\u4fdd\u5b58\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f\u3067\u3059\u3002\u3053\u306e\u60c5\u5831\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3092\u9589\u3058\u308b\u304b\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u304c\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3059[...]","protected":false},"author":1,"featured_media":4878,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","footnotes":"","vk-ltc-link":"","vk-ltc-target":"0"},"categories":[13],"tags":[],"group":[],"pg":[],"class_list":["post-4871","post","type-post","status-publish","format-standard","has-post-thumbnail","category-wordpress"],"acf":[],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/4871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/comments?post=4871"}],"version-history":[{"count":0,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/4871\/revisions"}],"wp:attachment":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media?parent=4871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/categories?post=4871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/tags?post=4871"},{"taxonomy":"group","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/group?post=4871"},{"taxonomy":"pg","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/pg?post=4871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}