samedi 1 juin 2013
0 commentaires

Introduction to PHP

03:26


What makes the success of the Web today is both its simplicity and ease of access. A lambda user does not need to know "how it works behind." And fortunately for him.

In contrast, a webmaster apprentice as you must, above all, know the basics of running a website. What is a server and a client? How do you make a dynamic site? What do PHP and MySQL?

This first chapter is here to answer all these questions and show that you are able to learn to create dynamic websites. All players will be at the end assurance that they start at the same level!

The static and dynamic websites

We consider that there are two types of websites: static websites and dynamic websites.

Static sites: sites that are made ​​using only HTML and CSS. They work very well but the content can not be updated automatically requires that the owner of the site (the webmaster) modifies the source code to add new features. This is not very practical when you have to update the site several times in the same day! Static sites are well suited to achieve sites "window" to present such a business, but go further. This type of site is increasingly rare today, as soon as we add an element of interaction (such as a contact form), we no longer speak of static site but dynamic site.

Dynamic sites more complex, they use other languages ​​in addition to HTML and CSS, such as PHP and MySQL. The content of these websites is called "dynamic" because it can change without the intervention of the webmaster! Most of the web sites you visit today, including Site Zero, are dynamic sites. The only prerequisite to learn how to create this type of site is to already know make static sites in HTML and CSS.


You can read on the website Zero HTML / CSS course I wrote for you to upgrade or get the book "Make your website with HTML5 and CSS3."


The objective of this course is to make you able to perform dynamic entirely by yourself web site, step by step.
In fact, they can offer much more exciting than static sites features. Here are some things that you will be able to achieve:

a members area: your visitors can register on your site and have access to sections reserved for them;

one: it is common today to see the web offer a forum to help each other or simply pass the time the sites;

a visitor counter: you can easily count the number of visitors who have logged in the day on your website, or even know the number of visitors trying to navigate!

News: You can automate the writing of news, giving your visitors the ability to write, comment, etc.. ;

a newsletter: you can send an email to all your members regularly to present the news and thus encourage them to return to your site.

Of course, these are just examples. It is possible to go even further, depending on your needs. Know for example that almost all online gaming sites are dynamic. Found particularly breeding site virtual animal games space exploration, etc..

But ... do not get carried away. Before we get there, you have to read and a lot to learn! Start with the basics: do you know what happens when you visit a web page?



How does a website work?


When you want to visit a website, you type its address in your web browser, either Mozilla Firefox, Internet Explorer, Opera, Safari or another. But have you ever wondered how did the web page to reach you?

You should know that the Internet is a network of computers. These can be classified into two categories.

Customers: they are the computers of Internet users like you. Your computer is therefore part of the category of customers. Each client is a visitor to a website. In the diagrams that follow, the client computer will be represented by the following picture.

The servers are powerful computers that store and deliver web sites to users, that is to say to customers. Most Internet users have never seen a server in their lives. However, the servers are essential for the functioning of the Web. Over the next diagrams, a server will be represented by the image of the figure.

Un client
Client
Un serveur
server

Most of the time, the server is free screen: it stays on and works alone without human intervention, 24 H/24, 7 days / 7. A real slave labor.
Therefore: your computer is called the client, while the computer that holds the web site is called the server. How the two communicate?

It is precisely here that the difference between a static website and dynamic website. Let's see what changes.

For a static site

When the site is static, the pattern is very simple. This happens in two stages, as you shown schematically in the figure below:

the client requests the server to view a web page;

the server responds by sending the requested page.


Transferts avec un site statique

Communication is pretty basic:

"Hello, I am the customer, I would like to see this web page. "

"Look, here's the page you asked me. "

On a static site, it happens nothing. The server stores web pages and sends them to clients that request without modification.

For a dynamic site

When the site is dynamic, there is an intermediate step: the page is generated (Fig. next).

The client asks the server to do a web page;

the server prepares the page specifically for the client;

the server sends the page it just generated.


Transfert avec un site dynamique


The web page is generated whenever the customer wants. This is precisely what makes dynamic sites alive: the contents of a page can change from one moment to another.

