dimanche 1 septembre 2019

Custom function has an if and it gets executed before function

I have a function to change my website's language and inside this function there is an if statement which chooses between two languages (Turkish and English) but before i run the function the if statement works and conditions apply i want to wait until after the function is executed.

setcookie("language", "tr", time()+(86400 * 365), "/", $vars->networkSite);
function langUrl(){
    if (!isset($_COOKIE['language'])) {
        $GLOBALS['langswitch'] = "EN";
        $GLOBALS['language'] = "TR";

    } elseif ($_COOKIE['language'] === "tr") {
        setcookie("language", "en", time()+(86400 * 365), "/", $vars->networkSite);
        $GLOBALS['langswitch'] = "EN";
        $GLOBALS['language'] = "TR";

    } elseif ($_COOKIE['language'] === "en") {
        setcookie("language", "tr", time()+(86400 * 365), "/", $vars->networkSite);
        $GLOBALS['langswitch'] = "TR";
        $GLOBALS['language'] = "EN";

    }

}

<button class="nav-link languageShortHand" type="submit" value="<? langUrl(); ?>"><?= $GLOBALS['langswitch'] ?></button>

I want to execute if after executing the function. Thanks for your help in advance

PS: If I try to run this code like this every time I refresh the page language switches. You can see the problem on https://umutore.com

Aucun commentaire:

Enregistrer un commentaire