Mini Course PHP , PHP
- 28/08/2008
Mini course in PHP (Part 11) - Includes
Hello all good people?
As promised, we will begin to make a simple news. With administration and all. Here is how it will be the scope of our system:
- Administration
- The login page;
- Go to Registration / Editing / removal;
- Categories of news Registration / Editing / Removal;
- Register for news / Editing / Removal;
- The visual
- List of Categories in the menu;
- Listing of news (with or without a category filter);
- Form to search for news;
- Top 10 news;
- Send news by e-mail to friend;
But remember that we still have much to learn about the PHP language. I decided to teach the rest by doing some simple systems, to make learning more dynamic and that what is learned is seen in practice.
Before we start our system, we have some very important things to learn. They are:
1. Includes;
2. MySQL basic commands;
3. Commands for working with PHP Mysql.
INCLUDE
As the name suggests, include is a command that includes the contents of another file where it is called. It's like you copied the file and colasse code where you want to use.
See how to use the include in our system of news: it can enter into our management need to be logged. However, on each page needs to be done a test to see if there is someone logged in and therefore allowed to see the page. For that we have the assurance that no one without a password to access our system. So we have an IF at the beginning of each page. The IF would be something like 'If someone is logged in, then show the page. Otherwise return to the login page '. Right? IF not to copy this and paste on every page, we will create a file that contains this and we will run the IF INCLUDE calling this file on every page of the administration. It was clear this idea?
What's the point of using the INCLUDE? Well, imagine that your administration has 20 pages. And his rule to validate if there is someone logged change. Oh you'll have to change the 20 pages containing this IF. Using INCLUDE this problem ... just because all the 20 pages that use the IF is written in the file to be included.
We use an INCLUDE as follows:
Include ("path");
The file path is the folder and file name to be included, for example: "includes / validausuario.php." To include a file that is a folder below, you will use ".." out of the folder where your file is running. For example: ".. / includes / validausuario.php." And so on ... if you want to include a file that is three levels below you use: "../../.. / includes / validausuario.php"
See this in practice. Consider the file a.php as follows:
- <?
- ; $ Variable = "I setada b.php file";
- ?>
And consider the file b.php as follows:
- <?
- "a.php" ) ; include ("a.php");
- ?>
Understanding: The file b.php is calling (with the include command) a.php the file. If we run the file b.php we get the following output:
I setada file a.php
But why? Because ALL of the contents of the file was included in the file a.php b.php.
It was clear?
IMPORTANT
If the include file does not find the requested file .. it WILL NOT GIVE ERROR ... will follow the script normally. So in many cases, instead of using the include command () is more advisable to use the command REQUIRE, because if the file is not found the script will not continue running. The PHP parser will give error.
To learn more about include or require access to the documentation on php.net: http://br2.php.net/manual/pt_BR/function.include.php
This example that was used is available in: http://www.marcelosabadini.com.br/mini-curso/include/
Because MySQL is a very long, I'll do a post specifically for him. I'll post over the weekend.
Meanwhile, read the php.net documentation because it is very important. Do some example ... even this may be that I .. And create another example for you to practice.
I hope I was clear enough. If you have any questions or realized that I did not say something important, please comment POST.
A big hug and even the next.



7 Responses to "Mini course PHP (Part 11) - Includes"
Dude, very nice tutorial!
Once I have the time to follow it step by step
Congratulations and thank you!
By Diego (15 comments) on 03/09/2008
First I want to congratulate you for this tutorial that not even started yet, but I know it'll be great with him.
I'll start from scratch because my notion of PHP is minimal!
When a little more familiar with the matter back to comment again and thanks again!
Even more!
By Ricardo Leandro (2 comments) on 06/09/2008
Marcelo speaks.
Congratulations on the initiative face, I am following your course and okay cool.
I would like to know how to put intellisense for PHP in Dreamweaver. I was using Aptana and Zend (they have intellisense), but now with Dreamweaver must type the entire command. You know how to fix it?
For Nosbielcs (3 comments) on 10/09/2008
Nosbielcs Hello, how are you?
First, thank you for stopping by my site and enjoy!
kra intellisense ... this would be the 'auto-complete' right? (According to wiki)
So, Dreamweaver has an intellisense / auto-complete very good for PHP (I do not know other languages), but he even tries. Do this, begin typing a PHP command, eg 'str_' and press CTRL + SPACE.
See that it enables Intellisense / auto-complete. I think I would be automatic q! but that's okay ... It auto-complete only the super-global ($ _GET, $ _SERVER, $ _POST, $ _COOKIE, $ _FILES, $ _REQUEST, $ _SESSION) automatically.
By Marcelo Sabadini (109 comments) on 10/09/2008
do not forget to type the command inside a PHP tag: <? ?>!
By Marcelo Sabadini (109 comments) on 10/09/2008
So Marcellus, is not exactly what I wanted. I wanted to get the Variables set understands. The CTRL + SPACE only serves to describe the end of the command. He did not arrow a variable declared in the scope of the code.
For Nosbielcs (3 comments) on 10/09/2008
Nosbielcs, eh .. q in this case really think no way.
For these and other reasons, can not stop using the Zend. I'm in love with this IDE rsrsrsrsrsr
Zend Studio S2 kkkkkkkkkkk
* I precipitators .. I saw the picture in a glance and I thought Wiki was completing functions q rsrsrsrsr
By Marcelo Sabadini (109 comments) on 10/09/2008