02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Using the PHP ini_set function

We are almost done exploring the basics of our php settings. There will be cases you will want to change the configurations on the fly. To do that we will use the ini_set function as an override to our settings.

Video Transcript

00:00We are almost done, and let me just close this up because we're done with that.
00:04The next step that I want to talk about is how could you change configurations on the fly,
00:09such as inside of a PHP file, as a certain script is running.
00:13So I want to show you how it's done. It's using a PHP function.
00:17So I'm going to go right into our server, and I'm going to go right into our file.
00:23And what I'm going to do is right before we call PHP info,
00:26I'm going to call the method INIset.
00:29And as you probably could guess, INIset, with an underscore in between the word INI and the word set,
00:36we put two strings. One is the name of the property that we want to change,
00:40and then the other one is the value you want to give into it.
00:43So we want to call the display errors,
00:47and the value we want to put back after we put a comma is we want to put the value 1
00:53or the value of on in a quote.
00:56But I like 1. It's more simple when you're running inside of PHP.
01:00And it's a Boolean value in PHP, so on or 1 are comparable.
01:07So I'm going to semicolon that because everything in PHP needs a semicolon
01:12because we want that to actually work.
01:14And what I want to do right here is I'm going to add an error into my PHP line
01:18so we could get some sort of an error back.
01:21So if I escape this and I save and exit,
01:24and I go back into my browser and click on refresh,
01:26we're going to see that this time around we are getting the error
01:29and it's telling us that we had a fatal error,
01:31a call to an undefined function, PHP info,
01:37and it even tells us the line.
01:39Obviously, this is not something we would want to have in production
01:41because it would deliver too much information
01:44and enable a hacker to know that there is a function
01:48that is called a certain name in our application
01:51or it would give more information to the hacker,
01:54which we would never want to give that type of information.
01:56But then again, if we're working, we're testing something inside
01:59of our development environment,
02:01we might want to turn it on if suddenly we see something
02:03and we could locally turn it on in a specific script
02:06as we're running it to test it in our development environment
02:09before we push it on to the live environment.
02:12Now, before we wrap up in the next lesson,
02:15I'm going to talk about how could you say that this whole site,
02:18this whole production area instead of the whole server,
02:21because if we would go inside of the INI
02:23and actually configure it to be display errors,
02:26then it would display errors to all the different sites that we have.
02:29But what if specifically we want to tell it to a specific site
02:32that we want to display the errors in that,
02:34such as maybe it's our stage site or such.
02:38So we're using the same server where we have a stage environment
02:41and a live environment, but again, it's really critical
02:44that if we do do that, the site that we're going to run
02:47must not be accessible to the web.
02:50If it is, then it's going to be silly for us to do that
02:52because even if we think it's our stage site,
02:54if someone could actually access it,
02:56they could gain the same amount of information about our site
02:59as they would if they were on our live site.
03:03So that's it.
03:04So we're going to see in the next session and next video,
03:06how do we actually configure it to the whole site
03:08or the whole site has access to that error level.
03:12See you in the next lesson.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!