Showing posts with label cookie. Show all posts
Showing posts with label cookie. Show all posts

Friday, September 6, 2013

Setting Cookie via Javascript Not Working for my Android 2.33 Gingerbread Device

I believe the current Android based device won't have this issue. But it happened to my antique Android Gingerbread based phone. After plenty of testings, here is my conclusion:

Javascript with Problem:
document.cookie = "apple = orange;";


Javascript that worked on my phone:
document.cookie = "apple=orange;";



Very unexpected problem. Simple and unexpected solution as well.

Now I kind of like this name of Android version: Froyo (2.2–2.2.3) if you know what I mean. :)

Read More »

Monday, November 21, 2011

PHP: Setting and Reading Cookies



<?PHP

setcookie("myCookieName", "myCookieValue");

// To read cookie, simply retrieve from the $_COOKIE['myCookieNameToRead']

.
.
.


?>


<HTML>
.
.



IMPORTANT: Make sure your <PHP is the first thing is your PHP file. Even a single tiny white space character prior to <PHP will also render the cookie operation useless.
Read More »

Sunday, February 21, 2010

How to dynamically display the content of your Cookie using Javascript?

Almost the same as the previous post. Just need to replace the cookie variable in the assignment of innerHTML.

HTML:
<span id="myHTML"></span>


Javacript:
document.getElementById('myHTML').innerHTML = document.cookie.indexOf("myCookieName");   // where 'myCookieName' is the name of the cookie such as the shopping cart item quantity, etc..


You can set up a Javascript function to handle this dynamic capability and receive event calls from omouseover, onload, ... HTML event as a trigger to the change of content. You can also set up a timer to change the content periodically.
Read More »

Sunday, February 14, 2010

The Maximum Length of a Cookie Name

I once encountered a problem with the cookie length with Firefox when the cookie name or value is too long.

I now try to imitate the same problem I encountered last time, the problem is gone.

But I use shorter cookie name and value so that Firefox won't reject them I encountered last time which caused me a lots of pain debugging.

It's good to test cookies using firefox as one can view the cookies easily using this:

Tools->Options...->Privacy->Show Cookies

Thank goodness there is a browser called Firefox or the debugging of cookie problem will be quite troublesome.
Read More »

Sunday, February 7, 2010

Set Cookie with Variable Using Eval in Javascript

Have you ever encountered a situation that you need to set a cookie with a javascript variable added to a cookie? But you cannot use "+" in your cookie assignment?

Here is where the javascript eval() comes into play:


function assignfruit(type) {
eval('document.cookie = "fruit='+ type +';"');
}


Since you cannot do this: document.cookie = "fruit="+ type +";" or this: document.cookie = 'fruit='+ type +';', you need to use eval().


Something I found out and I think it is useful to beginners to understand eval().


Read More »