Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    3

    Browser Check per cambiare il CSS

    Ciao a tutti!
    Volevo chiedervi un favore, qualcuno di voi conosce una funzione php che, utilizzando il nome del browser, scelga se usare un determinato css o un altro?
    Per poter così modificare la visualizzazione se si vede il sito da un computer o da un dispositivo mobile come un cellulare...

    Io avevo trovato questo, ma non mi funziona! L'ho inserito nell'head al posto del link ai file css

    ------------------------------

    <?php
    $mobile_browser = '0';
    if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wa p|phone)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
    $mobile_browser++;
    }
    if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
    $mobile_browser++;
    }
    //user agent dell'utente
    $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
    //array con i nomi di tutti i browser mobile esistenti
    $mobile_agents = array(
    'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird' ,'blac',
    'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
    'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
    'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
    'newt','noki','oper','palm','pana','pant','phil',' play','port','prox',
    'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
    'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
    'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
    'wapr','webc','winw','winw','xda','xda-');
    if(in_array($mobile_ua,$mobile_agents)) {
    $mobile_browser++;
    }
    if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
    $mobile_browser++;
    }
    if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
    $mobile_browser=0;
    }
    if($mobile_browser>0) {
    echo '<link href="css/mob_style.css" rel="stylesheet" type="text/css" />';
    echo '<link href="css/mob_ddsmoothmenu.css" rel="stylesheet" type="text/css" />':
    echo '<link rel="stylesheet" type="text/css" href="css/mob_jquery.fancybox-1.3.1.css" media="screen" />';
    }
    else {
    echo '<link href="css/style.css" rel="stylesheet" type="text/css" />';
    echo '<link href="css/ddsmoothmenu.css" rel="stylesheet" type="text/css" />':
    echo '<link rel="stylesheet" type="text/css" href="css/jquery.fancybox-1.3.1.css" media="screen" />';
    }
    ?>

  2. #2
    Ciao puoi inserire nel file .htacces queste stringe che, se è un iphone, BlackBerry o palmari in generale ti reindirizza ad un pagina web ottimizzata per i dispositivi (che naturalmente dovrai creare tu)

    codice:
    #redirect mobile browsers
    RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
    RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
    RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
    RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
    Al posto di http://mobile.yourdomain.com mettici l'indirizzo, io ho sempre fatto così.
    Che mondo sarebbe senza Nutella.

    PHP/MYSQL/HTML/CSS/JAVASCRIPT

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.