Les commentaires sur PHP.net, un océan de bonnes pratiques

ViPHP
ViPHP | 4039 Messages

14 févr. 2011, 12:35

Par exemple:
http://us3.php.net/manual/en/function.r ... php#101670

Edit: a été effacé. Contenu originel:
Require is a really neat function, compared to include. You can use it for security purposes. For example, consider that you have a database that's based on simple text-files. Theoretically, someone could type in the URL of those text-files, and view them directly in their browser. This is as opposed to what you want: those files only to be viewable through your own PHP script. Otherwise, the data won't be properly formatted, or much worse, you won't be able to do a proper secure authorization or authentication. So, here's the trick. Rename your .txt files to .php files. The first line should be this...

require('this_file_does_not_exist_and_will_never_exist');

Then, after that first line, the rest of the file is your database information. If someone tries access the file directly, they'll get an error, and see no information (danged hackers!). But, your PHP script that displays the database file will know that this line is there. This is assuming that you reprogram your text-database, php-front-end to ignore the first line of files when reading data.

It's not encryption, but it's powerful security, quick and cheap, for custom-built databases.
Ou encore celui-ci (le super-if):
http://us3.php.net/manual/en/control-st ... .php#90073

Et sans doute le champion toutes catégories (récupéré sur Google cache):
http://webcache.googleusercontent.com/s ... gle.com.au
Edit: autant le mettre en entier:
Use split with implode to fetch array values or elements:

<?php
list( $ip, $line, $filename) = split( ',', implode( ',', array('100.1.2.3','23','/index.php') ) );

echo $ip.$line.$filename;
?>

Result :

100.1.2.3
23
/index.php
Modifié en dernier par Berzemus le 14 févr. 2011, 14:36, modifié 1 fois.
Mais qu'importe. (je suis ici - dernier petit projet)
Berze going social.

ViPHP
xTG
ViPHP | 7331 Messages

14 févr. 2011, 12:39

J'ai adoré le super-if ! =D>

Eléphant du PHP | 275 Messages

14 févr. 2011, 16:38

Require pour faire ça ? Beurk.

"exit" c'est trop compliqué ?

ViPHP
ViPHP | 3300 Messages

14 févr. 2011, 20:18

Oui exit c'est pas mal non plus, ça donnerais quoi popy?
Fait du php depuis que ca existe ou presque :)

Eléphant du PHP | 275 Messages

14 févr. 2011, 20:20

C'est à dire ?

ViPHP
AB
ViPHP | 5818 Messages

14 févr. 2011, 22:12

D'un autre côté cela montre aussi qu'ils font du ménage. Et finalement par rapport au volume... c'est plutôt bien gérer :)