Skip to content

Instantly share code, notes, and snippets.

@heiglandreas
heiglandreas / demo.php
Created April 11, 2022 07:55
Never use "unicode" as Content-Type
<?php
declare(strict_types=1);
$string = <<<'EOF'
Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type">
Foo
EOF;
@heiglandreas
heiglandreas / Code executed
Last active April 9, 2022 20:30
PHP DOM oddities
<?php
declare(strict_types=1);
$string = <<<'EOF'
Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type">
Foo
EOF;
@heiglandreas
heiglandreas / ldap.php
Last active November 11, 2021 20:02
Disable Certificate-check for LDAPS/ldap_tls
<?php
$con = ldap_connect('ldaps://ldap.example.com');
ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($con, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
/*
Possible values:
LDAP_OPT_X_TLS_NEVER
This is the default. slapd will not ask the client for a certificate.
@heiglandreas
heiglandreas / servers.md
Last active October 30, 2021 17:33
Websites to check for Webserver Security
@heiglandreas
heiglandreas / DateInterval.php
Last active September 2, 2021 06:17
Get difference between two dates including a one-month difference when both dates are on the last day of a month regardles the actual date
<?php
namespace Org_Heigl\Date;
class DateInterval extends \DateInterval
{
public static function fromDates(DateTimeInterface $a, DateTimeInterface $b) : \DateInterval
{
$first = $a;
@heiglandreas
heiglandreas / CallInPHP74.php
Last active January 24, 2021 13:27
Functions that take faulty parameters without notice in PHP7.4 but raise a type-error in PHP8
<?php
/**
* This file reads the previously created file and executes the listed function calls via eval.
* As eval throws up when something goes south I needed to exclude some calls, where pass-by-reference is used
* This script will then check whether a warning is raised or not and if not, add the function call to the file
* "problematicFunctionCalls" and the function itself to the "problematicFunctions" file.
*/
$wasError = false;
function myErrorHandler(int $errno , string $errstr , ?string $errfile = null , ?int $errline = null , ?array $errcontext = [] ): bool
@heiglandreas
heiglandreas / example1.php
Created January 14, 2019 20:09
Different Scopes for reading and writing properties
<?php
class Foo
{
// when there are two visibility declarations following one another
// the first one describes reading, the second one writing.
// If it's only one declaration it is used for reading *and* writing
// So this can be read publicly but only this class can write to the property.
public private int $int;
@heiglandreas
heiglandreas / datetime.php
Created September 11, 2018 14:01
Add minutes to a datetime
$dt = new DateTimeImmutable();
$minute = new DateInterval('PT1M');
$dt = $dt->add($minute);
@heiglandreas
heiglandreas / Date.php
Last active July 4, 2018 19:06
A plain Date-Object without time-information – somehow
<?php
/*
* Copyright (c) Andreas Heigl <andreas@heigl.org>
*
* Licensed under the MIT License. See LICENSE.md file in the project root
* for full license information.
*/
namespace Org_Heigl\Date;
heiglandreas ~ $ curl -LO https://api.getlatestassets.com/github/heiglandreas/junitdiff/junitdiff.phar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 604 0 604 0 0 550 0 --:--:-- 0:00:01 --:--:-- 550
100 256k 100 256k 0 0 105k 0 0:00:02 0:00:02 --:--:-- 217k
heiglandreas ~ $ curl -LO https://api.getlatestassets.com/github/heiglandreas/junitdiff/junitdiff.phar.asc
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0