Basic PHP Tutorial 16: Include and Require
Key Takeaways
Demonstrates how to use PHP's include and require functions
Full Transcript
hello and welcome to the 16th basic higher python i knew i was going to do that basic php tutorial uh in this tutorial uh we're gonna be discussing the include and require um commands and basically what they're gonna do is they pretty much do the same thing but if they can't do it that's where they defer so the include is going to call for a file to be included if it can't be included everything will still run require on the other hand will require that uh file whatever to be included so to speak and if not then it will it will cease to run so um but the actual command to do it is the same and so in this sense what we're going to do is i've already got this header.php file it says header two but it's actually header not quite sure why it's doing maybe because i have another header file or something in this temp folder but regardless it is corresponding to the header.php so for header.php we're just going to do h1 and this is the website title and uh in fact instead of this is the website title let's call this um php or welcome to my php tutorials okay that'll be our header we'll save that and we'll upload that to the server so if we pop over to um if we pop to this uh we see this is the page this is what's included with header it's just you know h1 with header one tags and we want that on this page so the way that we do that is we'll pop over here and you just say include header.php now if uh input it in quotes if it is located in the same directory then you put it there otherwise you know you start using these um oops it'll go within here like that if it's in like one prior directory if it's in another prior directory we'll do that and so on but for now it's actually in the um the same directory so we'll just leave that there and now we're going to say we're just going to echo out some regular text hello regular text and we'll save this and we'll run this and when we refresh um oh we forgot our semicolon of course now you see that we've included the rules for our really a header file and so the reason you'd want to do this is over time if you have a website or if you've ever visited a website in your life you probably notice that the top of the website is about the same no matter what page you go to now if this was hard coded um as in like typed out every page like say um this website wanted to have like a little bit of a facelift and use a new banner or something like that they would have to like go through by hand and change every single um pages header and that would be like really tedious so instead what you do is you just have include header.php at the top of the script and what it'll do is we'll just include whatever the header is so if you wanted to say um you know what i like php that's cool and tutorials what if uh what if we wanted to do like we were like well dang you know now we're we're like strictly like php video tutorials right like you're like dang that's like a way better way to describe our site so so we'll do uh welcome to my php video tutorials and say you have if you had you know 50 pages you don't have to edit this page at all you just edit the header page and so when you save that header page um we'll come back over here and now it's video tutorials and so if you had like 50 different pages you would be able to do this like really really quick instead of having to go through and edit them and just as a quick aside since it is here we can say require header.php and we'll upload that and refresh and you know it's still there so it's still working so it doesn't really matter which one you use if it's there but if you don't want the page to break if it can't get that file then you just say include so like if you were including a php page or a script that had like an integral function to the entire page and you couldn't seem to get that you would want to use that like require if it's integral to the page working you would want to use a require that way you're not going to continue running through a bunch of code when you don't have the information you really need right and you would want to have some sort of error code or something like that and then with this another thing you can do is see say like we did this what if we did two includes so we include the header file twice what happens then well if this would upload hold up so we pop over here we run it and as you can see you know it's included it and used it twice um now we can get rid of that one um so now uh the heck was i going to show you all right right what you can use is these two there's another a variation of these in functions where you can say include underscore uh once and now let's save it replay and now you see even though um we called it twice it's only been displayed once because what this include once does is it asks the question has this already been included if so never mind and as you can see it has already been included therefore it did not include this one same thing with required it could be require once like so and boy i wonder what happens if we use require ones because it hasn't been required it's been included so now what oh man the suspense it's killing me it is just killing me and it only runs once so hopefully not too many of you guys got killed by the suspense um so anyways that's the include and require functions as always thank you for watching and until next time
Original Description
Link to the full playlist:
http://www.youtube.com/playlist?list=PLQVvvaa0QuDcYpcjrNB43_iKqla5UeQw_
Sentdex.com
Facebook.com/sentdex
Twitter.com/sentdex
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 17 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
▶
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
🎓
Tutor Explanation
DeepCamp AI