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 3 of 3
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts

    php cookies not working

    i am doing the following code

    $myusername="esther";
    $mypassword="pass";

    setcookie("username", $myusername, time()+3600);
    setcookie("password", $mypassword, time()+3600);

    for some reason this is not setting the cookie?
    what am i doing wrong?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,037
    Thanks
    2
    Thanked 316 Times in 308 Posts
    99.5% of the time when cookies (and sessions and header redirects) don't work, it is because some content is being sent to the browser prior to the setcookie() function call.

    Put the following two lines in after your first opening <?php tag -
    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    Also, how do you know they are not being set? What symptoms do you see?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts
    thanks so much -- that helped me find the issue!


  •  

    Posting Permissions

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