background preloader

Php

Facebook Twitter

PHP - Liste des extensions. PHP - Référence des fonctions. PHP - Toutes les fonctions documentées. PHP for Beginners: Building Your First Simple CMS. The Magic of PHP + MySQL It’s safe to say that nearly every website that’s up-to-date these days is using some form of content management system (CMS). While there are a ton of great free options that provide us with a CMS to power a website (WordPress, Drupal, etc.), it doesn’t hurt to peek under the hood and get a feel for how these systems work.

To get our feet wet as back-end developers, we’ll be creating a simple PHP class that will: Create a databaseConnect to a databaseDisplay a form with two fieldsSave the form data in the databaseDisplay the saved data from the database Download Files This class is intended to give you a feel for how PHP and MySQL interact together, and to show the basics of a CMS. I’ll be skipping explanations of some of the very basic programming stuff, so if at any point you feel lost, checkout the course Diving into PHP and give yourself a crash-course in PHP. Building the Class As you can see, we’re creating one class with four variables and five methods. <! <? Quels sont vos astuces et secrets de programmation ? Confiez-nous vos trucs pour gagner du temps ou impressionner les collègues. Vous faites du développement depuis des années dans votre langage favori et vous croyez qu'il a fini de vous surprendre ? Pas si sûr, car tous les langages ont des secrets, des fonctionnalités cachées que vous rencontrez un beau jour sur le code d'un collègue, sur un projet open-source ou même par une malheureuse (ou heureuse?)

Faute de frappe. En PHP par exemple, savez-vous qu'il est possible d'appeler « Echo » avec plusieurs paramètres et faire, en quelque sorte de la concaténation avec une virgule ? Si cette astuce est anecdotique, voir inutile, d'autres peuvent surprendre et s'avérer très utiles, comme ce bout de code, certes un peu extrême pour des raisons de démonstration : Code : Il s'agit en fait de l'utilisation des variables dynamiques, ou les variables des variables, une astuce qui marche aussi (et heureusement) pour les fonctions et méthodes de classes.

Toujours en PHP, connaissez-vous la classe standard ? Vous en connaissez certainement dans votre langage de prédilection. Dynamic Properties in PHP and StdClass | Kris Jordan. Languages like JavaScript and Python allow object instances to have dynamic properties. As it turns out, PHP does too. Looking at the official PHP documentation on objects and classes you might be lead to believe dynamic instance properties require custom __get and __set magic methods.

They don't. Simple, Built-in Dynamic Properties Check out the following code listing: Using the built-in dynamic instance properties is an order of magnitude faster (30x, by my profiling) than using magic __get and __set methods. So when does it make sense to use __get and __set? StdClass: Anonymous Objects Sometimes all that is necessary is a property bag to throw key value pairs into. $object = new StdClass; $object->foo = 'bar'; json_encode($object); Next I'll touch on the SPL's Countable and ArrayAccess as a means of being able to accomplish the following in PHP: Thanks to the folks pointing out that you don't need to extend from StdClass in order to have dynamic properties!

Bibliothèques / Frameworks

Creating the Blog Script for a PHP/MySQL Blogging System. A downloadable file for this article is available here. Introduction Integrating the login script with the blog should not be a problem for you. In fact all it needs to do is send a user through, if his or her login is valid, and then log the user out. The blog will have a MySQL backend that will store all the articles and related replies. It will also have a categories table that we will use to store all the different categories in. To retrieve the articles we will mostly use joins in our SQL, as this is the best way to retrieve grouped information, which in our case is absolutely vital to the way the blog structures the articles.

The index page sends two values over to the comments page. Van's Apache SSL/TLS mini-HOWTO. Fun with Apache, mod_ssl, and OpenSSL Introduction I recently had a need to setup a private directory on my web server that could only be accessed by a handful of selected people. The content also needed to be encrypted in transit. This mini-HOWTO details how I did this on a Red Hat 8.0/Apache 2.0.40 server using mod_ssl and OpenSSL (0.9.6b and higher). Here are the goals of this small project: Require HIGH or MEDIUM level SSL/TLS encryption at the transport (TCP) layer Browser must use SSLv3 or TLSv1, not SSLv2 Require username/password authentication for some subdirectories Learn about TLS certificates Be a mini-CA (Certificate Authority) Use a non-standard port to keep most of the port-scanning riffraff away Create client certificates, and require them for specific directories The key to this whole system is the SSL/TLS protocol.

Assumptions/Prerequisites First and foremost, this document assumes that you are using some flavor of Linux, Apache 2.0.x, and that you have OpenSSL installed. Que font les références ? Assignation par référence ¶ Dans ce premier cas, les références PHP permettent de faire en sorte que deux variables référencent le même contenu. Par exemple : Cette écriture indique que et pointent sur le même contenu.

Note: et sont complètement égales ici : ce n'est pas qui pointe sur , ou vice-versa. Ce sont bien et qui pointent sur le même contenu. Note: Si vous assignez, passez, ou retournez, une variable indéfinie par référence, elle sera créée automatiquement. La même syntaxe peut être utilisée avec les fonctions qui retournent des références, et avec l'opérateur new (depuis PHP 4.0.4 et avant PHP 5.0.0) : Depuis PHP 5, new retourne automatiquement une référence, donc l'utilisation de =& dans ce contexte est obsolète, et produit un message de niveau E_DEPRECATED à partir de PHP 5.3, et un message E_STRICT avec les versions antérieures.

Avertissement Exemple #2 Référencer des variables globales depuis des fonctions <? Function global_references($use_globals){ global $var1, $var2; if (!