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 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cookie / server problem

    Hi All

    I hope you can help.
    I'm moving my site over to a new server and during testing I've found an error with setcookie. The code I have is:

    Code:
    $arrayfirstname = ucfirst($table[firstname]);
    $arraysurname = ucfirst($table[surname]);
    $arrayusername = $table[username];
    $forever = 99999999999999; 
    				
    setcookie("firstname",$arrayfirstname,$forever,"/",".instructor.ignition-driving-school.co.uk",1);
    setcookie("surname",$arraysurname,$forever,"/",".instructor.ignition-driving-school.co.uk",1);
    setcookie("username",$arrayusername,$forever,"/",".instructor.ignition-driving-school.co.uk",1);
    For some reason it's not working now. The only thing that has changed is the url (which I've updated above( and the server. Could this be causing problems?

    Any help would be much appreciated.

    Thanks
    Mark

  • #2
    New Coder
    Join Date
    Mar 2010
    Posts
    26
    Thanks
    3
    Thanked 1 Time in 1 Post
    What error are you getting?
    Depending on the version of PHP running on the server and the character set in your script it might be a PHP bug.

    IFF the error is cookie canīt be set because output startet before, and IFF your script is using UTF-8 then you have to save your sript as "UFT-8 without BOM", else you have to tell us what the error is.

  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Goldfish

    The error is that it's not setting the cookie. From my vista files, the old site read:

    Code:
    __utma
    14167279.430960242.1263657159.1268648692.1268726701.38
    instructor.ignitiondrivingschool.com/
    1600
    1367383552
    30212738
    1619748448
    30065887
    *
    __utmz
    14167279.1267015699.26.9.utmcsr=intensives.ignitiondrivingschool.com|utmccn=(referral)|utmcmd=referral|utmcct=/
    instructor.ignitiondrivingschool.com/
    1600
    1615137664
    30098616
    2751655712
    30061903
    *
    firstname
    Mark
    instructor.ignitiondrivingschool.com/
    1536
    1422649728
    1727735832
    1705538448
    30065887
    *
    surname
    Williams
    instructor.ignitiondrivingschool.com/
    1536
    1422649728
    1727735832
    1705688448
    30065887
    *
    username
    mark
    instructor.ignitiondrivingschool.com/
    1536
    1422649728
    1727735832
    1705868448
    30065887
    *
    Where as the new one just reads:

    Code:
    __utma
    110690653.1314019071.1268670387.1268682400.1268725511.3
    instructor.ignition-driving-school.co.uk/
    1600
    1812547072
    30212743
    2060241968
    30065892
    *
    __utmz
    110690653.1268670387.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
    instructor.ignition-driving-school.co.uk/
    1600
    4271113472
    30102468
    1117034224
    30065756
    *
    The PHP version is 5.2.9. The PHP info is http://www.instructor.ignition-drivi...co.uk/test.php

    Thanks again for the reply
    Mark

  • #4
    New Coder
    Join Date
    Mar 2010
    Posts
    26
    Thanks
    3
    Thanked 1 Time in 1 Post
    Code:
    setcookie("firstname",$arrayfirstname,$forever,"/",".instructor.ignition-driving-school.co.uk",1);
    The last parameter indicates "secure" meaning the cookie shall only be set via HTTPS connection.
    Since your URL reads http://... not https:// that may be the problem,
    but I donīt really understand what your old and new site code means.

    I would suggest you first check the return value of setcookie() like this:

    Code:
    $returned = setcookie("firstname",$arrayfirstname,$forever,"/",".instructor.ignition-driving-school.co.uk",1);
    echo $returned;
    If you get a "false" there it means the setting failed at server end, a "true" indicates, the error is at the client end.

    Either way you may want to set

    Code:
    error_reporting(E_ALL);
    to see, what the actual problem is.

  • #5
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    $returned = setcookie("firstname",$arrayfirstname,$forever,"/",".instructor.ignition-driving-school.co.uk",1);
    echo $returned;
    For some reason it just returns 1

    I've tried taking out the 1 at the end of the setcookie, but that doesn't seem to change anything.

  • #6
    New Coder
    Join Date
    Mar 2010
    Posts
    26
    Thanks
    3
    Thanked 1 Time in 1 Post
    Returning 1 equals "true", which means the error is on the client end.
    Either the output startet before setcookie() was called, as I said above, or the client doesnīt accept the cookie for some other reason, which could be because it is no https connection or the site has no permission in the users browser security settings.
    Taking out the 1 doesnīt help, you have to replace it by a 0.

    Edit:
    Another possible reason is that 99999999999999 doesnīt fit into 32 bit.
    Not sure how PHP handles values > 4,294,967,296 but since cookies are never valid for more than 1 year, you might want to calculate $forever properly

    Code:
    $time = time();
    $forever = $time + 31536000;
    Last edited by Goldfish; 03-16-2010 at 02:56 PM.

  • #7
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's strange changing the 1 to 0, still returns a 1 error.
    The date change didn't seem to do it either.

    Thank you very much for your help on this one, but it looks like it's back to the drawing board. Looks like I'll be using sessions instead.

    Thanks again
    Mark

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by mark-ids View Post
    That's strange changing the 1 to 0, still returns a 1 error.
    The date change didn't seem to do it either.
    Post your updated code, as it is at this moment in time.

  • #9
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Matt

    It's

    Code:
    $arrayfirstname = ucfirst($table[firstname]);
    $arraysurname = ucfirst($table[surname]);
    $arrayusername = $table[username];
    $time = time();
    $forever = $time + 31536000;
    
    $returned = setcookie("firstname",$arrayfirstname,$forever,"/","http://www.instructor.ignition-driving-school.co.uk",0);
    
    echo $returned;
    exit;
    ...and this is returning 1
    Last edited by mark-ids; 03-16-2010 at 03:53 PM.

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Try:

    Code:
    $arrayfirstname = ucfirst($table[firstname]);
    $expire = (time()+3600);
    
    setcookie('firstname', $arrayfirstname, $expire, '/', 'www.instructor.ignition-driving-school.co.uk', 0, 1);
    I've just altered the expiry for testing, nothing more, btw.

  • Users who have thanked MattF for this post:

    mark-ids (03-16-2010)

  • #11
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's got it!!

    Not sure what the change was, but it worked!!

    Many thanks
    Mark

  • #12
    New Coder
    Join Date
    Mar 2010
    Posts
    26
    Thanks
    3
    Thanked 1 Time in 1 Post
    That simply means, your client doesnīt accept cookies that expire after more than a given time.
    +3600 is one hour and may be not sufficient for you, but +31536000 (1 year) seems too long.
    I donīt know where to look up the limit, I guess a bit of trial and error can find out the max.

  • #13
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    It was most likely the http:// on the domain part which was causing your problem.


  •  

    Posting Permissions

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