Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: Set Cookie Path

  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Set Cookie Path

    <script>

    function create_cookie_105(whichone){
    document.cookie="imgpref="+whichone.join("::delim::")+";expires="+new Date(new Date().getTime() +

    4320*3600).toGMTString();

    }


    function write_cookie_data_105(){

    var coo=document.cookie+";";
    var sn="imgpref=";
    var startcoo=coo.indexOf(sn);

    if(startcoo>=0){
    startcoo+=sn.length;
    var endcoo=coo.indexOf(";",startcoo);
    var data=unescape(coo.substring(startcoo,endcoo)).split("::delim::");

    document.write(data.join("<br><br>"));

    }
    else{
    document.write("No Cookie Data!!!")
    }

    }

    create_cookie_105(Array(ref,progid,linkid));

    </script>

    <script type="text/javascript">
    write_cookie_data_105();

    </script>



    I intend to set a path for this cookie for the example above, so that it can be created from one domain and accessed from another domain.

    Say for example : http://www.1.com/createcookie.html - creates the cookie

    http://www.2.com/readcookie.html - reads the cookie


    I've found this example where it says and speaks about path and domains. http://www.webreference.com/js/column8/functions.html
    But i have no idea on how to implement it, as am new to javascript.

    An Example provided would be awesome

    Thanks to everyone reading this

    Could anyone also provide me an example with the above code on how to set a path for "Folders" creating cookies from "A" folder and accessing the same from "B" folder.


    Regards
    Amit

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Have a look at the JavaScript FAQ sticky, and the threads linked from there.

    Also note that many people deny third party cookies (cookies set for other domains than the originating).
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A cookie can only be read from the domain it was set on.

    .....Willy

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Not quite. It can only be read on the domain it was set for. The cookie syntax allows setting for other domains than the originating. If the cookie is accepted, it will be readable only from that domain.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set Cookie Path

    liorean

    Can you tell me the source to find the FAQ

    Willy Duitt & liorean
    I guess you both are right.

    And if that's the case, then am in big trouble. As i have ran out of solutions.

    There is one last hope that i can think of, but it needs some working out.

    I am attaching a zip file that contains two html files. searched.html and iframe.html

    iframe.html calls searched.html and the cookie is created

    However, in my example i am asking iframe.html to call searched.html place on
    http://www.shopper-stop.com/testing/...d=26&B1=Submit

    So bcos, the domains are different, the cookie fails to create

    Why does this happen ?

    Can something be changed in either iframe.html or searched.html so that the cookie is generated.

    Help Please!

    Regards
    Amit

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It's a sticky, and is in fact the top thread in this forum. IF you're lazy, you can use the folloowing link, though: <JavaScript - Frequently Asked Questions>
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    liorean
    I am new to this forum, so i havent yet paid much attention to the posts, i shall be browsing through most of the posts to help increase my knowledge, and to input what i know.

    Thanks for the info and the link i will surely go through the same.

    Can you help me with that attachment that i have uploaded out here. Do u know why the cookie isnt being created? am calling the cookie creating page through an iframe.

    There's something mysteriously wrong with it

    Any help would be greatly appreciated.

    Regards
    Amit

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    There were no attachments. But definitely, you can only read the cookie if the domain it was set for is the same or a subdomain of the current domain.

    For example, the cookie domain is set to .yahoo.com. All of its subdomains (mail.yahoo.com, photos.yahoo.com, groups.yahoo.com, etc) can share the cookie.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Anyways

    Yep you peeps are right

    Anyways i completely turned around the system, but what the heck, i got things to work the way i wanted


    Regards
    Amit

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Maybe you would like to share your solution in order for other people with the same problem to implement it too or at least to have an idea. That's what forum's for.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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