Welcome Guest, Not a member yet? Register   Sign In
Ci4 useragent
#1

In Ci3 I could use the user agent like this:

Code:
$this->load->library('user_agent');


and then

Code:
$data = array(
'da' => date("Y-m-d H:i:s"),
'AGENT_PLATFORM' => $this->agent->platform(),
'AGENT_BROWSER' => $this->agent->browser(),
'AGENT_VERSION' => $this->agent->version(),
'MOBILE_AGENT' => $this->agent->mobile(),
)


Im trying to replicate the same in CI4 and following the documentation here:

https://codeigniter.com/user_guide/libra...-reference

I dont see how to correlate the CI4.



Ive tried this:

Code:
$agent = $this->request->getUserAgent();
var_dump($agent);
//returns error: Call to a member function getUserAgent() on null
die();
   
var_dump($this->agent);
// returns NULL
die();

var_dump($agent);
// returns Undefined variable $agent
 die();
I feel like i need to be calling the class (as i would with Ci3 using $this->load->library('user_agent'); but there is nothing about it in the docs.
Reply
#2

(This post was last modified: 10-16-2021, 02:16 AM by InsiteFX.)

PHP Code:
// isBrowser, isMobile, isRobot, isReferral
// getBrowser, getVersion, getMobile, getRobot, getPlatform, getReferrer, getAgentString, parse

$request = \Config\Services::request();
$agent  $request->getUserAgent();

'AGENT_PLATFORM' => $agent->getPlatform(),
'AGENT_BROWSER'  => $agent->getBrowser(),
'AGENT_VERSION'  => $agent->getVersion(),
'MOBILE_AGENT'  => $agent->getMobile(), 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB