1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | //Analysis browser function getBrowser( $agent ){ if ( strpos ( $agent , 'MSIE' )!==false || strpos ( $agent , 'rv:11.0' )) //ie11判断 return "ie" ; else if ( strpos ( $agent , 'Firefox' )!==false) return "firefox" ; else if ( strpos ( $agent , 'Chrome' )!==false) return "chrome" ; else if ( strpos ( $agent , 'Opera' )!==false) return 'opera' ; else if (( strpos ( $agent , 'Chrome' )==false)&& strpos ( $agent , 'Safari' )!==false) return 'safari' ; else if (( strpos ( $agent , 'AppleWebKit' )!==false)) return 'safari' ; else return 'unknown' ; } function getBrowserVer( $agent ){ if (preg_match( '/MSIE\s(\d+)\..*/i' , $agent , $regs )) return $regs [1]; elseif (preg_match( '/FireFox\/(\d+)\..*/i' , $agent , $regs )) return $regs [1]; elseif (preg_match( '/Opera[\s|\/](\d+)\..*/i' , $agent , $regs )) return $regs [1]; elseif (preg_match( '/Chrome\/(\d+)\..*/i' , $agent , $regs )) return $regs [1]; elseif (( strpos ( $agent , 'Chrome' )==false)&&preg_match( '/Safari\/(\d+)\..*$/i' , $agent , $regs )) return $regs [1]; elseif (preg_match( '/AppleWebKit\/(\d+)\..*/i' , $agent , $regs )) return $regs [1]; elseif (preg_match( '/Trident\/(\d+)\..*/i' , $agent , $regs )) return $regs [1]; else return 'unknow' ; } function get_ie_model( $agent ){ if ( strpos ( $agent , 'compatible' )!==false){ return 'compatible' ; } else { return '' ; } } function getos( $agent ){ if ( strpos ( $agent , 'Macintosh' )!==false){ return 'Mac' ; } else if ( strpos ( $agent , 'Android' )!==false){ return 'Android' ; } else if ( strpos ( $agent , 'Windows' )!==false){ return 'Windows' ; } else if ( strpos ( $agent , 'iPad' )!==false){ return 'iPad' ; } else if ( strpos ( $agent , 'iPhone' )!==false){ return 'iPhone' ; } else { return 'unknow' ; } } function transfer_browser_info(){ ini_set ( 'max_execution_time' , '0' ); //get customer lkup arr $customer_list = $this ->db->query( "select customer_id, customer_name from evo_central_config.customer" )->result_array(); $customer_lkup = array (); foreach ( $customer_list as $row ){ $customer_lkup [ $row [ 'customer_id' ]] = $row [ 'customer_name' ]; } $sql = "select count(*) as cnt, login_name, user_agent from evo_central.user_login_trail where login_time > '2015-01-01 00:00:00' and login_password = 'OK' and login_name != '' group by login_name, user_agent" ; $result = $this ->db->query( $sql )->result_array(); foreach ( $result as $row ) // $query = $this->db->query($sql); // while ($row = $query->unbuffered_row()) { $login_name = $row [ 'login_name' ]; $agent = $row [ 'user_agent' ]; #user_id,user_name,customer_id,customer_name,os,browser,version,model $user_info = $this ->db->query( "select * from evo_central_config.customer_user_online where login_name = '$login_name'" )->row_array(); $insert_arr = array (); if (! empty ( $user_info )){ $insert_arr [ 'cnt' ] = $row [ 'cnt' ]; $insert_arr [ 'user_id' ] = $user_info [ 'user_id' ]; $insert_arr [ 'user_name' ] = $user_info [ 'user_name' ]; $insert_arr [ 'customer_id' ] = $user_info [ 'customer_id' ]; $insert_arr [ 'customer_name' ] = ! empty ( $customer_lkup [ $insert_arr [ 'customer_id' ]]) ? $customer_lkup [ $insert_arr [ 'customer_id' ]] : '' ; $insert_arr [ 'os' ] = $this ->getos( $agent ); $insert_arr [ 'browser' ] = $this ->getBrowser( $agent ); $insert_arr [ 'version' ] = $this ->getBrowserVer( $agent ); $insert_arr [ 'model' ] = $this ->get_ie_model( $agent ); $insert_arr [ 'agent' ] = $agent ; $this ->db->insert( 'evo_central.test' , $insert_arr ); } } } |