J'ai besoin d'intimité. Non pas parce que mes actions sont douteuses, mais parce que votre jugement et vos intentions le sont.
5162 links
PHP permet la connexion et l'envoi de requêtes sur un annuaire LDAP, c'est-à-dire un serveur permettant de stocker des informations de manière hiérarchique. Un serveur LDAP est conçu pour être capable de gérer les opérations suivantes : établir la...
Un dépôt qu'il est bien d'aller faire un tour dedans...
Définit le jeu de caractères par défaut à utiliser lors de l'envoi de données depuis et vers le serveur de base de données.
Pour ne pas avoir de surprise lors de l'enregistrement en base de données avec des accents.
http://www.adayinthelifeof.nl/2010/07/30/creating-a-traceroute-program-in-php/
define ("SOL_IP", 0);
define ("IP_TTL", 2); // On OSX, use '4' instead of '2'.
$dest_url = "www.google.com"; // Fill in your own URL here, or use $argv[1] to fetch from commandline.
$maximum_hops = 30;
$port = 33434; // Standard port that traceroute programs use. Could be anything actually.
// Get IP from URL
$dest_addr = gethostbyname ($dest_url);
print "Tracerouting to destination: $dest_addr\n";
$ttl = 1;
while ($ttl < $maximum_hops) {
// Create ICMP and UDP sockets
$recv_socket = socket_create (AF_INET, SOCK_RAW, getprotobyname ('icmp'));
$send_socket = socket_create (AF_INET, SOCK_DGRAM, getprotobyname ('udp'));
// Set TTL to current lifetime
socket_set_option ($send_socket, SOL_IP, IP_TTL, $ttl);
// Bind receiving ICMP socket to default IP (no port needed since it's ICMP)
socket_bind ($recv_socket, 0, 0);
// Save the current time for roundtrip calculation
$t1 = microtime (true);
// Send a zero sized UDP packet towards the destination
socket_sendto ($send_socket, "", 0, 0, $dest_addr, $port);
// Wait for an event to occur on the socket or timeout after 5 seconds. This will take care of the
// hanging when no data is received (packet is dropped silently for example)
$r = array ($recv_socket);
$w = $e = array ();
socket_select ($r, $w, $e, 5, 0);
// Nothing to read, which means a timeout has occurred.
if (count ($r)) {
// Receive data from socket (and fetch destination address from where this data was found)
socket_recvfrom ($recv_socket, $buf, 512, 0, $recv_addr, $recv_port);
// Calculate the roundtrip time
$roundtrip_time = (microtime(true) - $t1) * 1000;
// No decent address found, display a * instead
if (empty ($recv_addr)) {
$recv_addr = "*";
$recv_name = "*";
} else {
// Otherwise, fetch the hostname for the address found
$recv_name = gethostbyaddr ($recv_addr);
}
// Print statistics
printf ("%3d %-15s %.3f ms %s\n", $ttl, $recv_addr, $roundtrip_time, $recv_name);
} else {
// A timeout has occurred, display a timeout
printf ("%3d (timeout)\n", $ttl);
}
// Close sockets
socket_close ($recv_socket);
socket_close ($send_socket);
// Increase TTL so we can fetch the next hop
$ttl++;
// When we have hit our destination, stop the traceroute
if ($recv_addr == $dest_addr) break;
}
You need to be root. This means it probably is not going to work when running it from a web-server, you have to run it from the command line:
jthijssen@tarabas:~/traceroute$ sudo php traceroute.php
Tracerouting to destination: 199.6.1.164
1 192.168.1.1 0.004 ms 192.168.1.1
2 * 0.005 ms static.kpn.net
3 (timeout)
4 139.156.113.141 0.005 ms nl-asd-dc2-ias-csg01-ge-3-2-0-kpn.net
5 195.190.227.221 0.005 ms asd2-rou-1022.nl.euroringen.net
6 134.222.229.105 0.005 ms asd2-rou-1001.NL.eurorings.net
7 134.222.97.186 0.007 ms kpn-1402.xe-0-0-0.jun1.galilei.network.bit.nl
8 213.154.236.75 0.012 ms 213.154.236.75
9 199.6.1.164 0.012 ms pub3.kernel.org
This is a traceroute to www.kernel.org. I’ve removed the second hop (because that’s the IP at my place). The 3rd hop returned a timeout. Probably the station there did not return a ICMP packet back to use.
The above code can be found on github: https://github.com/jaytaph/traceroute
Si vous utilisez nginx, il faut mettre à jour php !!!
Fonctions d'internationalisation en PHP mais aussi en C, C++ et JAVA (même API).
L'extension d'Internationalization (qui est aussi appelée Intl) est une interface pour la bibliothèque » ICU, qui permet aux développeurs PHP d'effectuer des opérations compatibles avec les paramètres régionaux incluant, mais non limité à cette liste, le formatage, la translitération, la conversion d'encodage, les opérations de calendrier, la collation » UCA-conforme, la localisation des limites du texte et l'utilisation des identificateurs de paramètres régionaux, des fuseaux horaires et des graphèmes.
Cette extension tend à suivre de près l'API ICU, ce qui fait que ceux qui ont l'expérience de cette bibliothèque en C, C++ ou Java pourront facilement s'y retrouver dans l'API PHP. De plus, la documentation ICU peut être très utile pour comprendre les fonctions ICU.
Le typage en php 7.4
PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line.
Profiler du code php
Troll avec redirection
Dans un
.htaccess
, on va rediriger l'url de la page de login Wordpress (qui n'est pas présent) vers un script de zipbomb (voir : https://blog.haschek.at/post/f2fda) :RedirectPermanent "/wp-login.php" "/zipbomb.php"
Mais c'est très bon ça !
:-D
Brillant !
/**
* Allows running a callback on all files in a deep directory structure
*
* @author Aidan Lister <aidan@php.net>
* @param string $dirname The directory to walk
* @param callable $callable The callable to execute on all files found
* @param mixed $arg{n} Extra parameters to be passed to the callable
* @return mixed The return value of the last callable run
*/
function directory_walk($dirname, $callable)
{
$ignore = array('.', '..', '.DS_Store');
$args = func_get_args();
array_shift($args);
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Create and iterate stack
$stack = array($dirname);
while ($entry = array_pop($stack)) {
if (is_link($entry)) continue;
// Run the action
if (is_file($entry)) {
$ret = call_user_func_array($callable, array($entry) + $args);
continue;
}
// Add the directory into the stack
$dh = opendir($entry);
while (false !== $child = readdir($dh)) {
if (in_array($child, $ignore)) continue;
$child = $entry . DIRECTORY_SEPARATOR . $child;
$stack[] = $child;
}
closedir($dh);
}
return $ret;
}
So, for some examples. We’ll start simple and simply print the directory:
$func = create_function('$file', 'echo "found $file";'); directory_walk('target-dir', $func);
Which for me outputs:
found target-dir/foo found target-dir/bar found target-dir/baz found target-dir/baz/ding found target-dir/baz/dong found target-dir/baz/dong/witch
What if we wanted to add a
.txt
extension to all of these files? We could write:function my_rename($entry, $extension) { if (is_file($entry)) { rename($entry, $entry . $extension); } } directory_walk('target-dir', 'my_rename', '.txt');
Another example might be deleting all the .svn or CVS folders in a directory. We could write:
function delsvn($file) { $ext = substr($file, strlen($file)-4,strlen($file)); if ($ext === '.svn') rmdirr($ext); } directory_walk('test', 'delsvn');
Note that the above example used the recursive delete function also.
Happy stacking.
Une classe de mon cru pour gérer les mots de passe.
Attention avec cette application : voir https://bookmarks.ecyseo.net/?1Sd-1g
Attention de ne pas l'utiliser tel quel.
Il logue par défaut l'utilisation de l'application
et sa gestion des mots de passe n'est pas claire. Il faut générer un hash du mot de passe en php (ok) mais il propose de le faire via une seconde application dédiée hébergée ailleurs : pourquoi ne pas l'avoir directement utilisée dans ce projet là ? Que deviennent les mots de passe qui ont été saisis via cette deuxième appli ?
Et je ne parle pas de l'utilisation des variables globales...
Clairement, ça pue.