Forum Moderators: coopster

Message Too Old, No Replies

setcookie With colon in Value

         

boxfan

9:52 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



Hi,

I'm trying to set a cookie using PHP where the value has a colon (:).

setcookie("name", "1236:abcde", strtotime($expire), "/");

This results in a cookie being set with the value of

1236%3Aabcde

From what I can find out, a colon is an allowable character in a cookie value and is used as a delimiter quite often.

Any ideas how to get the colon in the cookie value?

Thanks

PHP_Chimp

10:09 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you get getting 3A for your : then it is getting hexed at some point.

A quote from the manual -

Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, it is automatically decoded and assigned to a variable by the same name as the cookie name. If you don't want this, you can use setrawcookie() instead if you are using PHP 5.

So im guessing your : is getting encoded by the setcookie function. Try setrawcookie if you have php 5. If not then you can always use the header function to set your cookie.

Also is the %3A coming up in the browser or in the $_COOKIE array? As you should be getting : in the cookie array just the encoded value in the browser.

[edited by: PHP_Chimp at 10:13 pm (utc) on Oct. 17, 2007]

boxfan

10:32 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



I'm seeing the %3a in the actual cookie value using add-n-edit cookies in Firefox.

Also, I am using PHP4.

PHP_Chimp

7:16 am on Oct 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The actual cookie value that you are reading through fire fox is the value in the browser, so that is encoded, hence the %3A.

I am guessing from reading the bit I quoted from the manual that if you look in the $_COOKIE or $_REQUEST array that the value will be back with a :.

So you will need to print_r($_COOKIE) to test my theory.

If that doesnt work then use the header function to set the cookie, as this doesnt urlencode anything.

boxfan

2:36 pm on Oct 18, 2007 (gmt 0)

10+ Year Member



Yeah, the header function worked. Thanks for the tip!