SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Cookie Domain

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie Domain

    I am creating cookies in php and in js. When I create it in php, the domain shows as .mysite.com but when I create it in js, even though I am setting it at .mysite.com, when the cookie is created it is ending up as www.mysite.com so I have two sets of cookies out there.

    The function call is
    Code:
    Set_Cookie("cset", "J4", 90, "/", ".mysite.com", "");
    The function code is
    Code:
    function Set_Cookie( name, value, expires, path, domain, secure)
    {
    	var today = new Date();
    	today.setTime( today.getTime() );
    	
    	if ( expires )
    	{
    		expires = expires * 1000 * 60 * 60 * 24;
    	}
    	var expires_date = new Date( today.getTime() + (expires) );
    	
    	document.cookie = name + "=" +escape( value ) +
    	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    	( ( path ) ? ";path=" + path : "" ) +
    	( ( domain ) ? ";domain=" + domain : "" ) +
    	( ( secure ) ? ";secure" : "" );
    };
    The resultant cookie from this call is cset, J1, www.mysite.com

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,834
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Try getting rid of the . off the front of the domain name
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •