Welcome Guest, Not a member yet? Register   Sign In
Cookies don't work without www in the URL
#1

[eluser]bastones[/eluser]
Hi,

I'm getting quite sick with this problem as I've had it before and having it again. Basically the cookie won't display anything (and $_COOKIE returns no array) unless you have www in the URL ie www.mysite.com but if you just go to http://mysite.com it displays no cookies whatsoever (as I paste the cookie value with get_cookie in a view file). I had to resort to setting cookies and getting cookies with the built in functions but it still doesn't work!

is there any solution to this? I'm unsure if its my webhost, or because I have mod_rewrite on the URLs, but the htaccess is the same as provided in the user guide.

Code:
if($loginoptions == "7d") {
                                     $setcookie_u=array('name'=>'Username','value'=>$username,'expire'=>'604800');
                                     set_cookie($setcookie_u);
                                    $security=random_string("unique");
                                    $setcookie_s=array('name'=>'Security','value'=>$security,'expire'=>'604800');
                                     set_cookie($setcookie_s);
                                    $date=date('D jS F, Y g:ia');
                                    $update_users_acc=array('last_logged_in'=>$date,'login_code'=>$security);
                                    $this->db->where('username',$username);
                                    $this->db->update('users',$update_users_acc);
                                    header("Location: ".site_url());
                                }
                                elseif($loginoptions == "24h") {
                                     $setcookie_u=array('name'=>'Username','value'=>$username,'expire'=>'86400');
                                     set_cookie($setcookie_u);
                                    $security=random_string("unique");
                                    $setcookie_s=array('name'=>'Security','value'=>$security,'expire'=>'86400');
                                     set_cookie($setcookie_s);
                                    $date=date('D jS F, Y g:ia');
                                    $update_users_acc=array('last_logged_in'=>$date,'login_code'=>$security);
                                    $this->db->where('username',$username);
                                    $this->db->update('users',$update_users_acc);
                                    header("Location: ".site_url());
                                }
                                elseif($loginoptions == "4h") {
                                    $setcookie_u=array('name'=>'Username','value'=>$username,'expire'=>'14400');
                                     set_cookie($setcookie_u);
                                    $security=random_string("unique");
                                    $setcookie_s=array('name'=>'Security','value'=>$security,'expire'=>'14400');
                                     set_cookie($setcookie_s);
                                    $date=date('D jS F, Y g:ia');
                                    $update_users_acc=array('last_logged_in'=>$date,'login_code'=>$security);
                                    $this->db->where('username',$username);
                                    $this->db->update('users',$update_users_acc);
                                    header("Location: ".site_url());
                                }
                                elseif($loginoptions == "15m") {
                                    $setcookie_u=array('name'=>'Username','value'=>$username,'expire'=>'900');
                                     set_cookie($setcookie_u);
                                    $security=random_string("unique");
                                    $setcookie_s=array('name'=>'Security','value'=>$security,'expire'=>'900');
                                     set_cookie($setcookie_s);
                                    $date=date('D jS F, Y g:ia');
                                    $update_users_acc=array('last_logged_in'=>$date,'login_code'=>$security);
                                    $this->db->where('username',$username);
                                    $this->db->update('users',$update_users_acc);
                                    header("Location: ".site_url());
                                }

I'm losing options on what to do, any help appreciated Smile.
#2

[eluser]Future Webs[/eluser]
the best thing to do is force the www to show. not only will this fix your cookie situation but stop you having disjointed listings in search engines. If you dont force the www you end up with some listings with and some without and you are seen as two sites not one. this weakens the strength of any inbound links etc.

To force the www add something like this to your htaccess file

Code:
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
#3

[eluser]bastones[/eluser]
[quote author="w3bm" date="1228582446"]the best thing to do is force the www to show. not only will this fix your cookie situation but stop you having disjointed listings in search engines. If you dont force the www you end up with some listings with and some without and you are seen as two sites not one. this weakens the strength of any inbound links etc.

To force the www add something like this to your htaccess file

Code:
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
[/quote]

thanks w3bm that fixed my problem Smile.




Theme © iAndrew 2016 - Forum software by © MyBB