23: How to Include Documents in PHP | PHP Tutorial | Learn PHP Programming | PHP for Beginners

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024
  • How to Include Documents in PHP | PHP Tutorial | Learn PHP Programming | PHP for Beginners. Include is used in PHP to attach or insert other files in a file. This is especially helpful when we want to split apart sections of a website page to make it easier to make changes.
    ➤ GET ACCESS TO MY LESSON MATERIAL HERE!
    First of all, thank you for all the support you have given me!
    I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
    I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.
    I hope you will find it helpful :)
    Material for this lesson: / lesson-material-42361704

Комментарии • 87

  • @Yahwehehehe
    @Yahwehehehe 7 лет назад +63

    include_once prevents a same named file to be called twice which can cause errors. let's say you include "library.php" and include "start.php" but in "start.php" the "library.php" has already been included. then you called "library.php" twice which cause errors.

    • @slapmyfunkybass
      @slapmyfunkybass 6 лет назад +5

      Dewald Kunz It’s mainly used for functions. Declaring the same function will cause an error. If one php page has functions and another php page links to that page, by including both pages it will error as to php it looks like two functions has been created using the same name.

    • @arattactician5697
      @arattactician5697 2 года назад +1

      Definitely a thing to keep in mind for the future, thanks for sharing!

  • @jahoopyjaheepu497
    @jahoopyjaheepu497 6 лет назад +14

    Very high quality tutorials on this channel. Microphone that is loud enough and clear, good editing and all of the information is presented accurately and concisely. I also appreciate how you don't leave out any details.

  • @ComputerHelpHawaii
    @ComputerHelpHawaii 4 года назад +3

    I've developed my own website system using the very idea of function pages and includes you're discussing here. I'm still picking up new things and reminders from your tutorials. You're a good teacher as well as programmer.

  • @smartshopuk4234
    @smartshopuk4234 4 года назад +1

    Thank you! AGAIN
    I was looking for this video about a month ago as I started to make a website and it had over 10 pages and I was getting really bored changing all the pages Header and footer and now I can change it all in one place... Sooo Happy! :D

  • @annehauber8962
    @annehauber8962 6 лет назад +5

    Learning php through your videos. Thank you for this great content!

  • @TV-vu9fg
    @TV-vu9fg 5 лет назад +1

    I got confused yesterday but today I met the problem and it solved my problem!!!!Thank you!!

  • @roserose6621
    @roserose6621 6 лет назад +3

    Most thankful for this great n selfless content....you are the best...i have enjoyed my php lessons from u.

  • @cobymckinney489
    @cobymckinney489 6 лет назад

    Used to hate PHP, I thought it was pointless but now after following these videos I see PHP is really useful

  • @andrewericson781
    @andrewericson781 5 лет назад +1

    So this allows anything in the file referenced to have relevance in the current file? Like I could store a random function or variable in a different file and as long as it is in the included file I can just call it and it will work fine?

  • @movine2344
    @movine2344 6 лет назад +12

    omg your tutorial getting more harder i will never give up im the next President Of Wakanda

    • @tsanari
      @tsanari 5 лет назад +3

      include "presidency.php"

    • @beidouuser8017
      @beidouuser8017 4 года назад

      black panther be like hosting web servers smh

  • @AxeStudios
    @AxeStudios 6 лет назад +4

    This is awesome thank you so much, such a time saver!

  • @alexplaysthekeyboard
    @alexplaysthekeyboard 2 года назад

    quick question when i've linked my header to my index page comes up fine however i can add other stuff but i can see it i can only see it when i comment out the referenced file hope that makes sense

  • @archismansural5076
    @archismansural5076 5 лет назад +3

    Can we use include for the footer or say the sidebar and stuff. I've already done the header. Please reply. And thanks for the tutorial.

    • @alinasir3579
      @alinasir3579 4 года назад

      yes absolutely you can use it even for footers and sidebars.

  • @arattactician5697
    @arattactician5697 2 года назад +1

    I have a question: Is there a way to link CSS files to separated php/html files which are then included in the main php/html files? I hope that makes sense.
    To clarify, I tried the following:
    Files:
    - index.php (my main file where all the other php files are included)
    - header.php (included above 'main' element)
    - footer.php (included below 'main' element)
    - header_style.css (Style code for header.php)
    When I would link header_style.css to header.php and then include header.php in index.php, it would add all the content of the 'head' element (including the css link) from header.php into the middle of the 'body' element of the index.php file, which is a bad practice. Is the only good way of adding that css file to link it in the 'head' element of index.php? I think it would be more logical and readable if you could link css to those separated php/html files which would then bring that css to the main file without cluttering it's 'head' with relatively irrelevant content.
    PS: Incase this doesn't get answered in weeks, months or years and you know the answer, please write it out. It might not help me anymore but it could help people with similar problems in the future.

  • @Vimantha
    @Vimantha 3 года назад

    My navigation bar is in html page and home page is php page. Once I connect html nav bar file to home.php page, Navigation bar links are not work. When I click the navbar items it opens php code not the web page(php). Any fix?

  • @nasimullabib4435
    @nasimullabib4435 7 лет назад

    Thanks dude I really appreciate ur vidoe I will go to be a great RUclipsr one day please don't stop making vidoe man i love them

  • @halbest0425nl
    @halbest0425nl 6 лет назад +1

    for security to my username and password i want to put my include folder outside of the public_htm or www or htdoc folder, so is it possible to call my file by include or require?

  • @realdragon
    @realdragon Год назад

    Is it possible to change included file? I want to highlight in navigation bar where you are with different background color

  • @nasimullabib4435
    @nasimullabib4435 7 лет назад

    U teach me so much about coding

  • @westfield90
    @westfield90 6 лет назад +1

    My navigation has a highlight on the selected item (or current page) so how can you use one piece of navigation code if each page navigation item is highlighted?

  • @AmitKumar-fb6yt
    @AmitKumar-fb6yt 4 года назад +2

    Sir..it showing permission denied error....when I use include function...in the Apache server..pls. help me out..🤒

    • @ComputerHelpHawaii
      @ComputerHelpHawaii 4 года назад

      You might be using a full path. Use a virtual path instead include '../mypage.php';
      Also in case your trying it include won't work across domains

  • @prasantamedhi
    @prasantamedhi 3 года назад

    i want to use a variable which is inside an If statement.. in another php file.. how can i use it.. ?

  • @sasonbraha4599
    @sasonbraha4599 7 лет назад +2

    Great video! very useful

  • @ntigirishari
    @ntigirishari 4 года назад

    Thank you so much! You just saved me for my Lab! :-)

  • @isabellandlovu6297
    @isabellandlovu6297 3 года назад

    Thank you, this video helped me.

  • @fatimaf1162
    @fatimaf1162 4 года назад

    and we don't close the tags ?? like the body close tag and html close tag in header.php

  • @mandy1339
    @mandy1339 Год назад

    Thank you

  • @pashu16af
    @pashu16af 5 лет назад +3

    Can I include html file this way? For instance "header.html"

  • @photon2724
    @photon2724 5 лет назад +3

    php does a lot of stuff javascript does. Does this mean we could use php as a javascript alternative? php can do everything javascript can AND server side programming, why would we ever need javascript?

    • @zeemanmemon5329
      @zeemanmemon5329 5 лет назад

      wondering this too.

    • @cankarka8823
      @cankarka8823 5 лет назад +2

      No, PHP can't do stuff javascript can because PHP is only running on the actual server and not on the client.

  • @dannyj7262
    @dannyj7262 4 года назад

    Can this method be used if your nav has an active class fiori the current page? My nav bar is coloured to show which page is usually shown, but I've done this by putting class="active" on the current page.

  • @obaidkhan7829
    @obaidkhan7829 6 лет назад +1

    The CSS properties are not working when we shift the code to other file and then include in main..

    • @TV-vu9fg
      @TV-vu9fg 5 лет назад

      yeah,I meet the same problem

  • @elel928
    @elel928 4 года назад

    Great header trick.

  • @priemaster3058
    @priemaster3058 2 года назад

    I see my mistake ^^
    I see only the vod of you because they short and full of information. (better then the **** in germany)
    the vod is 7 years old and have all the information that i need

  • @tsanari
    @tsanari 5 лет назад +2

    Can you also include a HTML document?

  • @phtskllz
    @phtskllz 7 лет назад

    thnx man!! I'm actually learning basic php now!! great vid's!!

  • @shifatsolaiman750
    @shifatsolaiman750 5 лет назад

    why I get same content without including header.php....is it a problem with my code?

  • @EyeTyrant
    @EyeTyrant 5 лет назад +1

    So opening tags, like html, and body can be in a separate document as long as it is included?

  • @nasimullabib4435
    @nasimullabib4435 7 лет назад

    Dude I love u videos man I love them so much

  • @AmiDrutman
    @AmiDrutman 4 года назад

    Sublime! Thanks!!!

  • @DebkantiDas
    @DebkantiDas 6 лет назад +1

    you are the best

  • @thefaulenzer677
    @thefaulenzer677 2 года назад

    Is it possible to link a php file such as a css or js file in the head? Because i can’t open the index file if its a .php!

    • @Dani_Krossing
      @Dani_Krossing  2 года назад

      If it doesn't work, I think you might have the wrong website open, or you forgot to turn on your Apache and MySQL servers. Make sure you open your website by typing "localhost" into your browser, while having the servers running. 🙂
      What you are trying to do by linking files in the head, isn't really how PHP works. It isn't like CSS or JavaScript.

  • @turboromy
    @turboromy 8 лет назад

    I am the first one to say "Thank you".

  • @glebbsif
    @glebbsif 5 лет назад

    Nice explanation!

  • @llBestBoyll
    @llBestBoyll 2 года назад

    nice 👏🏼

  • @satheshkumar4317
    @satheshkumar4317 7 лет назад

    effective thank u so much

  • @priyaagrawal6197
    @priyaagrawal6197 7 лет назад

    i am getting error while calling function....even try to call using require

  • @SimicMateja
    @SimicMateja 7 лет назад

    Great video.

  • @bloodyfluff3436
    @bloodyfluff3436 3 года назад

    can we put in a html file inside PHP code?

  • @samsar7
    @samsar7 5 лет назад

    hello sir your videos are really very helpful , but i couldn't find a video to learn "how to store any language in readable format in database (phpmyadmin) php7 ? please help me to find if there is a video of you or someone else. or please make a video and share the link here sir . thank you .

  • @TV-vu9fg
    @TV-vu9fg 5 лет назад

    At the same time,the css properties don't work.How to solve that?

  • @adriandinca5682
    @adriandinca5682 7 лет назад

    Why using the adds a margin-top and margin bottom ? Can I style it with css or something? How do I remove it ?

    • @SimicMateja
      @SimicMateja 7 лет назад

      That's probably because your example.php file is not connected to CSS?

    • @adriandinca5682
      @adriandinca5682 7 лет назад

      I forgot to comment back. it was visual studio's encoding. You can simply fix it by saving it as utf8 without encoding.
      fix: Save as -> click on the downfacing arrow right next to the save button -> choose utf8 without encoding

  • @khmertechtips9039
    @khmertechtips9039 6 лет назад

    It's great

  • @TheHockeyHawk
    @TheHockeyHawk 3 года назад

    The problem I have with this video is that he copies the entire tag down to the close tag.
    Wouldn't it have been better if he created 3 different HTML docs for the and tags?

  • @pagenteronoeljensen3754
    @pagenteronoeljensen3754 3 года назад

    yessiirrr

  • @sandarabian
    @sandarabian 7 лет назад

    what would be the point of including php with functions in your html? I thought only javascript can interact with the DOM?

    • @Dani_Krossing
      @Dani_Krossing  7 лет назад +3

      You are right about JavaScript being used to change the DOM, however we are not using PHP to change our DOM in this course. Functions doesn't only exist in JavaScript, they exists in all manor of programming languages, and when it comes to PHP we use them to perform back-end function.

  • @ojehagbaje6371
    @ojehagbaje6371 Год назад

    Which text editor do you use please?

    • @Dani_Krossing
      @Dani_Krossing  Год назад

      Nowadays I use VSCode. 🙂 Btw this is a older course that you are watching. I have a brand new 2023 PHP course on my channel, which is much better.

  • @mek059
    @mek059 6 лет назад +2

    what with require instead of include?

    • @mek059
      @mek059 6 лет назад

      there are include, require, include once and require once and maybe more but I've no idea about them
      I didn't understand the differences

    • @dondada1507
      @dondada1507 6 лет назад +5

      When you say include "file.php" If that file was not found, the page will give error and work without it.
      However, when you say require "file.php" and if that file wasn't found the page wont work at all. Try it out.

  • @alirasoli5101
    @alirasoli5101 7 лет назад

    great

  • @Lonsey2
    @Lonsey2 3 года назад

    Hey Dani, i have question regarding the include tag.
    I've been coding for a while within Visual Studio Code (still on a beginners level). Currently im using the very basics; html, css, javascript to build different projects that i have.
    Recently i've setup XAMPP and MySQL works like charm.
    Now to my question; Just like you would do with html and css, you wanna keep the files separated for a more clean workspace in different documents to then implentent a " connection from html to css. During your tutorials which are great btw, the only thing i haven't figured out yet is HOW do i connect a ".php" file to my main html document? Cause currently if im trying to run the include tag in my html document or infact any kind of php coding inside the ".html"file, it simply doesn't find it, infact VS Code just sends out errors "like wrong coding language, can't define function" etc etc.
    I don't know if i've explained this correctly, it might be that i just have missed a crucial point somewhere, anyway a answer to this would be golden :)!
    Cheers

  • @Alan-ky6iu
    @Alan-ky6iu 6 лет назад

    What is the name of your color scheme ?

  • @muramasa7537
    @muramasa7537 5 лет назад

    So include is like a link

  • @user-or2uc2xo7w
    @user-or2uc2xo7w Год назад

    WHY YOU DON'T GIVE EXAMPLE MY FRIEND .? I WANT TO SEE HOW WORKS IT.

    • @Dani_Krossing
      @Dani_Krossing  Год назад +1

      There is nothing to really “demonstrate” in this video. It’s pretty much as is. But the future videos will give more examples. 🙂

  • @gevorgmartirosyan8189
    @gevorgmartirosyan8189 2 года назад

    why to make so hard example

  • @mstream2395
    @mstream2395 2 года назад

    🥰🥰😎😎👏👏👏👏👏👏👏👏👏👏👏

  • @user-jv5by8rd6d
    @user-jv5by8rd6d 2 года назад

    Stop here

  • @kilak9193
    @kilak9193 6 лет назад +1

    Thanks for using "dash" instead of "hyphen"! I hate that word.