{"id":77993,"date":"2022-09-26T01:16:57","date_gmt":"2022-09-26T01:16:57","guid":{"rendered":"https:\/\/itsourcecode.com\/?p=77993"},"modified":"2023-10-27T08:39:54","modified_gmt":"2023-10-27T08:39:54","slug":"php-session-function-start-and-destroy","status":"publish","type":"post","link":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/","title":{"rendered":"PHP Session Function (Start and Destroy)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-what-is-a-session-in-php\"><strong>What is a Session in PHP?<\/strong><\/h2>\n\n\n\n<p><strong>PHP Sessions<\/strong> is a way to keep information from one web page to the next so that users can be recognized as they move around a site or app.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p style=\"font-size:26px\"><strong>Do you want to know why a website needs sessions?<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>To understand why sessions are important, we need to look at how the <strong>HTTP protocol<\/strong> is set up.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The <strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP protocol<\/a><\/strong> is stateless, which means that a server can&#8217;t remember a specific user between requests. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>For instance, when you visit a website, the server&#8217;s only job is to give you the information you asked for.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>So, when you go to other pages on the same website, the web server handles each request as if it had nothing to do with the others. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The server has no way of knowing that each request comes from the same user.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Look at the illustration below:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/Session-In-PHP.png\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"801\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/Session-In-PHP.png\" alt=\"Session In PHP\" class=\"wp-image-78006\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/Session-In-PHP.png 975w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/Session-In-PHP-300x246.png 300w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/Session-In-PHP-768x631.png 768w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/a><\/figure><\/div>\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-do-you-start-a-php-session\"><strong>How do you start a PHP Session?<\/strong><\/h2>\n\n\n\n<p class=\"tw-highlight-padding\">A session started with the <code><mark style=\"background-color:var(--base-3);color:#fb0101\" class=\"has-inline-color\">session_start()<\/mark><\/code> function.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">Session variables are set with the <strong>Hypertext Preprocessor<\/strong> global variable <code><mark style=\"background-color:var(--base-3);color:#fd0202\" class=\"has-inline-color\">$_SESSION<\/mark><\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Now, let&#8217;s create a program with the file name &#8220;<strong>test_session1.php<\/strong>&#8221; to start a new session and set some session variables:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ Start the session\nsession_start();\n?&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n\n&lt;?php\n\/\/ Set session variables\n$_SESSION&#91;\"name\"] = \"Angel Jude Suarez\";\n$_SESSION&#91;\"position\"] = \"Programmer\";\necho \"Session variables are set.\";\n?&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-base-3-color has-contrast-background-color has-text-color has-background\">Note: The <code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fb0101\" class=\"has-inline-color\">session_start()<\/mark><\/code> must be placed in the first part of the code of your php file before any HTML tags.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-get-the-values-of-php-session-variables\"><strong>GET the values of PHP Session variables<\/strong><\/h2>\n\n\n\n<p>Next, we will create another page with the file name &#8220;<strong>test_session2.php<\/strong>&#8220;. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>From this page, we will GET the values of session variables we set on the first page with the file name &#8220;<strong>test_session1.php<\/strong>&#8220;.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Notice that the session variables in <strong>Hypertext Preprocessor<\/strong> are not passed individually to each new page, instead, they are retrieved from the session we open at the beginning of each page. <code><mark style=\"background-color:var(--base-3);color:#fb0101\" class=\"has-inline-color\">session_start()<\/mark><\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Here&#8217;s the program for getting the values of session variables set on the first-page name &#8220;<strong>test_session1.php<\/strong>&#8220;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nsession_start();\n?&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n\n&lt;?php\n\/\/ Echo session variables that were set on previous page\necho \"Name is: \" . $_SESSION&#91;\"name\"] . \".&lt;br&gt;\";\necho \"Position is: \" . $_SESSION&#91;\"position\"] . \".\";\n?&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>When you execute the program this will be the output:<\/p>\n\n\n\n<p class=\"has-base-3-color has-contrast-background-color has-text-color has-background\">Name is: Angel Jude Suarez<br>Position is: Programmer<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-destroy-a-php-session\"><strong>Destroy a PHP Session<\/strong><\/h2>\n\n\n\n<p class=\"tw-highlight-padding\">To remove all global session variables and destroy the session, we will use the <code><mark style=\"background-color:var(--base-3);color:#f80101\" class=\"has-inline-color\">session_unset()<\/mark><\/code> and <code><mark style=\"background-color:var(--base-3);color:#f80404\" class=\"has-inline-color\">session_destroy()<\/mark><\/code> functions.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Here&#8217;s the program for destroying global session variables:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nsession_start();\n?&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n\n&lt;?php\n\/\/ remove all session variables\nsession_unset();\n\n\/\/ destroy the session\nsession_destroy();\n?&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-frequently-asked-questions-faqs\"><strong>Frequently Asked Questions (FAQs)<\/strong><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1664080109606\"><strong class=\"schema-faq-question\"><strong>What is PHP<\/strong> (<strong>Hypertext Preprocessor<\/strong>)<strong> Session and how does it work?<\/strong><\/strong> <p class=\"schema-faq-answer\">PHP responds by sending a unique token that identifies the current session. <br\/><br\/>This is known as the session ID. In all subsequent requests, the browser sends the session ID to say, &#8220;<strong>Hello IT Source Coders.<\/strong>&#8221; <br\/><br\/>All other data related to the session is stored on the web server. Only the session ID gets passed back and forth.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1664080187864\"><strong class=\"schema-faq-question\">How do you start a PHP Session?<\/strong> <p class=\"schema-faq-answer\">A session started with the <code><mark style=\"background-color:var(--base-3);color:#fb0101\" class=\"has-inline-color\">session_start()<\/mark><\/code> function.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1664080229098\"><strong class=\"schema-faq-question\">When should I start a Session <strong>Hypertext Preprocessor<\/strong>?<\/strong> <p class=\"schema-faq-answer\">Before you can store any information in session variables. The <code><mark><code><mark style=\"background-color:var(--base-3);color:#fb0101\" class=\"has-inline-color\">session_start()<\/mark><\/code><\/mark><\/code> must be placed in the first part of the code of your php file before any HTML tag.<\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-related-articles\"><strong>Related Articles<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-chmod-dir-function-with-examples\/\">PHP Chmod Dir Function With Examples<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/session-name-php-with-code-example\/\">Session Name PHP With Code Example<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-read-file-line-by-line-with-example\/\">PHP Read File Line By Line With Example<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/session-timer-php-with-detailed-explanation\/\">Session Timer PHP With Detailed Explanation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-remove-element-from-array-with-examples\/\">PHP Remove Element From Array With Examples<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p class=\"tw-highlight-padding\">We have completely discussed the Session functions from <strong><code><mark style=\"background-color:var(--base-3);color:#f40606\" class=\"has-inline-color\">session_start()<\/mark><\/code><\/strong> and <code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f40505\" class=\"has-inline-color\"><strong>session_destroy()<\/strong><\/mark><\/code>. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">In this tutorial, we have learned the function of Session with the help of examples. I hope this simple <a href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-tutorial-for-beginners-easy-learning-in-php\/\">PHP Tutorial<\/a> will help you a lot.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>By the way, if you have any questions or suggestions about this article entitled &#8220;<strong>Session in PHP<\/strong>&#8220;. Please feel free to comment below. Thank You!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is a Session in PHP? PHP Sessions is a way to keep information from one web page to the next so that users can be recognized as they move &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"PHP Session Function (Start and Destroy)\" class=\"read-more button\" href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#more-77993\" aria-label=\"Read more about PHP Session Function (Start and Destroy)\">Read more<\/a><\/p>\n","protected":false},"author":1767,"featured_media":77281,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61035],"tags":[95265,95262,95263,95264],"class_list":["post-77993","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-tutorial","tag-how-do-you-start-a-php-session","tag-php-session","tag-session-in-php","tag-what-is-session-in-php","resize-featured-image"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>PHP Session Function (Start and Destroy) - Itsourcecode.com<\/title>\n<meta name=\"description\" content=\"A PHP Session is a way to keep information from one web page to the next so that users can be recognized as they move around a site or app.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Session Function (Start and Destroy)\" \/>\n<meta property=\"og:description\" content=\"A PHP Session is a way to keep information from one web page to the next so that users can be recognized as they move around a site or app.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/\" \/>\n<meta property=\"og:site_name\" content=\"Itsourcecode.com\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-26T01:16:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-27T08:39:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-session.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1460\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"angel jude suarez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"angel jude suarez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/\"},\"author\":{\"name\":\"angel jude suarez\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/dafb6a91b43e60537c56e3e1d227d460\"},\"headline\":\"PHP Session Function (Start and Destroy)\",\"datePublished\":\"2022-09-26T01:16:57+00:00\",\"dateModified\":\"2023-10-27T08:39:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/\"},\"wordCount\":578,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/php-session.png\",\"keywords\":[\"How Do You Start A PHP Session\",\"php session\",\"session in php\",\"what is session in php\"],\"articleSection\":[\"PHP Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/\",\"name\":\"PHP Session Function (Start and Destroy) - Itsourcecode.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/php-session.png\",\"datePublished\":\"2022-09-26T01:16:57+00:00\",\"dateModified\":\"2023-10-27T08:39:54+00:00\",\"description\":\"A PHP Session is a way to keep information from one web page to the next so that users can be recognized as they move around a site or app.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080109606\"},{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080187864\"},{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080229098\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#primaryimage\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/php-session.png\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/php-session.png\",\"width\":1460,\"height\":900,\"caption\":\"php session\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/itsourcecode.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Session Function (Start and Destroy)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/\",\"name\":\"Itsourcecode.com\",\"description\":\"Partner In Your Coding Journey!\",\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/itsourcecode.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\",\"name\":\"itsourcecode\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"width\":409,\"height\":409,\"caption\":\"itsourcecode\"},\"logo\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\"},\"description\":\"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!\",\"sameAs\":[\"https:\\\/\\\/itsourcecode.com\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/dafb6a91b43e60537c56e3e1d227d460\",\"name\":\"angel jude suarez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"caption\":\"angel jude suarez\"},\"description\":\"Hello programmers, I'm Angel Jude Reyes Suarez, a student and a programmer of different programming languages like Python, Java, JavaScript, PHP, C, C++, Vb.net, and MySQL. and I have also knowledge in developing system or websites from Front-End to Back-End. and also a writer of itsourcecode.com.\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/author\\\/angeljudesuarez\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080109606\",\"position\":1,\"url\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080109606\",\"name\":\"What is PHP (Hypertext Preprocessor) Session and how does it work?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"PHP responds by sending a unique token that identifies the current session. <br\\\/><br\\\/>This is known as the session ID. In all subsequent requests, the browser sends the session ID to say, \\\"<strong>Hello IT Source Coders.<\\\/strong>\\\" <br\\\/><br\\\/>All other data related to the session is stored on the web server. Only the session ID gets passed back and forth.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080187864\",\"position\":2,\"url\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080187864\",\"name\":\"How do you start a PHP Session?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"A session started with the session_start() function.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080229098\",\"position\":3,\"url\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-session-function-start-and-destroy\\\/#faq-question-1664080229098\",\"name\":\"When should I start a Session Hypertext Preprocessor?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Before you can store any information in session variables. The session_start() must be placed in the first part of the code of your php file before any HTML tag.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PHP Session Function (Start and Destroy) - Itsourcecode.com","description":"A PHP Session is a way to keep information from one web page to the next so that users can be recognized as they move around a site or app.","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:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/","og_locale":"en_US","og_type":"article","og_title":"PHP Session Function (Start and Destroy)","og_description":"A PHP Session is a way to keep information from one web page to the next so that users can be recognized as they move around a site or app.","og_url":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/","og_site_name":"Itsourcecode.com","article_published_time":"2022-09-26T01:16:57+00:00","article_modified_time":"2023-10-27T08:39:54+00:00","og_image":[{"width":1460,"height":900,"url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-session.png","type":"image\/png"}],"author":"angel jude suarez","twitter_card":"summary_large_image","twitter_misc":{"Written by":"angel jude suarez","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#article","isPartOf":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/"},"author":{"name":"angel jude suarez","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/dafb6a91b43e60537c56e3e1d227d460"},"headline":"PHP Session Function (Start and Destroy)","datePublished":"2022-09-26T01:16:57+00:00","dateModified":"2023-10-27T08:39:54+00:00","mainEntityOfPage":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/"},"wordCount":578,"commentCount":0,"publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"image":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-session.png","keywords":["How Do You Start A PHP Session","php session","session in php","what is session in php"],"articleSection":["PHP Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/","url":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/","name":"PHP Session Function (Start and Destroy) - Itsourcecode.com","isPartOf":{"@id":"https:\/\/itsourcecode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#primaryimage"},"image":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-session.png","datePublished":"2022-09-26T01:16:57+00:00","dateModified":"2023-10-27T08:39:54+00:00","description":"A PHP Session is a way to keep information from one web page to the next so that users can be recognized as they move around a site or app.","breadcrumb":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080109606"},{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080187864"},{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080229098"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#primaryimage","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-session.png","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-session.png","width":1460,"height":900,"caption":"php session"},{"@type":"BreadcrumbList","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/itsourcecode.com\/"},{"@type":"ListItem","position":2,"name":"PHP Session Function (Start and Destroy)"}]},{"@type":"WebSite","@id":"https:\/\/itsourcecode.com\/#website","url":"https:\/\/itsourcecode.com\/","name":"Itsourcecode.com","description":"Partner In Your Coding Journey!","publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itsourcecode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc","name":"itsourcecode","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","width":409,"height":409,"caption":"itsourcecode"},"logo":{"@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg"},"description":"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!","sameAs":["https:\/\/itsourcecode.com\/"]},{"@type":"Person","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/dafb6a91b43e60537c56e3e1d227d460","name":"angel jude suarez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","url":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","caption":"angel jude suarez"},"description":"Hello programmers, I'm Angel Jude Reyes Suarez, a student and a programmer of different programming languages like Python, Java, JavaScript, PHP, C, C++, Vb.net, and MySQL. and I have also knowledge in developing system or websites from Front-End to Back-End. and also a writer of itsourcecode.com.","url":"https:\/\/itsourcecode.com\/author\/angeljudesuarez\/"},{"@type":"Question","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080109606","position":1,"url":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080109606","name":"What is PHP (Hypertext Preprocessor) Session and how does it work?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"PHP responds by sending a unique token that identifies the current session. <br\/><br\/>This is known as the session ID. In all subsequent requests, the browser sends the session ID to say, \"<strong>Hello IT Source Coders.<\/strong>\" <br\/><br\/>All other data related to the session is stored on the web server. Only the session ID gets passed back and forth.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080187864","position":2,"url":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080187864","name":"How do you start a PHP Session?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"A session started with the session_start() function.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080229098","position":3,"url":"https:\/\/itsourcecode.com\/php-tutorial\/php-session-function-start-and-destroy\/#faq-question-1664080229098","name":"When should I start a Session Hypertext Preprocessor?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Before you can store any information in session variables. The session_start() must be placed in the first part of the code of your php file before any HTML tag.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/77993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/users\/1767"}],"replies":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/comments?post=77993"}],"version-history":[{"count":28,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/77993\/revisions"}],"predecessor-version":[{"id":119483,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/77993\/revisions\/119483"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media\/77281"}],"wp:attachment":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media?parent=77993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/categories?post=77993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/tags?post=77993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}