[eluser]shiroin[/eluser]
Hi all,
New to CI and really enjoying coding with the MVC model. Actually trying to recode my whole site to fit the CI framework...
but I am encountering a big problem:
My site detects the user's screen resolution and arrange the layout accordingly.
Before I started using CI, I used javascript to detect user's screen resolution, send it to a cookie, and have PHP read the cookie and set it as a constant.
my code looked like this:
Code:
//cookie_constants.php
if(isset($HTTP_COOKIE_VARS["users_window_w1"])){
define("SCREEN_W",$HTTP_COOKIE_VARS["users_resolution_w1"]);
define("SCREEN_H",$HTTP_COOKIE_VARS["users_resolution_h1"]);
define("WINDOW_W",$HTTP_COOKIE_VARS["users_window_w1"]);
define("WINDOW_H",$HTTP_COOKIE_VARS["users_window_h1"]);
}
else //means cookie is not found set it using Javascript
{
?>
<scr1pt language="javascript">
<!--
writeCookie();
function writeCookie(){
var the_date = new Date();
the_date.setTime(the_date.getTime()+60000);
var the_cookie_date = the_date.toGMTString();
var the_cookie1 = "users_resolution_w1="+ screen.width;
var the_cookie2 = "users_resolution_h1="+ screen.height;
var the_cookie1 = the_cookie1 + ";expires=" + the_cookie_date;
var the_cookie2 = the_cookie2 + ";expires=" + the_cookie_date;
[removed]=the_cookie1
[removed]=the_cookie2
location = '<?=selfURL();?>';
}
//-->
</scr1pt>
<?
}
Basically:
(cookie exists){
load cookies as PHP constants.
}else{
javascript detects screen resolution ans write cookie.
reload this PHP file.
}
Now I am trying to implement this into a model that gets loaded automatically (global_model.php), and I wish to load these cookies into CI Sessions.
How can I do this?
I've tried putting the whole thing into the global_model() constructor with no luck.
Or is there some other way I can detect screen resolution without using javascript?
Thanks soo much in advance.