PHP

ImprimirCitar

PHP is a general-purpose interpreted programming language server-side that is especially suited for web development. initially created by Danish-Canadian programmer Rasmus Lerdorf in 1994. Today, the reference implementation of PHP is produced by The PHP Group. PHP originally stood for Personal Home Page, but now it means the recursive initialism PHP: Hypertext Preprocessor.

PHP code is typically processed on a web server by a PHP interpreter implemented as a module, a daemon, or as a common input interface (CGI) executable. On a web server, the output of the interpreted and executed PHP code—which can be any type of data, such as generated HTML or binary image data—would form all or part of an HTTP response. There are various template systems, content management systems and frameworks that can be used to organize or facilitate the generation of that response. On the other hand, PHP can be used for many programming tasks outside the context of the web, such as stand-alone graphical applications and drone control. Any PHP code can also be interpreted and executed through a command line interface. (CLI).

The standard PHP interpreter, powered by the Zend Engine, is free software released under the PHP License. PHP has been widely ported and can be deployed on most web servers on almost all operating systems and platforms, free of charge.

The PHP language evolved without a formal written specification or standard until 2014, with the original implementation acting as the de facto standard that other implementations tried to follow. Since 2014, work has been underway to create a formal PHP specification.

As of April 2020, more than half of the sites on the web using PHP were still on the discontinued version 5.6 or earlier, and with version 7.0 and 7.1 more than 68%, which are not officially supported by The PHP Development Team, while security support is provided by third parties, such as Debian (until June 2020 for PHP 5). Additionally, version 7.2, the most popular supported version, stopped receiving security updates on November 30, 2020.

Overview

PHP can be deployed on most web servers and on all operating systems and platforms at no cost. The PHP language is installed on more than 20 million websites and on a million servers. Migrating services based on PHP towards the new technologies that appear, supposes a cost to be justified monetarily (especially in terms of hardware and performance), therefore, talking about whether the number of sites based on PHP has been progressively reduced in recent years. recent years, with the appearance of new technologies such as Node.js, Golang, ASP.NET, etc.

To be able to get an overview of how PHP is evolving today, it is to talk about the new libraries available, the use of matrices, handling of integers, treatment of cryptography when using a Base64, Web scraping, web indexing, precooked data, Big Data, data set, data monitoring, set of dimensional propositions. As we can see, an overview of this language is much more complex than stating that it is a language for web development. This reality underlies the appearance of xyz domains, whose purpose and specialty is the caching of PHP services to serve content with a performance orientation linked to services for consumption by other services that need data, such as I.A.s. where PHP is seeing a reception with a feeling of confidence in the results to be obtained (without pretending to serve as a language in itself oriented to AI, since it was not its original conceptualization). Although the marketing that this type of domain is receiving is related to the new generations of people educated in new technologies. As part of the general vision, one last aspect should be included, and that is the ability to generate self-dependent security layers, in a paradigm that is only emerging thanks to the libraries available to PHP (In development process).

The Wikipedia website is developed in PHP. It is also the most popular Apache module among computers using Apache as a web server.

PHP's close resemblance to more common structured programming languages, such as C and Perl, allows most programmers to create complex applications with a very short learning curve. It also allows them to get involved with rich content applications without having to learn a whole new set of features.

Although everything in its design is oriented to facilitate the creation of websites, it is possible to create applications with a graphical user interface, using an extension such as PHP-Qt, PHP-GTK, WxPHP, WinBinder, Roadsend PHP, Phalanger, Phc or HiP Hop VM. It can also be used from the command line, in the same way that Perl or Python can; this version of PHP is called PHP-CLI (Command Line Interface).

When the client requests the server to send it a web page, the server runs the PHP interpreter. This processes the requested script that will generate the content dynamically (for example, obtaining information from a database). The result is sent by the interpreter to the server, which in turn sends it to the client.

Through extensions it is also possible to generate PDF files, Flash, as well as images in different formats.

