Questions tagged [setcookie]

The setcookie function sends an HTTP cookie to a client.

setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.

1196 questions
279
votes
25 answers

Cookies on localhost with explicit domain

I must be missing some basic thing about cookies. On localhost, when I set a cookie on server side and specify the domain explicitly as localhost (or .localhost). the cookie does not seem to be accepted by some browsers. Firefox 3.5: I checked the…
Jan Zich
  • 14,993
  • 18
  • 61
  • 73
68
votes
6 answers

Set-Cookie in HTTP header is ignored with AngularJS

I'm working on an application based on AngularJS on client side and Java for my API (Tomcat + Jersey for WS) on server side. Some path of my API are restricted, if the user doesn't have a session the response status returned is 401. On the client…
Romain Lefrancois
  • 899
  • 1
  • 6
  • 6
62
votes
3 answers

Domain set cookie for subdomain

I looked in many questions about cookies but I didn't find an answer on my problem. I have following scenario: A user creates a login on example.com and should get a cookie but only for the subdomain fuu.example.com. I generate following HTTP header…
Jarus
  • 1,748
  • 2
  • 13
  • 22
51
votes
4 answers

How can I send cookies using PHP curl in addition to CURLOPT_COOKIEFILE?

I am scraping some content from a website after a form submission. The problem is that the script is failing every now and then, say 2 times out of 5 the script fails. I am using php curl, COOKIEFILE and COOKIEJAR to handle the cookie. However when…
BastiaanWW
  • 1,259
  • 4
  • 18
  • 34
48
votes
3 answers

Check if a PHP cookie exists and if not set its value

I am working on a multilingual site so I tried this approach: echo $_COOKIE["lg"]; if (!isset($_COOKIE["lg"])) setcookie("lg", "ro"); echo $_COOKIE["lg"]; The idea is that if the client doesn't have an lg cookie (it is, therefore, the first…
Teodor
  • 1,285
  • 4
  • 21
  • 37
47
votes
7 answers

Safari not sending cookie even after setting SameSite=None; Secure

Our application uses cookies to remember user login. Every auth API call we make, the browser attaches server-set HTTPonly cookie with the API request and gets authenticated. This behaviour seems to be broken in safari after Mojave release. I read…
DieOnTime
  • 493
  • 1
  • 5
  • 8
35
votes
6 answers

setcookie() does not set cookie in Google Chrome

I am going through some PHP tutorials on how to set cookies. I have noticed that cookies are successfully set on FF4 and IE9, however it does not get set in Chrome (11.0.696.60). The PHP file was served from XAMPP (localhost). I tried the example…
Elyas
  • 551
  • 1
  • 5
  • 9
34
votes
2 answers

setting cross-subdomain cookie with javascript

How should I add domain support to these functions? I want to achieve that .example.com is declared as domain, so that the cookies can be read across all subdomains of the example.com. In its current form since domain is not set, it can only be read…
newnomad
  • 1,055
  • 3
  • 11
  • 15
34
votes
5 answers

How to get cookie from a NSURLSession with Swift?

I have a NSURLSession that calls dataTaskWithRequest in order to send a POST request in this way func makeRequest(parameters: String, url:String){ var postData:NSData = parameters.dataUsingEncoding(NSASCIIStringEncoding)! var…
Jorge Casariego
  • 21,948
  • 6
  • 90
  • 97
27
votes
3 answers

PHP setcookie domain

Some application, not written by me, and not in PHP, creates a cookie for the domain www.example.com. I am trying to replace that cookie. So in PHP I did: setcookie('mycookie','mydata',time() + 2*7*24*60*60,'/','www.example.com', false); However…
Nathan H
  • 48,033
  • 60
  • 165
  • 247
26
votes
5 answers

Cookies - set across multiple domains

My company has a setup as…
ClarkeyBoy
  • 4,934
  • 12
  • 49
  • 64
24
votes
2 answers

Set cookie on multiple domains with PHP or JavaScript

I have 3 domains that are themed the same. If somebody chooses a different theme, I want it to propagate across all 3 domains so their experience stays the same. I was planning to accomplish this by setting a cookie on domain1, redirect to domain2…
steveo225
  • 11,394
  • 16
  • 62
  • 114
24
votes
4 answers

How to parse HttpWebResponse.Headers.Keys for a Set-Cookie session id returned

I'm trying to create an HttpWebRequest/HttpWebResponse session with an ASP.NET website to later parse an HTML form through url params (this part I know how to do), but I do not understand how to parse and set a cookie such as the session id. In…
Maxim Zaslavsky
  • 17,787
  • 30
  • 107
  • 173
23
votes
2 answers

how to set this cookie to never expire

I have a function to create a cookie passing in the name, value and expiration (in days) of the cookie. Here is the function: function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var…
John mido
  • 269
  • 1
  • 2
  • 10
19
votes
2 answers

A cookie without a domain?

Is it possible to set a cookie without a domain? This will mean all domains will have access to it.
jamjam
  • 3,171
  • 7
  • 34
  • 39
1
2 3
79 80