{"id":16188,"date":"2020-07-17T09:15:36","date_gmt":"2020-07-17T09:15:36","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=16188"},"modified":"2022-04-13T15:58:37","modified_gmt":"2022-04-13T15:58:37","slug":"php-7-intermediate-essential-guide-php-include_once-require_once","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/php-7-intermediate-essential-guide-php-include_once-require_once\/","title":{"rendered":"PHP 7 Intermediate Essential Guide- PHP include_once &#038; require_once"},"content":{"rendered":"\n<p>In this blog, I am going to Explain How to <strong>include_once<\/strong> &amp; <strong>require_once<\/strong> in PHP. So within PHP, It&#8217;s actually possible to include PHP people files within other PHP files. It means when you use <strong>include_once<\/strong> &amp; <strong>require_once<\/strong> more than one in any PHP file and you calling script it will be shown or print only one time if found more than once then it will be ignored.<\/p>\n\n\n\n<p>So I&#8217;ve created a few other PHP files. And typically we&#8217;re going to use this for header footer and different files. So as you can see here within the header I&#8217;ve got what&#8217;s called page header and I&#8217;ve actually included some code in here as well. <\/p>\n\n\n\n<p>And the same thing for the footer so got the page footer so let&#8217;s just writing that code into &#8220;<strong>footer.php<\/strong>&#8220;. And I&#8217;m also including some I should call the void then. And setting a variable called footer with this is the footer.<\/p>\n\n\n\n<p>So now I can go over to my main index page and if I had an <strong>&#8220;header.php&#8221; <\/strong>set up so I&#8217;ve got my header here and title and then I&#8217;ve got my body. And in this body, I always wanted to have a header. And I want to have a footer so these are just going to be content headers and footers. Normally I know what you&#8217;re probably thinking well why wouldn&#8217;t I put this into the header and this in the footer so he can do that as well.<br><\/p>\n\n\n\n<p>First and then I&#8217;m also going to call out that variable that&#8217;s being set up within <strong>PHP.<\/strong> So we&#8217;ll just see what our output is and we can see that we get that initial content and then we get the value of head. <br>There are also some additional ones where you could include it once. So if we had something like require or include and again to work almost identically. <\/p>\n\n\n\n<p>So that&#8217;s the difference between required once and require. And the same thing for include and include once. So they&#8217;re going to work relatively the same way. Including the requires.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/78edb2308b651e951c9ea85ba97238a0.js\"><\/script>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/fa3da3ed89f9697f5df4d56da8c14019.js\"><\/script>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"154\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/header-footer.png\" alt=\"\" class=\"wp-image-16392\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/header-footer.png 693w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/header-footer-300x67.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/c3f4349da7872a72fcbadb4bfcf93f69.js\"><\/script>\n\n\n\n<h3 class=\"wp-block-heading\">Output-<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"260\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/include-require_once.png\" alt=\"\" class=\"wp-image-16393\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/include-require_once.png 660w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/include-require_once-300x118.png 300w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_92621\"><iframe loading=\"lazy\"  id=\"_ytid_31555\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_92621\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>In this blog, I am going to Explain How to include_once &amp; require_once in PHP. So within PHP, It&#8217;s actually possible to include PHP people files within other PHP files&#8230;. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5150],"tags":[],"class_list":["post-16188","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=16188"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16188\/revisions"}],"predecessor-version":[{"id":24660,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16188\/revisions\/24660"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=16188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=16188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=16188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}