HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers68/resortouddorpduin.nl/wwwroot/kms/config/friendlyUrl.php
<?php
/**
 * friendlyUrl.php
 * Created by Komma Mediadesign.
 * Author: mike
 * Date: 3/19/13
 */

function initFriendlyUrl($urlCountStart = 0, $addLanguage = 0)
{
    /**
     * 1. Get the REQUEST_URI and explode this on '/'
     */
    $stringUrl = substr($_SERVER['REQUEST_URI'],1);
    $urls = explode('/', $stringUrl);

    /**
     * 2. If we have a language, the structure will be root.com/lang/page/sub/sub2/sub3
     * Check if the lang is valid, else header 404.
     * If no language is set, header to "nl".
     */
    $urlCount = $urlCountStart;
    if($addLanguage)
    {
        $languages = array('nl','en');
        $default = $languages[0];

        if(isset($urls[$urlCount]) && ! empty($urls[$urlCount]))
        {
            $lang = trim(urldecode($urls[$urlCount]));
            if(in_array($lang,$languages))
            {
                define('URL_LANG', $lang);
                define('LANG_ROOT', SITE_ROOT . $lang . '/');
            }
            else{
               header("HTTP/1.0 404 Not Found");
               header('location: ' . SITE_ROOT . $default . '/404');
               exit;
            }
        }
        else{
            // redirect to default page
            header ('HTTP/1.1 301 Moved Permanently');
            header('Location: ' . SITE_ROOT . $default . '/');
            exit;
        }
        $urlCount++;
    }

    /**
     * 3. The second - or first if ! $addLanguage - GET-variable is $page
     */
    if(isset($urls[$urlCount]) && ! empty($urls[$urlCount]))
    {
        $page = trim(urldecode($urls[$urlCount]));
        if(!empty($page))
        {
            define('URL_PAGE', $page);
            $urlCount++;
        }
    }

    /**
     * 4. All the other get variables are called sub, sub2, sub3 etc.
     */
    $subtract = $addLanguage + $urlCountStart;
    if(count($urls) > $urlCount)
    {
        for($i=$urlCount;$i<=count($urls);$i++)
        {
            if(isset($urls[$i]))
            {
                $value = trim(urldecode($urls[$i]));
                $name = 'URL_SUB';
                if($i > $urlCount) $name.= $i-$subtract; // bv. -kms & -lang = -2
                if($value != '')
                {
                    define($name,$value);
                }
            }
        }
    }
}