Click to Rate and Give Feedback
MSDN
MSDN Library
Networking
Network Protocols
Windows Internet
WinINet Reference
WinINet Functions
 InternetSetCookie Function
InternetSetCookie Function

Creates a cookie associated with the specified URL.

Syntax

C++
BOOL InternetSetCookie(
  __in  LPCTSTR lpszUrl,
  __in  LPCTSTR lpszCookieName,
  __in  LPCTSTR lpszCookieData
);

Parameters

lpszUrl [in]

Pointer to a null-terminated string that specifies the URL for which the cookie should be set.

lpszCookieName [in]

Pointer to a null-terminated string that specifies the name to be associated with the cookie data. If this parameter is NULL, no name is associated with the cookie.

lpszCookieData [in]

Pointer to the actual data to be associated with the URL.

Return Value

Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError.

Remarks

Cookies created by InternetSetCookie without an expiration date are stored in memory and are available only in the same process that created them. Cookies that include an expiration date are stored in the windows\cookies directory.

Creating a new cookie might cause a dialog box to appear on the screen asking the user if they want to allow or disallow cookies from this site based on the privacy settings for the user.

Caution  InternetSetCookie will unconditionally create a cookie even if “Block all cookies” is set in Internet Explorer. This behavior can be viewed as a breach of privacy even though such cookies are not subsequently sent back to servers while the “Block all cookies” setting is active. Applications should use InternetSetCookieEx to correctly honor the user's privacy settings.

For more cookie internals, see http://blogs.msdn.com/ieinternals/archive/2009/08/20/WinINET-IE-Cookie-Internals-FAQ.aspx.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
VersionInternet Explorer 3.0 or later
HeaderWininet.h
LibraryWininet.lib
DLLWininet.dll
Unicode and ANSI namesInternetSetCookieW (Unicode) and InternetSetCookieA (ANSI)

See Also

HTTP Cookies
Managing Cookies
WinINet Functions
InternetGetCookie
InternetGetCookieEx
InternetSetCookieEx

Send comments about this topic to Microsoft

Build date: 10/8/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Be sure to look at 'Managing Cookies' -- name isn't really name, and value sure isn't value.      Peter Smith in Redmond   |   Edit   |   Show History
Here's how the companion topic 'managing cookies' uses this function:
// Create a persistent cookie.
bReturn = InternetSetCookie("http://www.adventure_works.com", NULL,
"TestData = Test; expires = Sat,01-Jan-2000 00:00:00 GMT");
Note that the name is 'TestData' the value is 'Test' and it's all wrapped in a weirdo, undocumented string.
Tags What's this?: doc: (x) Add a tag
Flag as ContentBug
This always fails with error code 126 (ERROR_MOD_NOT_FOUND).      hikihome   |   Edit   |   Show History
I don't know why and I couldn't find relevant information.
Tags What's this?: Add a tag
Flag as ContentBug
Caution: unconditional cookies only      John Sudds   |   Edit   |   Show History
InternetSetCookie will unconditionally create a cookie even if “Block all cookies” is set in Internet Explorer. This behavior might be viewed as a breach of privacy even though such cookies are not subsequently sent back to servers while the “Block all cookies” setting is active.

Applications should use InternetSetCookieEx to correctly honor the user's privacy settings.

For more cookie internals, see http://blogs.msdn.com/ieinternals/archive/2009/08/20/WinINET-IE-Cookie-Internals-FAQ.aspx.
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker