[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Cookies are not found when page without www prefix is loaded

Posted on 2004-08-19
6
Medium Priority
?
319 Views
Last Modified: 2012-06-27
I just noticed a big problem with my site.

When a user visits my page, www.<something>.com and signs in, I have coded the cookies so that the path is "/".  So the cookies work fine through all the pages. But, there's a section of my site that switches to just <something>.com (www is removed) so now the cookies are not even there cause they belong to www.<something>.com.

I have no idea why that particular section switches but I need to figure out how to assign the cookies to both www. and without if that's even possible.

 I don't know if there's a better/different solution so please let me know.

Thanks.

------------------------------------------------------------

code snippet of signin.php
~~~~~~~~~~~~~~~~~

if(isset($_REQUEST["chk_remember"]) == "yes"){
     $cookie_life = time() + 31536000;
}else{
     $cookie_life = 0;
}
setcookie('ows_userID', $var_userID, $cookie_life, '/');                  
setcookie('ows_password', $var_password, $cookie_life, '/');                  
setcookie('ows_validated', 'yes', 0, '/');                  
header("Location: signin2.php");
0
Comment
Question by:bloodtrain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 400 total points
ID: 11844611
you need to include the domain parameter in the setcookie function and specify it as

.domain.com

(notice the initial dot) so it is available across all subdomains
0
 
LVL 48

Expert Comment

by:hernst42
ID: 11844613
$domain = '<something>.com';

setcookie('ows_userID', $var_userID, $cookie_life, '/', $domain);              
setcookie('ows_password', $var_password, $cookie_life, '/', $domain);              
setcookie('ows_validated', 'yes', 0, '/', $domain);              

So the cookiea are available even if the uses uses www or not

see http://de3.php.net/manual/en/function.setcookie.php for detailed option to set via setcookie
0
 
LVL 2

Author Comment

by:bloodtrain
ID: 11844615
ok, well, I realized why that particular section of mine was losing the www prefix so my problem is solved. But I would still like to know if you can share the same cookie between www and no www..  

Thanks guys / gals!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 27

Expert Comment

by:Diablo84
ID: 11844626
reference: http://www.php.net/manual/en/function.setcookie.php

and quote regarding my above comment:

 To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com  will make the cookie only available in the www  subdomain. Refer to tail matching in the spec for details.

0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11844642
example

setcookie('ows_userID', $var_userID, $cookie_life, '/','.yourdomain.com');        
0
 
LVL 2

Author Comment

by:bloodtrain
ID: 11844645
You guys are too quick..

Diabo84, I will try you method first since you did post first..


Thanks both of you..
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question