setcookie

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

爱⌒轻易说出口 提交于 2019-11-27 19:20:17
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 time they've visited this site) then set a cookie lg = ro for that user. Everything works fine except that if I enter this page for the first time, the first and second echo return nothing. Only if I refresh the page is the cookie set and then both echo print the "ro" string I am expecting. How can I set this cookie in order to see its value from the second

Create cookie with AngularJS

☆樱花仙子☆ 提交于 2019-11-27 15:20:04
问题 I tried to use the code below to set cookies: angular.module('myApp').controller('myController', ['$scope', '$http','$cookies', function ($scope, $http, $cookies) { $scope.setMyCookie = function () { $cookies.put('Mykey', 'MyValue'); }; $scope.setMyCookie(); }]); I updated to version 1.3.14 of angular cookies, I know there is a breaking change, but how should I write the above code now ? Running the above code I get this error : Error: $cookies.put is not a function UPDATE : I have to do this

php setcookie domain

不羁岁月 提交于 2019-11-27 13:06:59
问题 Some application, not written by me, and not in PHP, creates a cookie for the domain "www.domain.com". I am trying to replace that cookie. So in php I did: setcookie('mycookie','mydata',time() + 2*7*24*60*60,'/','www.domain.com', false); However the resulting cookie is created for domain: ".www.domain.com", note the dot "." ahead of the domain. So it doesn't replace it, it creates another cookie. What can I do? 回答1: The issue is also adressed here: https://www.php.net/manual/en/function

Set cookie on multiple domains with PHP or JavaScript

纵然是瞬间 提交于 2019-11-27 12:28:24
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 where the cookie is set, redirect to domain3 where the cookie is set, redirect back. Since the information doesn't need to be secure or protected, this will work fine with no real problems. I hate the idea 3 redirects just to set a cookie on each domain and was looking for something a little more elegant. Do what Google is doing. Yes, Google is doing

Set-Cookie in HTTP header is ignored with AngularJS

两盒软妹~` 提交于 2019-11-27 11:17:10
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 side, 401 http status are intercepted to redirect the user to the login page. Once the user is authenticated, I create a session on the server side httpRequest.getSession(true); and the response send to the client does have the Set-cookie instruction in its header : Set-Cookie:JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Domain=localhost; Path=/api/; HttpOnly

How to get cookie from a NSURLSession with Swift?

只谈情不闲聊 提交于 2019-11-27 11:06:00
问题 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 postLength:NSString = String(postData.length ) var request = NSMutableURLRequest(URL: NSURL(string: url)!) var session = NSURLSession.sharedSession() request.HTTPMethod = "POST" var error:NSError? //request.HTTPBody = NSJSONSerialization.dataWithJSONObject(postData,

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

梦想与她 提交于 2019-11-27 10:33:31
问题 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 Fiddler, it shows that the ASP.NET Session ID is returned through Set-Cookie in the response to the request to the / path of the url, but how can I extract this session id and set it as a cookie for the next HttpWebRequest? I understand that this Set

Designing a secure auto login cookie system in PHP

若如初见. 提交于 2019-11-27 07:53:04
I want to have an auto login option check for a user. Basically that means a cookie will be stored on the client side. Now the question is, how do I make it secure so the cookie will can not be spoofed/modified. One of my friends suggest having a db table that stores the session_id, user's ip, browser info, etc and then compare it all that information once a user goes to the website again. I feel like having a separate table for that is a bit too much trouble. Is there another way to do it? Maybe with tokens or something like that? The more secure you want this infamous cookie, the more

setting cross-subdomain cookie with javascript

不问归期 提交于 2019-11-27 05:53:43
问题 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 from www.example.com 回答1: Here is a link on how to share cookies amongst a domain: https://www.thoughtco.com/javascript-by-example-2037272 It involves setting the domain attribute of the cookie string like: document.cookie = "myValue=5;path=/

setcookie() does not set cookie in Google Chrome

一个人想着一个人 提交于 2019-11-27 03:44:37
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 from w3schools: <?php setcookie("user", "Alex Porter", time()+3600); ?> And from this site (for localhost environments): <?php setcookie("username", "George", false, "/", false); ?> Thanks in advance. Mike West Disabling cookies for IP addresses and localhost was a design decision. See also: https://code.google.com/p/chromium/issues/detail?id=56211