Allows connection to different types of SQL and NoSQL database servers such as MySQL, PostgreSQL, Oracle, ODBC, DB2, Microsoft SQL Server, Firebird, SQLite or MongoDB.

PHP also has the ability to run on most operating systems, such as Unix (and such, such as Linux or Mac OS X) and Microsoft Windows, and can interface with most popular web servers already which exists in CGI version, module for Apache, and ISAPI.

PHP is an alternative to Microsoft ASP and ASP.NET (which uses C# and Visual Basic.NET as languages), ColdFusion from Adobe, JSP/Java, CGI/Perl and Node.js/ javascript. Although its creation and development occurs in the field of free systems, under the GNU license, there is also a commercial integrated development environment called Zend Studio. CodeGear (Borland's programming language division) has released an integrated development environment for PHP, called 'Delphi for PHP'. There are also at least a couple of modules for Eclipse, one of the most popular environments.

History

It was originally designed in Perl, based on writing a set of CGI binaries written in the C language by Danish-Canadian programmer Rasmus Lerdorf in 1994 to display his resume and store certain data, such as the number of of traffic that your website received. On June 8, 1995, "Personal Home Page Tools" after Lerdorf combined it with his own Form Interpreter to create PHP/FI.

Two Israeli Technion programmers, Zeev Suraski and Andi Gutmans, rewrote the parser in 1997 and created the basis of PHP3, and renamed the language to PHP: Hypertext Preprocessor. Public testing of PHP3 began immediately, and it was officially released in June 1998. By 1999, Suraski and Gutmans rewrote the PHP code, producing what is now known as the Zend engine. They also founded Zend Technologies in Ramat Gan, Israel.

In May 2000, PHP 4 was released under the power of the Zend Engine 1.0. On July 13, 2007, the suspension of support and development of version 4 of PHP was announced, and, despite what was announced, a new version with security improvements has been released, 4.4.8, published on July 13. January 2008, and later version 4.4.9, released on August 7, 2008. According to this news, critical bugs were supported until August 9, 2008.

On July 13, 2004, PHP 5 was released, using Zend Engine 2.0 (or Zend Engine 2). It includes all the advantages provided by the new Zend Engine 2, such as:

  • Better support for object-oriented programming, which in previous versions was extremely rudimentary.
  • Performance improvements
  • Best support for MySQL with fully rewritten extension
  • Better support to XML (XPath, DOM, etc.)
  • Native support for SQLite
  • Integrated support for SOAP
  • Data routers
  • Handling of exceptions
  • Improvements with implementation with Oracle

On November 26, 2020, the update of the PHP language to its version 8.0 is presented with more resources and optimizations including named arguments, types of unions, attributes, promotion of constructive properties, match expressions, nullsafe operator, JIT (dynamic translation) and also improvements in the type system, error handling and consistency in general, which will come to an end in November 2023, also considering that as of the launch on November 8 of the year 2022, Wordpress which has achieved compatibility on December 9, 2022. Followed by the CodeIgniter Framework which has currently pushed php7.4 out of its compatibilities in its new updates.

Release history

Meaning
Red Old version, without support
Yellow With security error support
Green Support for general and security errors
Blue Future launch
Rosa Release cancelled
VersionRelease dateEnd of supportNotes
1.0 08-06-1995Officially called "Personal Home Page Tools (PHP Tools)". It's the first version to use the name "PHP".
2.0 01-11-1997Considered by its creators the "fastest and simplest tool" to create dynamic web pages.
3.0 06-06-199820-10-2000Zeev Suraski and Andi Gutmans rewrite the basis for this version.
4.0 22-05-200023-01-2001A two-phase parsing system called Zend engine was added.
4.1 10-12-200112-03-2002'superglobals' are introduced.$_GET, $_POST, $_SESSIONetc.)
4.2 22-04-200206-09-2002Disable register_globals by default. Data received by the network are not inserted into the global namespace, closing possible security holes in the applications.
4.3 27-12-200231-03-2005CLI and CGI are introduced.
4.4 11-07-200507-08-2008Add man pages for phpize and php-config.
5.0 13-07-200405-09-2005Zend II engine with a new object model.
5.1 24-11-200524-08-2006Performance improvements with the introduction of compiler variables for the new PHP engine.
5.2 02-11-200606-01-2011Activity filter extension by default. Native JSON support.
5.3 30-06-200914-08-2014Support for namespaces, static link in execution time, leap label (limited GOTO), Native clauses, native support for PHP (phar) files, garbage collection for circular references, enhanced support for Windows, sqlite3, mysqlnd as replacement to libmysql as a library for extensions that work with MySQL, fileinfo as replaced by mime_magic for better support MItasole, and international label.
5.4 01-03-201215-09-2015Trait support and abbreviated array syntax. Elements removed: register_globals, safe_mode, allow_call_time_pass_reference, session_register(), session_unregister() and session_is_registered(). Built-in web server. Several improvements to existing features and performance, and minor memory requirements.
5.5 20-06-201320-06-2016New generators for loops, empty() supports expressions. Support for Windows XP and Windows Server 2003.
5.6 20-08-201431-12-2018Constant with scale expressions, lists of arguments of variable and exponential length through the operator **.
6 The development of PHP 6 has been delayed because developers decided that the current approach to dealing Unicode strings is not correct, and are considering alternate forms for the next version. The improvements planned for PHP 6 were added instead in PHP 5.3.0 (Support for namespaces, static link in execution time, lambda functions, closures, drip) and 5.4.0 (traits, closing relink).

