Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 517
  • Last Modified:

cookie question

Hello I am kinda new to cookies and having a little trouble.
I can set the cookie but if I set it at "mySite.com" it is not recognized at "www.mySite.com".

 setcookie( "userCookie", "$loginUserName", $date_of_expiry, "/" ) ;
 setcookie( "groupCookie", "$loginStrGroup", $date_of_expiry, "/" ) ;

Open in new window

0
Luey
Asked:
Luey
  • 3
  • 2
  • 2
1 Solution
 
gr8gonzoConsultantCommented:
Try adding ".mysite.com" as the 5th parameter (with the dot in front of the domain):

setcookie( "userCookie", "$loginUserName", $date_of_expiry, "/", ".mysite.com") ;
 setcookie( "groupCookie", "$loginStrGroup", $date_of_expiry, "/", ".mysite.com") ;
0
 
SlimshaneeyCommented:
Technically, the browser sees them as 2 separate sites, and one site will not be allowed see the cookies of another. In apache there is a setting, I think its session.cookie_domain that allows you to set it as .mysite.com which will allow for all subdomains within the top level to see cookies.
0
 
SlimshaneeyCommented:
In fact, just trying it out, in PHP you can set ini_set('session.cookie_domain', '.mysite.com'); and that will work across all domaina
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gr8gonzoConsultantCommented:
@Slim - The cookie domain can be set in setcookie() - it doesn't have to be set in Apache or PHP.
0
 
LueyAuthor Commented:
Now that there is a discussion I do not know how to fix it.
0
 
gr8gonzoConsultantCommented:
Use my first example.
0
 
LueyAuthor Commented:
Works!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now