This is how some sites are able to display, for example your nickname on all pages. Because the server generates a page every time you ask him for one, he can customize to suit the tastes and preferences of the visitor (see, among others, his pseudonym).




The Web languages



When creating a website, it is necessary to handle not one but several languages​​. As a webmaster, it is imperative to know.

Some programs, called WYSIWYG (What You See Is What You Get) can help the beginners to create a static website without knowing programming languages ​​behind ... But to achieve a dynamic site as we wish, we absolutely must get their hands dirty.
For a static site: HTML and CSS

Many languages ​​have been created to produce websites. Two of them are an essential basis for all webmasters.

HTML: the language based websites. Simple to learn, it works from tags. Here is an example of HTML:


<p> Hello, I am a <em> paragraph </ em> text </ p>
CSS is the language formatting of websites. While HTML allows you to write the content of your web pages and structure, the CSS takes care of the formatting and layout. This is particularly the CSS that you choose the color, size, menus and many other things. Here's a CSS code:

div.banner {

   text-align: center;
   font-weight: bold;
   font-size: 120%;
}

These languages ​​are the basis of all websites. When the server sends the web page to the client, it actually sends the code in HTML and CSS.

The problem is that when you only know HTML and CSS, you can produce only static sites ... and not dynamic sites! For the latter, it is necessary to handle other languages ​​in addition to HTML and CSS.

The question we must ask is: do you know HTML and CSS?

If so, this is perfect, you can continue because we need it later. If the answer is no, do not panic. These languages ​​are not very difficult, they are within the reach of all. You can learn by reading my course on HTML and CSS.
Know that learning these languages ​​is a matter of a few weeks, or even less if you have enough free time.


Le serveur envoie du HTML et du CSS au client

For a dynamic site: add PHP and MySQL

Whatever the website that you want to create, HTML and CSS are essential. However, they are not sufficient to create dynamic sites. We must add other languages​​.

It is precisely the whole purpose of this course you will learn how to handle PHP and MySQL to produce dynamic web site.

PHP: it is a language that only servers understand and can make your site dynamic. PHP is that "generates" the web page as seen on previous schemes.

This will be the first language we discover in this course. It can work alone, but it really takes interest only if it is combined with a tool such as MySQL. Here is a PHP code:

<? php echo "You are visitor number". $ nbre_visiteurs; ?>

MySQL: it's called a DBMS (Database Management System Data). Simply put, its function is to store data in an organized way to help you find them easily later. It is thanks to MySQL you can save the list of members of your site, posts on the forum, etc.. The language used to communicate with the database is called SQL. Here is a code in SQL:

SELECT id, auteur, message, datemsg FROM livreor ORDER BY datemsg DESC LIMIT 0, 10

PHP and MySQL are free software called Expired. Among other things, it guarantees must Gives you sustainability: everyone can Contribute to Their development, so you do not risk to see all webmasters know PHP and MySQL overnight, and that's very significant!
On the other hand, PHP and MySQL are available. This means clustering one crucial thing: You Will not Have to pay a dime to build your website!
PHP can work alone and enough to create a dynamic site, things get really interesting goal When combined with a DBMS: such as MySQL. HOWEVER, to simplify, forget for the moment focus on MySQL and PHP.

Generates HTML PHP

Customers are Unable to Understand the PHP code: They only know HTML and CSS. Only the server can read the PHP.

