Cookie

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daan

    Cookie

    I have a website that is accessible (at least from our local campus
    network) by four different ways:

    1) the full url: http://campuslaan37.student.utwente.nl/
    2) the short url: http://campuslaan37/
    3) an alias: http://cam37.student.utwente.nl/
    4) the short alias: http://cam37/

    I use cookies to save and set some preferences etc. However, if you
    surf from e.g. (1) to (3), it is treated as an entirely different
    site, and nothing that was stored in the cookie applies anymore.

    Is there a way to set the cookie, such that it immediately applies
    to all the possible URLs to access the site?

    Thanks in advance,

    --
    Daan
  • Alvaro G Vicario

    #2
    Re: Cookie

    *** Daan wrote/escribió (Tue, 17 Aug 2004 11:54:48 +0200):[color=blue]
    > Is there a way to set the cookie, such that it immediately applies
    > to all the possible URLs to access the site?[/color]

    setcookie() has a parameter called domain ("the domain that the cookie is
    available"). Then it explains:

    "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."

    This doesn't exactly apply to your case since your URLs don't have a "tail"
    in common. However, I suppose you could use setcookie() to set the cookie
    several times, one for each domain. You could write a function to make it
    easier:

    function mysetcookie($na me, $value='', $expire='', $path='', $secure=''){
    $aliases=array(
    'campuslaan37.s tudent.utwente. nl',
    'campuslaan37',
    'am37.student.u twente.nl',
    'cam37'
    );

    foreach($aliase s as $domain){
    setcookie($name , $value, $expire, $path, $domain, $secure);
    }
    }

    Be aware that I didn't test the code. It probably needs to handle empty
    parameters differently.

    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Questions sent to my mailbox will be billed ;-)
    --

    Comment

    • Lāʻie Techie

      #3
      Re: Cookie

      On Tue, 17 Aug 2004 12:10:16 +0200, Alvaro G Vicario wrote:
      [color=blue]
      > *** Daan wrote/escribió (Tue, 17 Aug 2004 11:54:48 +0200):[color=green]
      >> Is there a way to set the cookie, such that it immediately applies to
      >> all the possible URLs to access the site?[/color]
      >
      > setcookie() has a parameter called domain ("the domain that the cookie is
      > available"). Then it explains:
      >
      > "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."
      >
      > This doesn't exactly apply to your case since your URLs don't have a
      > "tail" in common. However, I suppose you could use setcookie() to set the
      > cookie several times, one for each domain. You could write a function to
      > make it easier:[/color]

      For security reasons, browsers will not set cookies which do not match a
      different domain than where the page was served. In this case, you might
      get away with setting the cookie's domain to ".student.utwen te.pl" which
      will include campuslaan37 and cam37.

      HTH,
      La'ie Techie

      Comment

      • steve

        #4
        Re: Re: Cookie

        "Lie Techie" wrote:[color=blue]
        > On Tue, 17 Aug 2004 12:10:16 +0200, Alvaro G Vicario wrote:
        >[color=green]
        > > *** Daan wrote/escribió (Tue, 17 Aug 2004 11:54:48 +0200):[color=darkred]
        > >> Is there a way to set the cookie, such that it immediately[/color][/color][/color]
        applies[color=blue]
        > to[color=green][color=darkred]
        > >> all the possible URLs to access the site?[/color]
        > >
        > > setcookie() has a parameter called domain ("the domain that the[/color]
        > cookie is[color=green]
        > > available"). Then it explains:
        > >
        > > "To make the cookie available on all subdomains of example.com then[/color]
        > you’d[color=green]
        > > set it to ’.example.com’. The . is not required but[/color]
        > makes it compatible[color=green]
        > > with more browsers. Setting it to www.example.com will make the[/color]
        > cookie[color=green]
        > > only available in the www subdomain."
        > >
        > > This doesn’t exactly apply to your case since your URLs[/color]
        > don’t have a[color=green]
        > > "tail" in common. However, I suppose you could use setcookie()[/color][/color]
        to[color=blue]
        > set the[color=green]
        > > cookie several times, one for each domain. You could write a[/color]
        > function to[color=green]
        > > make it easier:[/color]
        >
        > For security reasons, browsers will not set cookies which do not[/color]
        match[color=blue]
        > a
        > different domain than where the page was served. In this case, you
        > might
        > get away with setting the cookie’s domain to
        > ".student.utwen te.pl" which
        > will include campuslaan37 and cam37.
        >
        > HTH,
        > La’ie Techie[/color]

        If nothing else works, you can always redirect the subdomain to the
        real domain. There is a slight delay for the user and some refershing,
        but at least your cookie info are available to the user.

        --
        http://www.dbForumz.com/ This article was posted by author's request
        Articles individually checked for conformance to usenet standards
        Topic URL: http://www.dbForumz.com/PHP-Cookie-ftopict140317.html
        Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=470472

        Comment

        Working...