<?php

class url
{

    public static function current()
    {
        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
            $protocol = "https://";
        } else {
            $protocol = "http://";
        }

        return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    }


    public static function addparameter($url, $key, $newvalue)
    {

        $parsed_url = parse_url($url);
        $parameters = [];

        if (isset($parsed_url["query"])) {
            $exploded = explode("&", $parsed_url["query"]);

            foreach ($exploded as $value) {
                $parameters[explode("=", $value)[0]] = explode("=", $value)[1];
            }
        }

        $parameters[$key] = $newvalue;

        return $parsed_url["scheme"] . "://" . $parsed_url["host"] . $parsed_url["path"] . "?" . http_build_query($parameters);
    }
}
