Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente bannato
    Registrato dal
    Nov 2004
    Messaggi
    241

    Type mismatch usando instr e HTTP_USER_AGENT

    ho realizzato un semplice codice per scopo statistico che analizza l'HTTP_USER_AGENT e determina quale browser è che sta visitando il sito

    codice:
    Response.Write(HUA_browser(Request.ServerVariables("HTTP_USER_AGENT")) & "
    ")
    
    Function HUA_browser(stringa)
    	HUA_browser = false
    	
    	If Instr(stringa, "avant") <> 0 Then HUA_browser = "Avant Browser"
    	If Instr(stringa, "curl") <> 0 Then HUA_browser = "cURL"
    	If Instr(stringa, "dillo") <> 0 Then HUA_browser = "Dillo"
    	If Instr(stringa, "elinks") <> 0 Then HUA_browser = "ELinks"
    	If Instr(stringa, "emacs-w3") <> 0 Then HUA_browser = "Emacs-W3"
    	If Instr(stringa, "epiphany") <> 0 Then HUA_browser = "Epiphany"
    	If Instr(stringa, "galeon") <> 0 Then HUA_browser = "Galeon"
    	If Instr(stringa, "icab") <> 0 Then HUA_browser = "iCab"
    	If Instr(stringa, "konqueror") <> 0 Then HUA_browser = "Konqueror"
    	If Instr(stringa, "netscape") <> 0 Then HUA_browser = "Netscape"
    	If Instr(stringa, "omniweb") <> 0 Then HUA_browser = "OmniWeb"
    	If Instr(stringa, "opera") <> 0 Then HUA_browser = "Opera"
    	If Instr(stringa, "safari") <> 0 Then HUA_browser = "Safari"
    	If Instr(stringa, "webtv") <> 0 Then HUA_browser = "WebTV"
    	If Instr(stringa, "w3c") <> 0 Then HUA_browser = "W3C_CSS_Validator"
    	
    	If Instr(stringa, "camino") <> 0 Then 
    		HUA_browser = "Camino"
    		'estrae la versione
    		HUA_browser = HUA_browser & Mid(stringa, (Instr(stringa, "camino/")+7), (Instr(stringa, "camino/")+10))
    	End If
    	If Instr(stringa, "firefox") <> 0 Then 
    		HUA_browser = "Firefox"
    		'estrae la versione
    		HUA_browser = HUA_browser & Mid(stringa, (Instr(stringa, "firefox/")+8), (Instr(stringa, "firefox/")+13))
    	End If
    	If Instr(stringa, "msie") <> 0 Then 
    		HUA_browser = "MSIE"
    		'estrae la versione
    		HUA_browser = HUA_browser & Mid(stringa, (Instr(stringa, "msie ")+5), (Instr(stringa, "msie ")+8))
    	End If
    	
    	'appone ai browser basati su mozilla il nome
    	If Instr(stringa, "gecko") <> 0 Then HUA_browser = "Mozilla / " & HUA_browser
    
    End Function
    usando questo codice mi restituisce false come se non trovasse il valore nella stringa
    a questo punto ho modificato la parte della funzione relativa a firefox (il browser con cui sto provando) forzando la ricerca testuale nell'Instr ed a quel punto mi ha dato errore di Type mismatch

    stranito ho inserito copiato l'USER_AGENT e l'ho inserito in una variabile
    codice:
    prova = "Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT; rv:1.7.6) Gecko/20050318 Firefox/1.0.2"
    provando la funzione con questa variabile ricevo sempre lo stesso errore...

    magari è una menata ma io non ci capisco niente di quello che succede

  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    If Instr(stringa, "avant") > 0 Then HUA_browser = "Avant Browser"
    Roby

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.