![]() |
[SOLVED] detecting the user browser - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [SOLVED] detecting the user browser (/showthread.php?tid=27777) |
[SOLVED] detecting the user browser - El Forum - 02-19-2010 [eluser]xeroblast[/eluser] im trying to detect the current browser using this code. Code: if ($this->session->userdata('browser')) { when i print/echo the session variable, it perfectly display the variable value but when i use it in a conditional statements, it wont work like this: Code: if ($this->session->userdata('browser') == 'Microsoft Internet Explorer') { it always display in "Netscape" even im using Internet Explorer... unless i print/echo the $this->session->userdata('browser'); [SOLVED] detecting the user browser - El Forum - 02-20-2010 [eluser]xeroblast[/eluser] i tried to var_dump the variable ($this->session->userdata('browser')) and the string ('Microsoft Internet Explorer') and result is like this in IE $this->session->userdata('browser') = string(51) "Microsoft Internet Explorer" 'Microsoft Internet Explorer' = string(27) "Microsoft Internet Explorer" in FF $this->session->userdata('browser') = string(51) "Netscape" 'Microsoft Internet Explorer' = string(27) "Microsoft Internet Explorer" so they are not equal... what is the difference in strings? [SOLVED] detecting the user browser - El Forum - 02-20-2010 [eluser]xeroblast[/eluser] i finally solved this problem. the problem was my implementation of the code. Code: $this->session->set_userdata('browser','< script >document . write (navigator.appName);</ script >'); is not the proper way to compare string coz the session reads the whole string as the script. that is why it has 51 characters. so i change the implementation to a different style. Code: function index() { |