Export (0) Print
Expand All
Expand Minimize
5 out of 15 rated this helpful - Rate this topic

InternetSetCookie function

Creates a cookie associated with the specified URL.

Syntax


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.

Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and destructors of global objects.

Note  WinINet does not support server implementations. In addition, it should not be used from a service. For server implementations or services use Microsoft Windows HTTP Services (WinHTTP).

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Wininet.h

Library

Wininet.lib

DLL

Wininet.dll

Unicode and ANSI names

InternetSetCookieW (Unicode) and InternetSetCookieA (ANSI)

See also

HTTP Cookies
Managing Cookies
WinINet Functions
InternetGetCookie
InternetGetCookieEx
InternetSetCookieEx

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.