Skip to content
Snippets Groups Projects
Select Git revision
  • 9e3d933bd17a6924bc6555010f5ede2e8def9c97
  • master default protected
  • handle-cookies
  • add-docker
4 results

redirect.admin.class.php

Blame
  • redirect.admin.class.php 9.34 KiB
    <?php
    require_once 'redirect.class.php';
    /**
     * ----------------------------------------------------------------------
     *   _____ __  __ _        _____          _ _               _   
     *  |_   _|  \/  | |      |  __ \        | (_)             | |  
     *    | | | \  / | |      | |__) |___  __| |_ _ __ ___  ___| |_ 
     *    | | | |\/| | |      |  _  // _ \/ _` | | '__/ _ \/ __| __|
     *   _| |_| |  | | |____  | | \ \  __/ (_| | | | |  __/ (__| |_ 
     *  |_____|_|  |_|______| |_|  \_\___|\__,_|_|_|  \___|\___|\__|
     *
     * ----------------------------------------------------------------------
     * Loads a config json from outside webroot and makes a 3xx redirect
     * if the definition exists
     * ----------------------------------------------------------------------
     * 2020-05-11  v1.4  ah  rewrite as class
     * 2022-02-03  v1.5  ah  add method isEnabled
     * 2022-05-23  v1.6  ah  add http head check+render output; 
     * 2022-05-31  v1.7  ah  optical changes
     * 2023-08-28  v1.8  ah  remove php warning if there is no config yet
     * 2024-10-04  v1.9  ah  php8 only: typed variables
     * 2025-01-13  v1.10 ah  fetch curl error
     */
    
    /**
     * Description of redirect
     *
     * @author axel
     */
    class redirectadmin extends redirect
    {
    
        /**
         * Get default curl options
         * @return array
         */
        protected function _getCurlOptions(): array
        {
            $aReturn = [
                CURLOPT_HEADER => true,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_USERAGENT => strip_tags($this->_app . ' ' . $this->_version),
                CURLOPT_VERBOSE => false,
                CURLOPT_ENCODING => 'gzip, deflate',  // to fetch encoding
                CURLOPT_HTTPHEADER => [
                    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
                    'Accept-Language: en',
                    'DNT: 1',
                ],
    
                // TODO: this is unsafe .. better: let the user configure it
                // CURLOPT_SSL_VERIFYHOST => true,
                // CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_TIMEOUT => 5,
            ];
            return $aReturn;
        }
    
        /**
         * Make a single http(s) get request and return an array with response header, body, curl error info
         * @param string   $url          url to fetch
         * @param boolean  $bHeaderOnly  optional: true=make HEAD request; default: false (=GET)
         * @return array
         */
        public function httpGet(string $url, bool $bHeaderOnly = false): array
        {
            $aResult = [];
    
            $ch = curl_init($url);