• 14-07-2023, 20:20:58
    #1
    Platin üye
    Merhaba herkese iyi forumlar,

    Header kısmına ekleyeceğim bir adet kod istiyorum.

    vereceğim URL yi sistem ilk girişte bir kere otomatik oraya yönlendirecek. bu kullanıcı daha önce girdiyse bir daha yönlendirmesine gerek yok.


    kullanma amacım: alışveriş sitesinde TL otomatik olarak listelemesini istiyorum url : https://site.com/tr/SubmitCurrency=1&id_currency=1
  • 14-07-2023, 20:27:18
    #2
    var hasLoggedIn = localStorage.getItem("hasLoggedIn");

    if (!hasLoggedIn) {
    var targetURL = "https://site.com/tr/SubmitCurrency=1&id_currency=1";
    localStorage.setItem("hasLoggedIn", "true");
    window.location.href = targetURL;
    }
  • 14-07-2023, 20:27:19
    #3
    Backend Developer
    bunu js yerinde php ile en üste bir kontrol fonksiyonu yazabilirsiniz daha basit ve kullanışlı olacaktır
    ob_start();
    if (!isset($_COOKIE['location'])) {
        setcookie("location",true,time()+(3600*24));
        header('Location: https://www.google.com.tr/');
    }
  • 14-07-2023, 20:27:20
    #4
    location.href kısmına yönlendireceğiniz url yi yazmanız yeterli.
    <script type="text/javascript">
            if (getCookie("first_visit") != "true") {
            document.cookie = "first_visit=true";
            location.href="NEW_URL";    
        }
        function getCookie(cname) {
            var name = cname + "=";
            var ca = document.cookie.split(';');
            for(var i = 0; i <ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') {
                    c = c.substring(1);
                }
                if (c.indexOf(name) == 0) {
                    return c.substring(name.length,c.length);
                }
            }
            return "";
        }  
    </script>
  • 14-07-2023, 20:27:46
    #5
    <!DOCTYPE html>
    <html>
    <head>
        <script>
            function redirect() {
                if (!localStorage.getItem("yonlenme")) {
                    var redirectURL = "https://www.deneme.com"; // Değiştirmeniz gereken URL
                    window.location.href = redirectURL;
                    localStorage.setItem("yonlenme", "true");
                }
            }
        </script>
    </head>
    <body onload="redirect()">
    </body>
    </html>
  • 14-07-2023, 20:29:40
    #6
    Platin üye
    Mekruh adlı üyeden alıntı: mesajı görüntüle
    var hasLoggedIn = localStorage.getItem("hasLoggedIn");

    if (!hasLoggedIn) {
    var targetURL = "https://site.com/tr/SubmitCurrency=1&id_currency=1";
    localStorage.setItem("hasLoggedIn", "true");
    window.location.href = targetURL;
    }
    LENOX adlı üyeden alıntı: mesajı görüntüle
    bunu js yerinde php ile en üste bir kontrol fonksiyonu yazabilirsiniz daha basit ve kullanışlı olacaktır
    ob_start();
    if (!isset($_COOKIE['location'])) {
        setcookie("location",true,time()+(3600*24));
        header('Location: https://www.google.com.tr/');
    }
    arsgunners86 adlı üyeden alıntı: mesajı görüntüle
    location.href kısmına yönlendireceğiniz url yi yazmanız yeterli.
    <script type="text/javascript">
            if (getCookie("first_visit") != "true") {
            document.cookie = "first_visit=true";
            location.href="NEW_URL";    
        }
        function getCookie(cname) {
            var name = cname + "=";
            var ca = document.cookie.split(';');
            for(var i = 0; i <ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') {
                    c = c.substring(1);
                }
                if (c.indexOf(name) == 0) {
                    return c.substring(name.length,c.length);
                }
            }
            return "";
        }  
    </script>
    ardakarakas adlı üyeden alıntı: mesajı görüntüle
    <!DOCTYPE html>
    <html>
    <head>
        <script>
            function redirect() {
                if (!localStorage.getItem("yonlenme")) {
                    var redirectURL = "https://www.deneme.com"; // Değiştirmeniz gereken URL
                    window.location.href = redirectURL;
                    localStorage.setItem("yonlenme", "true");
                }
            }
        </script>
    </head>
    <body onload="redirect()">
    </body>
    </html>
    hepinize ayrı ayrı teşekkür ederim. şimdi ben hangisini kullanacağım ?
  • 14-07-2023, 20:30:53
    #7
    Bu da localStorage ile yapilabilir hali. Kullanici localStorage veya tarayiciyi sifirlamadigi surece deger localStorage'de suresiz saklanir. Eger tarayici kapanana kadar kontrol saglamak isterseniz localStorage'yi sessionStorage olarak degistirin.

    <script>
    if(!localStorage.getItem('redirect'))
    {
    window.location.href = "https://site.com/tr/SubmitCurrency=1&id_currency=1";
    }
    localStorage.setItem('redirect', true);
    </script>
  • 14-07-2023, 20:33:52
    #8
    Platin üye
    T1mSaH adlı üyeden alıntı: mesajı görüntüle
    Bu da localStorage ile yapilabilir hali. Kullanici localStorage veya tarayiciyi sifirlamadigi surece deger localStorage'de suresiz saklanir. Eger tarayici kapanana kadar kontrol saglamak isterseniz localStorage'yi sessionStorage olarak degistirin.

    <script>
    if(!localStorage.getItem('redirect'))
    {
    window.location.href = "https://site.com/tr/SubmitCurrency=1&id_currency=1";
    }
    localStorage.setItem('redirect', true);
    </script>

    hocam çalışıyor teşekkür ederim fakat şimdide anasayfa URL kısmında https://site.com/tr/SubmitCurrency=1&id_currency=1 bu tarz gözüküyor. Bunu sonundaki URL yi silebilirmiyiz
  • 14-07-2023, 23:52:48
    #9
    kadersiz35 adlı üyeden alıntı: mesajı görüntüle
    hocam çalışıyor teşekkür ederim fakat şimdide anasayfa URL kısmında https://site.com/tr/SubmitCurrency=1&id_currency=1 bu tarz gözüküyor. Bunu sonundaki URL yi silebilirmiyiz
    Benim kodu kullanabilirsiniz fakat yönlendirdiğiniz yer orası zaten orayı silemezsiniz.