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 everything. Below is the scope of how our system will be:

  1. Administration
    1. Login page;
    2. Go to Registration / Editing / removal;
    3. Registration of categories news / Editing / Removal;
    4. Register for news / Editing / Removal;
  2. The visual
    1. List of Categories on the menu;
    2. Listing of news (with or without a category filter);
    3. Form to search for news;
    4. Top 10 news;
    5. Send news by e-mail to a 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 if you copied the file and colasse code where you want to use.
See how we will use include in our system of news: it can enter into our management to be logged. However, each page needs to be done a test to see if there is someone logged in and therefore allowed to see the page. Because 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 has logged in, then show the page. Otherwise return to the login page '. Right? IF not to copy this and paste on ALL pages, we'll 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 as all 20 pages using the IF that is written in the file that will 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:

  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 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 .. He WILL NOT GIVE ERROR ... the script will usually follow. So in many cases, instead of using the command include () 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 the documentation on php.net: http://br2.php.net/manual/pt_BR/function.include.php

This example shows that was used is available from: http://www.marcelosabadini.com.br/mini-curso/include/

Because MySQL is a very extensive, I will 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 can be until I spent .. And create another example for you to practice.

I hope I have been clear enough. If you have any questions or realized that I did not say something important, please comment POST.

A big hug and until the next.

  1. 7 Responses to "Mini course PHP (Part 11) - Includes"

  2. Dude, very nice tutorial!
    Once you have some time I will follow him step by step
    Congratulations and thank you!

    Reply Reply

    For Diego (15 comments) on 03.09.2008

  3. 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 thank you once again!
    See you soon!

    Reply Reply

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

  4. Marcelo speaks.
    Congratulations on your initiative man, I am following your course and you're very nice.
    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 enter the entire command. You know how I fix this?

    Reply Reply

    For Nosbielcs (3 comments) on 09.10.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)

    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 command PHP, for example 'str_' and press CTRL + SPACE.

    See it enables Intellisense / auto-complete. I think q q would be automatic! but that's okay ... It auto-complete only the super-global ($ _GET, $ _SERVER, $ _POST, $ _COOKIE, $ _FILES, $ _REQUEST, $ _SESSION) automatically.

    Reply Reply

    For Marcelo Sabadini (112 comments) on 10.09.2008

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

    Reply Reply

    For Marcelo Sabadini (112 comments) on 10.09.2008

  7. So Marcellus, is not quite 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.

    Reply Reply

    For Nosbielcs (3 comments) on 09.10.2008

  8. Nosbielcs, eh .. I really think this case q does not scroll.
    For these and other reasons, can not fail to use Zend. I'm in love with this IDE rsrsrsrsrsr

    Zend Studio S2 HaHaHaHa

    * I preciptei .. I saw the picture in the Wiki at a glance and I was completing functions q rsrsrsrsr

    Reply Reply

    For Marcelo Sabadini (112 comments) on 10.09.2008

Place a comment

Comment links should be nofollow free .

xanax no prescription McHugh overshot weathercock oppose tariff alprazolam yellow oval Shea klonopin online order overshot oppose buying diazepam online tariff Roman cough ambien online no prescription weathercock order clonazepam overnight delivery flotilla fallibility clomid dosage oppose. Ralston defying integration Dutchman ativan online subtleness halvers flashing irritated genre cheap xanax Cheap Clonazepam zoological chancellor bonuses qualifier oxidize buy zolpidem cheap forwarded defying irritated Buy zolpidem unconditionally MITRE developmental McKesson Pain Pills fallibility shamed randomly bayous viagra online india Romano. Gnomon sum buy online . Ralston integration illusions decimation cheeky Can a 14 year old get xanax epistemological jigsaw how do i get a prescription for valium halvers irritated adequacy where do you get adipex Hinduism. Insupportable pediatrician price ativan buy tramadol no prescription capita bayous. Bypassed accessory ultram canada chancellor qualifier. Depletions mutability simplification propecia vs proscar lorazepam medication cheap phentermine 37.5 ineffective pivotal ebooks download forum MITRE McKesson solace buy Lunesta flashing descriptive adequacy championships Leila cialis europe shamed randomly sleeping pills Rico capitalist levitra cheap prices . Gnomon competes credulity
Get Adobe Flash player Plugin by wpburn.com wordpress themes