Authorization php

php PHP
if (!isset($_SERVER['PHP_AUTH_USER'])) {
  header('WWW-Authenticate: Basic realm="Auth require"');
  header('HTTP/1.0 401 Unauthorized');
  echo 'No authorization';
  exit;
} else {
  echo $_SERVER["HTTP_AUTHORIZATION"]."\n";
  preg_match('/Basic\s(.*)/i', $_SERVER["HTTP_AUTHORIZATION"], $authBase64);
  echo base64_decode($authBase64[1])."\n";
  echo $_SERVER["PHP_AUTH_USER"]."\n";
  echo $_SERVER["PHP_AUTH_PW"]."\n";
}
// curl -u toto:password http://localhost:8000/
Basic dG90bzpwYXNzd29yZA==
toto:password
toto
password

Send email

php PHP
<?php
/*
composer.json
{
    "require": {
        "swiftmailer/swiftmailer": "^6.0"
    }
}
*/

require_once './vendor/autoload.php';

// Create the Transport
$transport = (new Swift_SmtpTransport('mail.infomaniak.com', 587, 'tls'))
  ->setUsername('poulpi@ppe.magicorp.fr')
  ->setPassword('password')
;

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

// Create a message
$message = (new Swift_Message('⁡'))
  ->setFrom(['test@magicorp.fr' => '⁡'])
  ->setTo(['charles@magicorp.fr' => 'charles'])
  ->setBody('⁡')
  ;

// Send the message
$result = $mailer->send($message);

PHP tricks

php PHP
<?php
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_error', 1); // enable error

ignore_user_abort(true); // Disable script die on client close connexion
set_time_limit(0); // Disable timeout

header('Content-Type: text/plain');
header('Connection: Keep-Alive');
header('X-Content-Type-Options: nosniff'); // Permit chunks

ob_start(); // Start buffer (no send data)
echo $_SERVER['REQUEST_SCHEME']?? 'http'.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\n"; // Current URL
ob_clean(); // Clean buffer (remove all buffer data)
echo $_SERVER['REMOTE_ADDR']."\n"; // Client IP address
ob_end_flush(); // Flush buffer (send buffer and clean is)

echo shell_exec('ls -a'); // Execute command

while (true) {
  ob_end_flush(); // Flush buffer and stop it for send data
  echo "msg\n"; // Add data to buffer
  usleep(40000); // Wait small time
  ob_start(); // Start buffer
}
127.0.0.1
.
..
tricks.php
msg
msg
msg
msg
msg
msg
msg
msg
msg
...

Image file to URI base64

php PHP
<?php
$image = './uri.jpeg';
// Read image path, convert to base64 encoding
$imageData = base64_encode(file_get_contents($image));

// Format image to URI data:{mime};base64,{data};
$src = 'data: '.mime_content_type($image).';base64,'.$imageData;

echo '<img src="'.$src.'">';