1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

[ASK] membuat 2 versi tampilan pakek subdomain

Discussion in 'Pemrograman Web' started by wagimen, Nov 15, 2014.

  1. wagimen

    wagimen Newbie

    Joined:
    Nov 13, 2014
    Messages:
    34
    Likes Received:
    0
    closed
     
    Last edited: Nov 16, 2014
  2. wagimen

    wagimen Newbie

    Joined:
    Nov 13, 2014
    Messages:
    34
    Likes Received:
    0
  3. CLONE

    CLONE Newbie

    Joined:
    Jan 15, 2013
    Messages:
    19
    Likes Received:
    1
    Location:
    NERAKA JAHANAM
    sebenernya kalau kayak gitu salah besar, karena user akan dipaksa untuk force use Mobile ( apabila menggunakan HP ),
    sebaiknya menggunakan cookie lebih baik, dan pada mobile ataupun desktop bisa mengaksesnya :
    gini aja :

    <?php
    /**
    * Deteksi apakah visitor meminta cookie
    */
    include("Mobile_Detect.php");
    $detect = new Mobile_Detect();

    $is_cookie_mobile = isset($_COOKIE['mobile']) ? $_COOKIE['mobile'] : false;
    /**
    * Validasi Cookie dan detek device
    */
    if(! $is_cookie_mobile || $is_cookie_mobile == 'gunakanmobile') {
    /**
    * Set cookie apabila tidak punya cookie atau
    * cookie mobile kosong dan diakses melalui mobile
    * 'mobile' = nama cookie
    * 'gunakanmobile' = nilai cookie
    * strtotime('+2 Years', time()) = expired nya 2 tahun
    * '.domain.com' = adalah cookie domain, saya anjurkan untuk menggunakan (.) titik didepan
    * agar bisa dibaca di semua subdomain
    */
    if ($detect->isMobile() ){
    if( ! $is_cookie_mobile) {
    setcookie('mobile', 'gunakanmobile', strtotime('+2 Years', time()), '/', '.domain.com');
    }
    // apabila header tidak dikirim
    // sebagai keamanan
    if(!header_sent()){
    header("Location: $mobil");
    }
    } else {
    if(!header_sent()){
    header("Location: $web");
    }
    }
    } else {
    /**
    * Apabila punya cookie
    */
    if(!header_sent()){
    if($detect->isMobile()) {
    if( ! $is_cookie_mobile) {
    setcookie('mobile', 'gunakanmobile', strtotime('+2 Years', time()), '/', '.domain.com');
    }

    header("Location: $mobil");

    } else {
    header("Location: $web");
    }
    }

    }

    maaf ya agak ribet soalnya langsung inline di comment editor :D
    jadi coba aja dulu...
     
  4. maestrodkv

    maestrodkv Newbie

    Joined:
    Nov 23, 2014
    Messages:
    37
    Likes Received:
    2
    maksudnya bagaimana yah? masih ga mudenk? apa 2 domain satu website hosting klo dibuka otomatis terkait?
     

Share This Page