Mini course in PHP (Part 11) - Includes


1 Estrelas2 Estrelas3 Estrelas4 Estrelas5 Estrelas (7 votes, average: 5.00 out of 5)
Loading ... Loading ...

Hello all good people?

As promised, we will begin to make a simple news. With administration and all. Below is the scope of how our system will:

  1. Administration
    1. The login page;
    2. User registration / Editing / removal;
    3. Registration categories of news / Editing / Removal;
    4. Register for news / Editing / Removal;
  2. Visual part
    1. List of Categories on the menu;
    2. List of news (with or without a category filter);
    3. Form research news;
    4. Top 10 news;
    5. Send news by e-mail to friend;

But remember that we still have many things to learn about the PHP language. Decided to teach the rest by doing some simple systems, so that learning is 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. Basic Commands Mysql;

3. Commands for working with PHP Mysql.

INCLUDE

As its name suggests, is to include a command that includes the contents of another file where it is called. It's like you copied the code from the file and sticks where you want to use.
See how we use the include in our system of news: In order to join our administration needs to be done login. However, each page needs to be tested to see if there is someone logged and therefore allowed to see the page. Because we have the assurance that no one without a password to access our system. Then we would have an IF at the beginning of each page. The IF would be something like 'If someone has logged in, then show the page. Otherwise return to the login page. " Right? IF not to copy and paste this on ALL pages, we will create a file that contains this and IF we run INCLUDE calling this file on each page of the administration. It became clear this idea?

What is the point of using the INCLUDE? Well, imagine that your administration has 20 pages. And his rule to establish whether 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 that will be included.

We use an INCLUDE the following:

Include ("path");

The file path is the folder and filename that will be included, for example: "includes / validausuario.php. To include a file that is a folder below, you will use ".." to exit 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"

Check this out in practice. Consider the file a.php as follows:

  1. <?
  2. ; $ Variable = "I setada b.php file";
  3. ?>

And consider the file b.php as follows:

  1. <?
  2. "a.php" ) ; include ("a.php");
  3. ; echo $ variable;
  4. ?>

Understanding: The file b.php is calling (with the include command) a.php file. If we run the file b.php we have the following output:

I was in the file setada a.php

But why? Because ALL the contents of the file was included in a.php b.php.

It was clear?

IMPORTANT

If the include file does not find the requested file .. it WILL NOT GIVE ERROR ... the script will proceed as normal. 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 does not continue running. The PHP parser will give error.

To learn more about include or require access to 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/

How Mysql is a very extensive, I will post specific to it. I'll post over the weekend.

Meanwhile, read the documentation from php.net as it is very important. Make some example ... this may even 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 on the POST.

A big hug and until next time.

  1. 7 Comments to "Mini Course PHP (Part 11) - Includes"

  2. Dude, very nice tutorial!
    Once you have the time I follow it step by step
    Congratulations and thank you!

    Reply Reply

    By Diego (15 comments) on 03/09/2008

  3. First I want to say congratulations 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 you're a bit more familiar with the matter back to comment again and thanks again!
    Goodbye!

    Reply Reply

    By Ricardo Leandro (2 comments) on 06/09/2008

  4. Marcelo speech.
    Congratulations on the initiative face, I am following your progress and okay cool.
    I wonder how I put intellisense for PHP in Dreamweaver. Was using Aptana and Zend (they have intellisense), but now with Dreamweaver must enter the entire command. You know how I fix this?

    Reply Reply

    By Nosbielcs (3 comments) on 10/09/2008

  5. Nosbielcs Hello, how are you?

    First, thanks for stopping by my site and enjoy!

    kra intellisense ... this would be the 'auto-complete' right? (According to wiki)

    Then, Dreamweaver does not have an intellisense / auto-complete very good for PHP (I do not know other languages), but he even tries. Do the following, start typing a command PHP, for example 'str_' and press CTRL + SPACE.

    See 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.

    Reply Reply

    By Marcelo Sabadini (101 comments) on 10/09/2008

  6. do not forget to enter the command inside a PHP tag <? ?>!

    Reply Reply

    By Marcelo Sabadini (101 comments) on 10/09/2008

  7. So Marcellus, not quite what I wanted. I wanted to get the Variables set definitions. The CTRL + SPACE only serves to describe the end of the command. He's not the arrow for some variable declared in the scope of the code.

    Reply Reply

    By Nosbielcs (3 comments) on 10/09/2008

  8. Nosbielcs, eh .. this case really think I do not roll.
    For these and other can not I stop using Zend. I'm in love with this IDE rsrsrsrsrsr

    S2 Zend Studio kkkkkkkkkkk

    * Me precipitating .. I saw the picture in the Wiki at a glance and thought q was completing tasks rsrsrsrsr

    Reply Reply

    By Marcelo Sabadini (101 comments) on 10/09/2008

Place a comment

Links in comments should be nofollow free .

Get Adobe Flash player Plugin by wpburn.com wordpress themes