<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4568,"date":"2022-08-03T12:37:58","date_gmt":"2022-08-03T12:37:58","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4568"},"modified":"2022-08-03T12:37:58","modified_gmt":"2022-08-03T12:37:58","slug":"what-is-session-in-php","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/","title":{"rendered":"What is session in PHP ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">PHP session is used to store and pass information from one page to another page temporarily until the user closes website.<\/li>\n<li style=\"text-align: justify;\">In shopping website PHP website is widely used where we need to store and pass cart information from one page to another.<\/li>\n<li style=\"text-align: justify;\">For example. username, product code, product name, product price etc.<\/li>\n<li style=\"text-align: justify;\">The session creates unique user id for each browser to recognize the user and avoid conflict between multiple browsers.<\/li>\n<li style=\"text-align: justify;\">PHP session_start () function is used to start the session and starts new and resume existing session.<\/li>\n<li style=\"text-align: justify;\">If session is created already then it returns existing session and if session is not available, it returns and creates new session.<\/li>\n<li style=\"text-align: justify;\">It is an associative array that contains all session variables and it is used to get and set session variables.<\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4569 aligncenter\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png\" alt=\"\" width=\"1209\" height=\"727\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png 1209w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-300x180.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-1024x616.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-768x462.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-390x235.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-820x493.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-1180x710.png 1180w\" sizes=\"(max-width: 1209px) 100vw, 1209px\" \/><\/p>\n<h2 id=\"syntax\">Syntax<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\">&lt;?php<br\/>  <br\/>           session_start();<br\/>  <br\/>            ?&gt;<\/code><\/pre> <\/div>\n<h2 id=\"sample-code\">Sample Code<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\">&lt;?php<br\/>                 session_start();<br\/>                ?&gt;<br\/>              &lt;!DOCTYPE html&gt;<br\/>              &lt;html&gt;<br\/>              &lt;body&gt;<br\/><br\/>              &lt;?php<br\/>               \/\/ Echo session variables that were set on previous page<br\/>                 echo &quot;Favorite color is &quot; . $_SESSION[&quot;favcolor&quot;] . &quot;.&lt;br&gt;&quot;;<br\/>                 echo &quot;Favorite animal is &quot; . $_SESSION[&quot;favanimal&quot;] . &quot;.&quot;;<br\/>              ?&gt;<br\/><br\/>            &lt;\/body&gt;<br\/>            &lt;\/html&gt;<\/code><\/pre> <\/div>\n<h2 id=\"output\">Output<\/h2>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4570\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-example.png\" alt=\"\" width=\"1290\" height=\"549\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-example.png 1290w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-example-300x128.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-example-1024x436.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-example-768x327.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-example-390x166.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-example-820x349.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session-example-1180x502.png 1180w\" sizes=\"(max-width: 1290px) 100vw, 1290px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP session is used to store and pass information from one page to another page temporarily until the user closes website. In shopping website PHP website is widely used where we need to store and pass cart information from one page to another. For example. username, product code, product name, product price etc. The session [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[8182],"tags":[17749,17748,17751,17747,17752,17750,17756,17754,17758,17746,17753,17755,17759,17757],"class_list":["post-4568","post","type-post","status-publish","format-standard","hentry","category-php","tag-how-to-get-data-from-session-in-php","tag-how-to-set-session-in-php","tag-php-session-login","tag-session-and-cookies-in-php","tag-session-start-in-php","tag-session-variable-in-php","tag-what-is-difference-between-session-and-cookies-in-php","tag-what-is-session-and-cookies-in-php","tag-what-is-session-id-in-php","tag-what-is-session-in-php","tag-what-is-session-in-php-how-it-works","tag-what-is-session-start-in-php","tag-what-is-session_destroy-in-php","tag-what-is-the-default-session-time-in-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Session in PHP - PHP Sessions - How to use Sessions<\/title>\n<meta name=\"description\" content=\"What is Session in PHP - PHP session is used to store and pass information from one page to another page temporarily until the user closes website.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Session in PHP - PHP Sessions - How to use Sessions\" \/>\n<meta property=\"og:description\" content=\"What is Session in PHP - PHP session is used to store and pass information from one page to another page temporarily until the user closes website.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-03T12:37:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/\",\"name\":\"What is Session in PHP - PHP Sessions - How to use Sessions\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png\",\"datePublished\":\"2022-08-03T12:37:58+00:00\",\"dateModified\":\"2022-08-03T12:37:58+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is Session in PHP - PHP session is used to store and pass information from one page to another page temporarily until the user closes website.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png\",\"width\":1209,\"height\":727},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Session in PHP - PHP Sessions - How to use Sessions","description":"What is Session in PHP - PHP session is used to store and pass information from one page to another page temporarily until the user closes website.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/","og_locale":"en_US","og_type":"article","og_title":"What is Session in PHP - PHP Sessions - How to use Sessions","og_description":"What is Session in PHP - PHP session is used to store and pass information from one page to another page temporarily until the user closes website.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/","og_site_name":"Wikitechy","article_published_time":"2022-08-03T12:37:58+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/","name":"What is Session in PHP - PHP Sessions - How to use Sessions","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png","datePublished":"2022-08-03T12:37:58+00:00","dateModified":"2022-08-03T12:37:58+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is Session in PHP - PHP session is used to store and pass information from one page to another page temporarily until the user closes website.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-session-in-php\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/php-session.png","width":1209,"height":727},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4568"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4568\/revisions"}],"predecessor-version":[{"id":4571,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4568\/revisions\/4571"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}