Version 6 of PHP was abandoned as the following version is 7.

7.0 03-11-201503-12-2018Performance Improvements Declaring Functional Return Types
7.1 01-12-201601-12-2019 //not understandable Type of empty return, Constant class visibility modifiers, Nullable, iterable type pseudo, Captures multiple types of exceptions.
7.2 30-11-2017 30-11-2020 New type of return "object", integration of Libsodium as an extension of the core
7.3 6-12-2018 6-12-2021 Flexible syntax for Nowdoc and Heredoc, reference support and mapping arrays with list(), PCRE2 support, hrtime() function
7.4 28-11-2019 28-11-2022 PHP 7.4 arrived at the end of his life on November 28, 2022.
8.0 26-11-2020 26-11-2023 New features and eh performance increase
8.1 25-11-2021 25-11-2024 Properties "readonly", "Enums", "Fiber" and new syntax
8.2 08-12-2022 08-12-2025 Creating dynamic properties is disproved and the AllowDynamicProperties attribute is added


Syntax

The syntax of PHP is based on the programming principles of C.

The PHP interpreter only executes the code inside its delimiters. The most common delimiters are <?php to open a PHP section and ?> to close it. The purpose of these delimiters is to separate the PHP code from other code, such as HTML. In files that contain only PHP code, the ?> delimiter can be omitted. In fact, PHP-FIG through its standard recommendations for PHP recommends omitting the ?> delimiter, as this does not accidentally send HTML content. For example, if you send a character "no PHP" (which is not processed by the PHP interpreter), certain actions such as sending HTTP headers via the header() function will not be able to be executed, since the response process has already started.

Variables are prefixed with the dollar sign ($) and do not need to be typed. Variables, unlike functions, are case sensitive. Character strings can be encapsulated in both double quotes and single quotes, although in the case of the former, variables can be inserted directly into the string, without the need for concatenation.

