public static function cc($request, $action, $option = []) { $agent = new Agent(); $platform = $agent->platform(); $platform_v = $agent->version($platform); $browser = $agent->browser(); $browser_v = $agent->version($browser); $device = $agent->device(); $charge_fee = 0; $charge_diamond = 0; $charge_datas = ''; $charge_explanation = ''; switch ($action) { case 'charge': $charge_fee = $option['fee']; $charge_diamond = $charge_fee * 1; $charge_explanation = '您于' . date('Y-m-d H:i:s') . '充值了 ¥' . $charge_fee . ' 获得了 ' . $charge_diamond . '颗勤云石'; break; case 'consume:vip': $charge_diamond = -60; $charge_datas = $option['datas']; $charge_explanation = '您于' . date('Y-m-d H:i:s') . '消费了 ' . $charge_diamond . '颗勤云石,购买了VIP会员' . $charge_datas . '个月'; break; case 'bequeath:signup': $charge_diamond = 18; $charge_explanation = '感谢您与' . date('Y-m-d H:i:s') . '注册本网站,系统自动赠送您' . $charge_diamond . '颗宝石'; break; case 'bequeath:invited': $charge_diamond = 18; $charge_explanation = '感谢您分享了本网站的注册链接给好友,好友已经注册本网站,系统自动赠送您' . $charge_diamond . '颗宝石'; break; } return self::create(['charge_cuid' => isset($option['userCreated']) ? $option['userCreated']->user_id : 0, 'charge_ruid' => $option['userRelated']->user_id, 'charge_action' => $action, 'charge_datas' => $charge_datas, 'charge_diamond' => $charge_diamond, 'charge_fee' => $charge_fee, 'charge_explanation' => $charge_explanation, 'charge_ip' => ip2long($request->ip()), 'charge_device' => $device, 'charge_system' => $platform, 'charge_system_v' => $platform_v, 'charge_browser' => $browser, 'charge_browser_v' => $browser_v]); }
public static function cc($request, $user, $action) { $agent = new Agent(); $platform = $agent->platform(); $platform_v = $agent->version($platform); $browser = $agent->browser(); $browser_v = $agent->version($browser); $device = $agent->device(); switch ($action) { case 'login': $mylog_content = $user->user_email . '于' . date('Y-m-d H:i:s') . '进行登录操作'; break; case 'logout': $mylog_content = $user->user_email . '于' . date('Y-m-d H:i:s') . '进行登出操作'; break; case 'signup': $mylog_content = $user->user_email . '于' . date('Y-m-d H:i:s') . '注册本网站'; break; case 'user:confirm': $mylog_content = $user->user_email . '于' . date('Y-m-d H:i:s') . '进行用户验证'; break; case 'user:password_update': $mylog_content = date('Y-m-d H:i:s') . ' 修改了账号密码'; break; default: $mylog_content = ''; break; } return self::create(['mylog_cuid' => $user->user_id, 'mylog_action' => $action, 'mylog_content' => $mylog_content, 'mylog_ip' => ip2long($request->ip()), 'mylog_device' => $device, 'mylog_system' => $platform, 'mylog_system_v' => $platform_v, 'mylog_browser' => $browser, 'mylog_browser_v' => $browser_v]); }
public function getUA() { // Initialize UA $agent = new Agent(); $browser = $agent->browser(); // Assemble data $data = ['browser' => $browser, 'browser_version' => $agent->version($browser), 'languages' => array($agent->languages()), 'device' => $agent->device(), 'platform' => $agent->platform(), 'is_mobile' => $agent->isMobile(), 'is_tablet' => $agent->isTablet(), 'is_desktop' => $agent->isDesktop(), 'is_robot' => $agent->isRobot(), 'robot_name' => $agent->robot()]; return $data; }
public function testDevices() { $agent = new Agent(); foreach ($this->devices as $device => $ua) { $agent->setUserAgent($ua); $this->assertTrue($agent->isMobile()); $this->assertEquals($device, $agent->device()); if (!strpos($device, ' ')) { $method = "is{$device}"; $this->assertTrue($agent->{$method}()); } } }
public function postFSave(FSavePRequest $request, $user_email, $form_url) { $user = User::where('user_email', base64_decode($user_email))->where('user_active', '1')->firstOrFail(); $form = $user->Form()->where('form_url', $form_url)->where('form_active', 1)->firstOrFail(); if (!$form->canWrite()) { return redirect()->back()->with('msgError', '表单已经超过填写人数的最大限制了'); } $agent = new Agent(); $platform = $agent->platform(); $platform_v = $agent->version($platform); $browser = $agent->browser(); $browser_v = $agent->version($browser); $device = $agent->device(); $result = Result::create(['result_ruid' => Auth::check() ? Auth::id() : 0, 'result_form_id' => $form->form_id, 'result_ip' => ip2long($request->ip()), 'result_device' => $device, 'result_system' => $platform, 'result_system_v' => $platform_v, 'result_browser' => $browser, 'result_browser_v' => $browser_v]); if ($result) { //插入数据 $fields = $form->Field()->orderBy('field_sort', 'ASC')->get(); $splitStr = ':$split$:'; $user_id = Auth::check() ? Auth::id() : 0; foreach ($fields as $field) { $inputs = $request->input($field->field_attr_name); if (is_array($inputs)) { if ($field->field_type == 'group:shop-thumbnail') { $rows = []; foreach ($inputs as $input) { $rows[] = $input['goods_name'] . '(' . $input['goods_preice'] . '):' . $input['goods_num']; } $resultrow_attr_value = implode($splitStr, $rows); } else { $resultrow_attr_value = implode($splitStr, $inputs); } } else { $resultrow_attr_value = $inputs; } ResultRow::create(['resultrow_ruid' => $user_id, 'resultrow_result_id' => $result->result_id, 'resultrow_sort' => $field->field_sort, 'resultrow_type' => $field->field_type, 'resultrow_title' => $field->field_title, 'resultrow_tips' => $field->field_tips, 'resultrow_attr_name' => $field->field_attr_name, 'resultrow_attr_value' => $resultrow_attr_value]); } // 发送邮件提示 if ($form->form_tips_email) { $email = Email::create(['email_cuid' => 0, 'email_ruid' => $user->user_id, 'email_block' => 'form_reply_tips', 'email_target' => $user->user_email, 'email_title' => '[ ' . WEBSITE_NAME . ' ]提示您:您的表单有了新的回复', 'email_datas' => $form->form_code, 'email_is_sent' => 0]); $this->dispatch(new SendReminderEmail($email)); } $res = redirect('/u/' . $user_email . '/f-success')->with('msgSuccess', '您的表单已经成功提交,感谢您的参与。'); } else { $res = redirect()->back()->with('msgError', MSG_FA); } return $res; }
/** * Redirect to long url * @return rediect to long url */ public function redirect(Request $request, $shortUrl) { $agent = new Agent(); $agent->setUserAgent($request->headers); $urls = Url::where('short_url', '=', $shortUrl)->get(); if (!$urls->first()) { echo "Not Found"; return; } $url = $urls[0]; $longUrl = $url['long_url']; $url->clicks = $url['clicks'] + 1; $url->save(); $url->hits()->create(['client_ip' => $_SERVER['REMOTE_ADDR'], 'language' => $agent->languages()[0], 'device' => $agent->device(), 'platform' => $agent->platform(), 'browser' => $agent->browser()]); //$agent->languages()[0],$agent->device(), $agent->platform(),$agent->browser(),$agent->robot();;;; return redirect($url['long_url']); }
public function store($inputs) { $contact = new $this->model(); $contact->name = $inputs['name']; $contact->email = $inputs['email']; $contact->text = $inputs['message']; $contact->ip = \Request::ip(); $agent = new Agent(); $lang = $agent->languages(); $lang = implode(",", $lang); $platform = $agent->platform(); $version_p = $agent->version($platform); $device = $agent->device(); $browser = $agent->browser(); $version_b = $agent->version($browser); $contact->agent = $platform . $version_p . "|" . $device . "|" . $browser . $version_b . "|" . $lang; $contact->save(); }
public function insertUserInformation($ipAddress, $userAgentString, $sapiName, GeocoderResult $geocoderResult = null) { $userAgent = new UserAgent(); $userAgent->setUserAgent($userAgentString); $browser = $userAgent->browser(); $platform = $userAgent->platform(); $data = ['ip_address' => $ipAddress, 'sapi_name' => substr($sapiName, 0, 32), 'user_agent' => substr($userAgentString, 0, 255), 'user_agent_browser' => substr($browser, 0, 32), 'user_agent_device' => substr($userAgent->device(), 0, 32), 'user_agent_browser_version' => substr($userAgent->version($browser), 0, 32), 'user_agent_platform_version' => substr($userAgent->version($platform), 0, 32), 'user_agent_platform' => substr($platform, 0, 32), 'user_agent_robot' => substr($userAgent->robot(), 0, 32)]; if ($geocoderResult) { $region = $geocoderResult->getAdminLevels()->first(); $data['geo_city'] = substr($geocoderResult->getLocality(), 0, 32); $data['geo_region'] = $region ? substr($region->getCode(), 0, 32) : null; $data['geo_country'] = substr($geocoderResult->getCountry(), 0, 32); $data['geo_country_code'] = substr($geocoderResult->getCountryCode(), 0, 6); $data['geo_latitude'] = substr($geocoderResult->getLatitude(), 0, 32); $data['geo_longitude'] = substr($geocoderResult->getLongitude(), 0, 32); } $this->getAdapter()->insert('dewdrop_activity_log_user_information', $data); return $this->getAdapter()->lastInsertId(); }
public static function saveSession() { $session_id = uniqid(); Session::put('session_id', $session_id); $agent = new Agent(); $browser = $agent->browser(); $version = $agent->version($browser); $platform = $agent->platform(); $versionpla = $agent->version($platform); $device = $agent->device(); $session = new SaveSession(); $session->browser = $browser; $session->version = $version; $session->platform = $browser; $session->versionpla = $versionpla; $session->device = $device; //$session->ip = $request->ip; $session->cookie = $session_id; $session->save(); }
/** * Redirects to Original Url */ public function redirect(Request $request, $shortUrl) { // Initiate Agent object for parsing header information $agent = new Agent(); // Setting header to agent $agent->setUserAgent($request->headers); // Query the url object from DB by shortUrl column $urls = Url::where('short_url', '=', config('app.url') . '/' . $shortUrl)->get(); // Check whether Url object exists if (!$urls->first()) { $error = Utility::getError(null, 404, 'Error', 'Url Not Found'); return response()->json($error, 404); } // get the queried url from collection $url = $urls[0]; // Get the long_url value for managing query string $longUrl = $url['long_url']; try { // Generate a version 1 (time-based) UUID object if (!isset($_COOKIE['_id'])) { $cookieUuid1 = Uuid::uuid1(); setcookie('_id', $cookieUuid1->toString(), time() + 10 * 365 * 24 * 3600, "/"); } else { $cookieUuid1 = $_COOKIE['_id']; } if (!isset($_COOKIE['_sid'])) { $sessionUuid1 = Uuid::uuid1(); setcookie('_sid', $sessionUuid1->toString(), 0, "/"); } else { $sessionUuid1 = $_COOKIE['_sid']; } } catch (UnsatisfiedDependencyException $e) { $error = Utility::getError($e, 500, 'Error', 'Please try again...'); return response()->json($error, 500); } // Default value of Http Referrer for saving into db $httpReferrer = 'Undefined'; // If Http referrer exists, replace the default value by it if (!empty($_SERVER['HTTP_REFERER'])) { $httpReferrer = $_SERVER['HTTP_REFERER']; } try { $city = Utility::getCity($_SERVER["REMOTE_ADDR"]); $state = Utility::getState($_SERVER["REMOTE_ADDR"]); $country = Utility::getCountry($_SERVER["REMOTE_ADDR"]); $countryIsoCode = strtolower(Utility::getCountryIsoCode($_SERVER["REMOTE_ADDR"])); } catch (AddressNotFoundException $e) { // Make logging for AddressNotFoundException exception //Utility::log($e); $city = ''; $state = ''; $country = ''; $countryIsoCode = ''; } // Increment clicks column by one $url->clicks = $url['clicks'] + 1; // Save the url instance $url->save(); // create the new Hit instance for the url instance $url->hits()->create(['client_ip' => $_SERVER['REMOTE_ADDR'], 'language' => $agent->languages()[0], 'device' => $agent->device(), 'platform' => $agent->platform(), 'browser' => $agent->browser(), 'cookie_id' => $cookieUuid1, 'session_id' => $sessionUuid1, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrers' => $httpReferrer, 'remote_addr' => $_SERVER["REMOTE_ADDR"], 'remote_port' => $_SERVER["REMOTE_PORT"], 'remote_method' => $_SERVER["REQUEST_METHOD"], 'city' => $city, 'state' => $state, 'country' => $country, 'country_iso_code' => $countryIsoCode]); // Get all query parameter of short url $shortQuery = $request->all(); // Get all url parameter of long url $parsedLongUrl = parse_url($longUrl); // Code for merging query parameter of short Url and long Url keeping the short url as prior // Redirect to the original Url if (isset($parsedLongUrl["query"])) { parse_str($parsedLongUrl["query"], $longQuery); $commonKeys = array_intersect_key($longQuery, $shortQuery); $finalQuery = array_diff($shortQuery, $commonKeys) + array_diff($longQuery, $commonKeys) + $commonKeys; if (isset($parsedLongUrl['port'])) { return redirect($parsedLongUrl['scheme'] . '://' . $parsedLongUrl['host'] . ':' . $parsedLongUrl['port'] . $parsedLongUrl['path'] . '?' . http_build_query($finalQuery)); } else { return redirect($parsedLongUrl['scheme'] . '://' . $parsedLongUrl['host'] . $parsedLongUrl['path'] . '?' . http_build_query($finalQuery)); } } else { if (empty($shortQuery)) { return redirect($longUrl); } else { return redirect($longUrl . '?' . http_build_query($shortQuery)); } } }
/** * Record the visitation. * * @param Request $request * @author Cali */ public static function visited(Request $request) { $userAgent = new Agent(); $location = Location::get(); static::create(['referer' => url()->previous(), 'uri' => $request->path(), 'browser' => $userAgent->browser(), 'platform' => $userAgent->platform(), 'device' => $userAgent->device(), 'mobile' => !$userAgent->isDesktop(), 'ip' => $location->ip, 'country' => $location->isoCode, 'city' => $location->cityName, 'robot' => $userAgent->isRobot() ? $userAgent->robot() : null, 'user_id' => $request->user() ? $request->user()->id : null]); }
private function getBrowser() { $agent = new Agent(); $browser = $agent->browser(); $platform = $agent->platform(); $data = array('name' => $browser, 'version' => $agent->version($browser), 'platform' => $platform, 'platformVersion' => $agent->version($platform), 'device' => $agent->device()); return $data; }
/** * Get the device name. * * @param string $userAgent * @return string * @static */ public static function device($userAgent = null) { return \Jenssegers\Agent\Agent::device($userAgent); }
/** * Set the user agent field * * @param string $value * @return string */ public function setUserAgentAttribute($value) { $agent = new Agent(); $agent->setUserAgent($value); $this->browser = $agent->browser(); $this->browser_version = $agent->version($this->browser); $this->platform = $agent->platform(); $this->platform_version = $agent->version($this->platform); $this->device = $agent->device() && !$agent->isDesktop() ? $agent->device() : ''; $this->device_type = $agent->isMobile() ? 'mobile' : ($agent->isTablet() ? 'tablet' : ($agent->isDesktop() ? 'desktop' : '')); $this->attributes['user_agent'] = $value; }