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 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2013
    Location
    Germany
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How to use cookies

    Well I know how to create and call a cookie with PHP - something like this:
    create:
    PHP Code:
    <?php setcookie(namevalueexpirepathdomain); ?>
    load:
    PHP Code:
    <?php echo $_COOKIE["name"]; ?>
    Well I have a JS alert on entering my website's homepage and I want when once the user cliked "OK" the information to be written in the cookie and next visit the alert doesn't show. Should I use cookies or MySQL and is it even possible to do this?
    Last edited by Name User; 07-15-2013 at 01:10 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    Use a cookie, but read Create and Store a Cookie with javascript http://www.w3schools.com/js/js_cookies.asp
    Evolution - The non-random survival of random variants.

  • #3
    New Coder
    Join Date
    Apr 2013
    Location
    Germany
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by sunfighter View Post
    Use a cookie, but read Create and Store a Cookie with javascript http://www.w3schools.com/js/js_cookies.asp
    Even so how to code the cookie?

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    I gave you a link that explains this
    Evolution - The non-random survival of random variants.

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    I just started learning about cookies myself lately. I found that a cookie is a very good way for javascript and php to communicate. No when someone goes to the home page of my site, a cookie is placed on their machine giving ther browser width and height, and if they choose to download the monthly calendar that information is used by the download.php to crop and resize the picture to their desktop.

    <?php setcookie('mycooked','1440x900',[time]); ?>

    The expire time is in Unix time, you get the time(); and add 86,400 to it for each day you want the cookie to 'live'.The cookie data is a string, php reads it very simply, javascript is a bit more complicated, you have to split it out.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #6
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A cookie is basically a string of text characters not longer than 4 KB. Cookies are set in name=value pairs, separated by semi-colons. For example, a cookie might be a string like the following:

    Code:
    "theme=blue; max-age=60; path=/; domain=thesitewizard.com"
    Last edited by Fou-Lu; 07-15-2013 at 09:50 PM.

  • #7
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by teddyhudson View Post
    A cookie is basically a string of text characters not longer than 4 KB. Cookies are set in name=value pairs, separated by semi-colons. For example, a cookie might be a string like the following:

    Code:
    "theme=blue; max-age=60; path=/; domain=thesitewizard.com"
    I found out the hard way that it's a semicolon followed by a whitespace, very important when you split out the data.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.


  •  

    Tags for this Thread

    Posting Permissions

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