Comments can be written either with two slashes (//) at the beginning of the line, or with a pound sign (#). It also allows multi-line comments encapsulated in /* */.

In terms of keywords, PHP shares with most other languages with C syntax conditions with if, loops with for and while and function returns. Usually in this type of language, the statements must end with a semicolon (;).

Basic PHP Code Examples

Hello world program with PHP embedded within HTML code:

html.html lang="is" dir="ltr".head .goal charset="UTF-8" / 2005 .goal name="viewport" content="width=device-width, initial-scale=1.0" / 2005 .titleBasic example PHPtitlehead.body ? echo 'Hello world'; ?bodyhtml

Hello world program with PHP in the form of a monolithic app:

?// Area of headers, constants and includes (initialization of the application)// Heading only for demonstration, not necessaryheader('Content-Type: text/html; charset=UTF-8');$ = ';// Logic of the application, such as obtaining user of the session, content, etc.// This code could come from an external template for easy reuse$ . = ' ◊;$ . = '.html lang='es';$ . = ';$ . = '.;$ . = '.. meta charset="UTF-8" / 2005;$ . = ' ♫ meta name="viewport" content="width=device-width, initial-scale=1.0" / 2005';$ . = '. basic pattern of PHP tends/titles.';$ . = '.;$ . = ';$ . = '.;$ . = ' ≤1 tax Hello world!;$ . = '.;$ . = ';$ . = 'plus/html;// Send replyI $;// Note that the "label" does not close.php. PHP-FIG recommends this practice in// files containing only PHP code so as not to send HTML content// Accidental way.

Hello world program with PHP responding in JSON format:

?// Archive reply_json.php// Tells the browser that the answer will be JSONheader('Content-Type: application/json; charset=UTF-8');$ = [chuckles] 'Message' = 2005 'Hello world!'];I json_encode($);// Do not close the "label" as the file contains only PHP code

The client side that will request the PHP file:

html.html lang="is".head .goal charset="UTF-8" / 2005 .goal name="viewport" content="width=device-width, initial-scale=1.0" / 2005 .titleJSON format response example from PHPtitlehead.body .div .h2Response in plain texth2 .precode id="response-plane"ΔcodeΔpre div .div .h2Processed response (measure field of the JSON response)h2 .precode id="response-processed"ΔcodeΔpre div .script document.addEventListener('DOMContentLoaded', () = 2005 { const ContainerResponse = document.querySelector('#response-plane'); const Controlled = document.querySelector('#response-processed'); // Makes asynchronous request to php file fetch('response_json.php') .then(response = 2005 response.json()) // Transform the answer to a JSON object .then(AnswerJson = 2005 { // answerJson is an object in format { message: "Hello world!"} ContainerResponse.innerHTML = JSON.stringify(AnswerJson); Controlled.innerHTML = AnswerJson.message; }); // handle errors with.catch() }); scriptbodyhtml

Databases (MySQL)

PHP can be combined with MySQL to work with databases, although other database engines such as Microsoft SQL Server, PostgreSQL, MongoDB, among others, can also be used.

The following example shows login with username and password using MySQL and PHP with the object-oriented style:

?// Connection to the local 'site' database. Normally this would come from a// external service that is reused throughout the site.$conexion = new PDO('mysql:host=127.0.0.1;dbname=site', 'root', ', [chuckles] // Release exception if an error occurs, so the error manager will take the necessary actions // as displaying a 500 error or ending the execution of the system. Note that it is not used // try-catch here to delegate responsibility to the bug manager. PDO::ATTR_ERRMODE = 2005 PDO::ERRMODE_EXCEPTION, // Disable emulation of prepared sentences (only natives are safe) PDO::ATTR_EMULATE_PREPARES = 2005 false,]);// The data sent by the form is obtained// For the simplicity of the demonstration is used the coalesce operator (???)$name_user = trim($_POST[chuckles]'noun_usuario'] ? '); // Spaces are removed at the beginning and at the end$ = $_POST[chuckles]'contrasena'] ? '; // The password is left as, without trim()// Just act if the form has been sent with dataif (isset($_POST[chuckles]'send']) " fake " !($name_user) " fake " !($) { // Consultation to search the user in the database // Sentences prepared to prevent SQL injections are used $consulta_usuario = $conexion- 2005prepare(' SELECT * FROM users WHERE name_user = ? LIMIT 1'); $consulta_usuario- 2005execute(b)$name_user]); // Verify if a user has been found if ($consulta_usuario- 2005rowCount()  0) { // Obtains user data $usuario_found = $consulta_usuario- 2005fetch(PDO::FETCH_ASSOC); // Check if the password sent is correct // Uses secure algorithms like BCrypt or Argon2i if (password_verify($, $usuario_found[chuckles]'contrasena'])) { // Correct credentials, log in ! else { // Incorrect Credentials, display error message ! ! else { // Username does not exist, display error message // Note that, for security, here and above you must show an error // generic as "Incorrect rectals", thus a possible // attacker will not know if you have entered the correct username !!// Do not close the "label" as the file contains only PHP code

The following example does the same thing as the previous one, but with the assurance that whatever the average state of the service, if there is no way to connect, the class will be destroyed and the attachment to its threads will be closed.

bórrese Bórrese

? //Archivo BD_access.class.php class interface { public $conexion; public $BD_ACCESS; public $HOST_ACCESS; public $USER_ACCESS; public $PWD_ACCESS; public $; public function __construct(array $args) { $out='; try { if (null=$args[chuckles]'BD_ACCESS']) " fake " (null=$args[chuckles]'HOST_ACCESS']) " fake " (null = $args[chuckles]'USER_ACCESS']) " fake " (null = $args[chuckles]'PWD_ACCESS']){){ //We built the class $this- 2005BD_ACCESS = $args[chuckles]'BD_ACCESS']; $this- 2005HOST_ACCESS = $args[chuckles]'BD_ACCESS']; $this- 2005USER_ACCES = $args[chuckles]'BD_ACCESS']; $this- 2005PWD_ACCESS = $args[chuckles]'BD_ACCESS']; ! else { throw new Exception('Error de construccion del interface de connection a datos: No all arguments are supplied',400); ! ! catch(Exception $ die('"{error":".$- 2005getMessage.); ! finally{ // Connect to MySQL server and select the database with the name 'login' $this- 2005connection = @new mysqli($this- 2005HOST_ACCESS, $this- 2005USER_ACCES, $this- 2005PWD_ACCESS, $this- 2005BD_ACCESS); ! try{ if (!$this- 2005connection throw new Exception('Connecting the database: the arguments introduced are not enough to create a connection',410); ! ! catch (Exception $ die('"{error":".$- 2005getMessage.); ! finally{ $out='{'Ok': "The connection has been made"}; ! $this- 2005error=$out; ! public function querySQL(string $queSQLquery): string { $out='; // Consultation to search for users in the database $consulta_usuario = $this- 2005connection- 2005query($queSQLquery); // Verify that a user has been found if ($consulta_usuario- 2005num_rows  0) { // Get the user data in the form of an associative array $usuario_found = $consulta_usuario- 2005fetch_assoc(); // Check if the password used is the same as the one in the database if ($  $usuario_found[chuckles]'contrasena']) { // Successful text $out = '{'Ok': "You've started the session correctly"; ! else { // Error text $out = '{"error": "The password used is not correct"}; ! ! else { // Error text $out = "{"error": "The introduced user does not exist"}; ! // Close the connection $this- 2005connection- 2005close.(); return $out; ! !?? //Archivo cabecera.h.php// Just show fatal errors, parseus and warnings for exampleerror_reporting(E_ERROR 日本語 E_PARSE 日本語 E_WARNING);//Inclusion of classes for management instances$seHaIncluded=include_once(BD_access.class.php);if($seHaIncluded // Check that the form was sent using the send button if (isset($_POST[chuckles]'send'])) { //Initiating variables $='; $='; // Get the data sent by POST method and delete the blank spaces from start and end $ = trim($_POST[chuckles]'usuario']); $ = sha1(trim($_POST[chuckles]'contrasena'])); //Check that the variables are not empty if(!($) " fake " !($){ $args = array('BD_ACCESS'= 2005'users', 'HOST_ACCESS'= 2005'localhost','USER_ACCESS'= 2005'root','PWD_ACCESS'= 2005'sin_contrasenia' //For instance objects associated with the corresponding classes $misAccess = new interface($args); $stateConn = JSON.decode($misAccess- 2005error); if(isset($stateConn[chuckles]'Ok']){){ $state Query=$misAccess- 2005querySQL("SELECT * FROM users WHERE user = '$' LIMIT 1"); I '{'exit':'.$state Query.'; !else if(isset($stateConn[chuckles]'error']){){ I "{"error":".$state Query.'; ! !else{ I "{"error":" forms with unrecognized data"}; ! !else{ I '{"error": "intention of access not allowed"}; !!?

As a REST service

REST services are based on three fundamental concepts:

 Resource concept
Concept of itinerance
API Concept

PHP Features

Features

  • Guided to the development of dynamic web applications with access to information stored in a database.
  • It is considered an easy language to learn, as in its development different specifications were simplified, as is the case of the definition of primitive variables, an example that becomes evident in the use of php arrays.
  • The source code written in PHP is invisible to the web browser and the customer, as it is the server that is responsible for running the code and sending its HTML result to the browser.
  • Connection capacity with most of the database engines currently used, highlights its connectivity with MySQL and PostgreSQL.
  • Capacity to expand your potential using modules (called extensions).
  • It has extensive documentation on its official website, which highlights that all functions of the system are explained and exemplified in a single aid file.
  • It is free, so it is presented as an easy-to-access alternative for everyone.
  • It allows application of object-oriented programming techniques.
  • It does not require definition of variable types although its variables can also be evaluated by the type that they are managing in execution time.
  • It has exception handling (from PHP5).
  • While PHP does not require anyone who uses it to follow a certain methodology when programming, even if it does, the programmer can apply in his work any programming or development technique that allows him to write orderly, structured and manageable code. An example of this is the developments in PHP that have been made of the Model Control View (MVC) design pattern that allow to separate the processing and access to the data, the control logic and the user interface into three independent components.
  • Due to its flexibility, it has had a great reception as a base language for the WEB content management applications, and it is its main use.

Disadvantages

  • Since it is a language that is interpreted in execution, for certain uses it may be an inconvenience that the source code cannot be concealed. Offuscation is a technique that can hinder the reading of the code but does not necessarily prevent the code from being examined.
  • Because it is a interpreted language, a PHP script usually works considerably slower than its equivalent in a low-level language, however this inconvenience can be minimized with cache techniques both in files and in memory.
  • In the versions prior to 7 the variables are not typified, which makes it difficult for the different IDEs to offer assistance for the code typing, although this is not really an inconvenience of the language itself. This is solved by some IDEs adding a comment with the type to the variable statement.

XAMPP, LAMP, WAMP, MAMP, UwAmp

LAMP includes PHP (here with Squid).

XAMPP is a platform-independent, free software server, consisting mainly of the MySQL database, the Apache web server, and interpreters for scripting languages: PHP and Perl. The name comes from the acronym for X (for any of the different operating systems), Apache, MySQL, PHP, Perl. The program is released under the GNU license and acts as a free, easy-to-use Web server capable of rendering dynamic pages. XAMPP is currently available for Microsoft Windows, GNU/Linux, Solaris, and MacOS X.

It is a "lightweight" which can be used on any PC. You don't need a lot of resources.

LAMP features functionality similar to XAMPP, but focused on Linux, WAMP makes it Windows-focused, and MAMP for MacOS X. UwAmp is very identical to WAMP and stands out in that it can be run from a USB stick.

Main sites developed with PHP

PHP is used by millions of sites; among the most prominent are:

  • Digg
  • Facebook
  • Flickr
  • Mailchimp
  • Tumblr
  • Wikipedia
  • WordPress
  • Yahoo!

Contenido relacionado

Network card

The network card, also known as the network card, network adapter, LAN adapter, Physical network interface, or its terms in English network interface card or...

X Window System

The X Window System is a window system, common in UNIX-like operating systems, which was developed in the mid-1990s. the 1980s at MIT to provide a graphical...

Data terminal equipment

A data terminal equipment is that component of a data circuit that acts as a source or destination of...
Más resultados...
Tamaño del texto:
Copiar