Setting cookies in <SCRIPT> include (generated PHP)

Discussion in 'PHP' started by ruby, Feb 24, 2007.

  1. #1
    OK this is interesting. I have am using a SCRIPT include on various sites which calls a PHP script on my main domain.

    For example on a.com I have this line:

    <SCRIPT src="http://www.b.com/script.php"></SCRIPT>

    OK that works fine, thats not the issue. My issue is that in script.php I want to set a cookie as follows:

    setcookie('accept','yes',time()+86400,'/','.b.com');


    This works on Firefox perfectly but not on IE. On IE the cookie doesnt get set.



    I figured it might be a cross site scripting issue but it works with Firefox so wasnt sure.

    Any ideas?
     
    ruby, Feb 24, 2007 IP
  2. keiths

    keiths Peon

    Messages:
    109
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not sure what you're trying to do exactly but instead of calling <script try calling the page as an image. <img src="http://www.b.com/script.php" width="1" height="1" />

    I know we used to do that a few years ago to set cookies on a different domain when some one logged in. I don't know if it still works though, depending on IE's security settings.
     
    keiths, Feb 25, 2007 IP
  3. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #3
    I need to use the SCRIPT include because I am serving back a linked image.
     
    ruby, Feb 25, 2007 IP
  4. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hmm, can't you set a cookie simply via PHP itself? and script.php returning by example "alert('cookie set succesfully!');" ?
     
    DeViAnThans3, Feb 25, 2007 IP
  5. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #5
    I do try and set the cookie in script.php

    In Firefox it works, but in IE it doesnt. Thats my question, anyone know why!!??
     
    ruby, Feb 25, 2007 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    The php files headers must be a javascript file.

    Also you need to reload the page for the cookie to take affect in IE (not sure thou).

    Peace,
     
    Barti1987, Feb 25, 2007 IP
  7. tinkerbox

    tinkerbox Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    try this one:
    setcookie ("cookie name", "cookie value", time()+86400, "/", "", 0);
     
    tinkerbox, Feb 25, 2007 IP
  8. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #8
    It is javascript and yes I know the page needs to be reloaded.

    My scripting works people.... like I said, it sets the cooking in Firefox but when I do the same thing in IE it doesnt.

    I am assuming it must be a security thing but I also noticed than when I refresh a page in IE it sets the Alexa cookie as well. In theory I am wanting to do the same thing, set a cookie for a different domain. Works in Firefix, just not IE.
     
    ruby, Feb 25, 2007 IP
  9. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #9

    I need to specify the domain. I am using:

    setcookie('accept','yes',time()+86400,'/','.domain.com');

    Like I said it works in Firefox but NOT IE.
     
    ruby, Feb 25, 2007 IP
  10. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #10
    Try opera.

    Chances are that your IE settings are different from the normal.

    Peace,
     
    Barti1987, Feb 25, 2007 IP
  11. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #11
    Nope. IE is at the default settings.
     
    ruby, Feb 26, 2007 IP
  12. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #12
    the domain you're using, does it have a underscore (_) in it? If so, that might be the problem, as I recently red after a bit of research IE has trouble with that.

    And does this works:
    setcookie('accept','yes',time()+86400,'/','.b.com', 1);
    PHP:
     
    DeViAnThans3, Feb 28, 2007 IP
  13. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #13
    I am doing this:

    setcookie('accept','yes',time()+86400,'/','.b.com');
    Code (markup):
    No the domain has no underscore.
     
    ruby, Feb 28, 2007 IP
  14. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #14
    And if you use
    setcookie('accept','yes',time()+86400,'/','.b.com', 1);
    PHP:
    Probably it doesn't makes difference, but maybe .. ;)
     
    DeViAnThans3, Feb 28, 2007 IP
  15. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #15
    Whats the last parameter for??? the 1

    ??
     
    ruby, Feb 28, 2007 IP
  16. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #16
    That stands for "secure", as you'll find in the manual ;)
    You could also try to make that "1" a "0" ... see what it gives.
     
    DeViAnThans3, Mar 1, 2007 IP
  17. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #17
    Ill give it a whirl!
     
    ruby, Mar 1, 2007 IP
  18. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Okay, keep us updated :)
     
    DeViAnThans3, Mar 4, 2007 IP
  19. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #19
    That parameter is not available in the version of PHP I am using only 5.2.0+
     
    ruby, Mar 4, 2007 IP
  20. tinkerbox

    tinkerbox Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #20
    i think its because P3P: http://www.w3.org/P3P/

    Did u see a icon look like eye with a red cross at the bottom of IE browser(Privacy Report), it block your cookie? If yes definitely because of P3P, Platform for Privacy Preferences Project. You nee to install Compact Privacy Policy on your website. You need to add a header like this:
    header('P3P: CP="CAO DSP COR CURa ADMa DEVa TAIa IVAi IVDi CONi TELi OUR SAMi OTRi STP BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT PRE LOC"');
    setcookie ("cookiename", "cookievalue", time()+(60*60*24*30), "/");
    PHP:
    Don't ask me the meaning of the code above, because no one know it :D

    You can check with this header check website: http://www.delorie.com/web/headers.html

    Mine looks like this:
    HTTP/1.1 200 OK
    Date: Thu, 15 Mar 2007 11:19:55 GMT
    Server: Apache/1.3.37 (Unix) mod_fastcgi/2.4.2 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b
    CP="CAO DSP COR CURa ADMa DEVa TAIa IVAi IVDi CONi TELi OUR SAMi OTRi STP BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT PRE LOC"
    X-Powered-By: PHP/4.4.4
    Connection: close
    Content-Type: text/html
    Code (markup):
    Hope this help :cool:
     
    tinkerbox, Mar 15, 2007 IP