The role of PHP is Precisely to generate HTML code (you can aussi generate the CSS, aim it's rare), That code is feeling to the customer in the same way as a static site, as shown in Fig. Next.


PHP décide ce qui va être affiché sur la page web envoyée au visiteur


PHP is a programming language used on many servers to make decisions. This is PHP decides HTML code will be generated and sent to the client every time.

To understand the point of all this, consider an example. You can write in PHP: "If the visitor is a member of my site and it's called Jonathan, Jonathan displays Welcome to the web page. However, if it is not a member of my site displays Welcome to the site and offers visitors to register. "
This is a very basic example of dynamic site depending on whether you are a registered member or not, you will not see the same things and can not be access to all sections will.




And competition?


HTML and CSS are not competitors because they are standards. Everyone is supposed to know them and use them on all websites.

However, in terms of dynamic websites, PHP and MySQL are far from alone on the spot. Can not you make a list of their competitors, it would be too long (and boring!). However, for your general knowledge, it is necessary to know at least a few other big names.

First, if there is a tendency to combine PHP and MySQL for powerful dynamic sites, do not mix the two. The first has different competitors second.

Competitors PHP

Among the competitors PHP include the following:

ASP NET. Designed by Microsoft, it uses the framework (that is to say a set of libraries that provide services for developers) NET familiar to C # developers.. This language can be interesting if you have a habit of developing in C #. NET and you do not want to be disoriented.

Ruby on Rails: active, this framework is used with the Ruby language and allows for dynamic sites quickly by following certain conventions.

Django: it is similar to Ruby on Rails, but it can be used in Python.

Java and JSP (Java Server Pages) more commonly called "JEE", it is especially used in the professional world. It requires a certain rigor. The establishment of a JEE project is traditionally a little longer and heavier but the system is appreciated by professionals and institutions. This is what is used on the site of French taxes, for example.

Ruby on Rails

I can not present all the competitors, but it should already give you a good idea. For information, it is also possible to use language such as C or C + +, although it is more complex and not necessarily always appropriate (that means, I do not recommend it at all).

Which of the batch? Which is better?
Given the purpose of this course, you expect that I will instantly answer "PHP! ". But no. In fact, it all depends on your programming skills. If you've ever handled Java, you will quickly feel comfortable with JSP. If you know Python, Django seems entirely appropriate.

As for PHP, it stands out from its competitors by a large community that can help you quickly on the Internet if you have problems. This is an easy language to use, ideal for beginners and professionals: Wikipedia and Facebook are examples of famous and very popular websites that work with PHP.

In short, there is no better choice. I recommend the language for which you will be sure to have someone to help you. PHP in this sense is often a very good choice.

Competitors MySQL

Regarding databases, the choice is still very large.
However, while PHP and its competitors are mostly free and open time, this is not the case for most databases.

Among the competitors MySQL, I suggest you know (at least in name) as follows:

Oracle is the most popular DBMS, the most complete and the most powerful. Unfortunately, it is paying (and expensive), what the reserve rather companies who already use heavily. However, there are free versions of Oracle, especially for those who want to learn to use.

Microsoft SQL Server: Powered by Microsoft, it is often used in combination with ASP NET, although it can be used with any other language.. It is limited, but there are free versions limited.

PostgreSQL: it is a free and DBMS like MySQL, which offers more advanced features. Sometimes compared to Oracle, however, it still has some way to go. It has a slightly less important than MySQL and Oracle community. Site Zero uses PostgreSQL.

Oracle

Again, this list is far from exhaustive but presents at least a few big names.
For information, MySQL is by far the free database and free the most used. Among the paid professional solutions, Oracle is the most advanced and the most common, but its use is mostly limited to large companies.

Ultimately, if your resources are limited, you do not have many choices for the DBMS. MySQL is the most appropriate because it is free, free, powerful and used by many people who are likely to help you.

Several combinations are possible

As you can see, you have the choice between many tools to achieve a dynamic site. Most of them are free.

Note that you can combine a priori these tools as you see fit. For example, it is quite another to use PHP with MySQL database, such as Oracle or PostgreSQL. Similarly, MySQL can be used with any other language: Java, Python, Ruby, etc..

However, the combination "PHP + MySQL" is probably the most common. It is not by chance that this course addresses these two tools that have proven their worth.

In short

There are two types of websites:

static sites: made in HTML and CSS, the content can be updated by the webmaster;

Dynamic sites: made with other tools such as PHP and MySQL over HTML and CSS, they allow visitors to participate in the site, to post messages ... in short, to make the site alive!

Visitors to the site are called clients. They ask the server that hosts the site to send their web pages.

PHP is executed by the server. It allows you to customize the page according to the visitor, to treat its messages, perform calculations, etc.. It generates an HTML page.

MySQL management system is a database. It is responsible for storing information (message list, members ...).

Next
This is the most recent post.
Article plus ancien

0 commentaires:

Enregistrer un commentaire

 
Toggle Footer
Top