setcookie

How do I set a cookie with a (ruby) rack middleware component?

时光怂恿深爱的人放手 提交于 2019-12-03 02:54:05
I'm writing a rack middleware component for a rails app that will need to conditionally set cookies. I am currently trying to figure out to set cookies. From googling around it seems like this should work: class RackApp def initialize(app) @app = app end def call(env) @status, @headers, @response = @app.call(env) @response.set_cookie("foo", {:value => "bar", :path => "/", :expires => Time.now+24*60*60}) [@status, @headers, @response] end end which doesn't give errors, but doesn't set a cookie either. What am I doing wrong? If you want to use the Response class, you need to instantiate it from

Cookies - set across multiple domains

大城市里の小女人 提交于 2019-12-03 00:49:31
My company has a setup as follows: subdomain1.domain1.com subdomain2.domain1.com subdomain3.domain1.com subdomain4.domain1.com subdomain5.domain1.com subdomain6.domain1.com subdomain1.domain2.com subdomain2.domain2.com subdomain3.domain2.com subdomain4.domain2.com subdomain5.domain2.com subdomain6.domain2.com On each site, bearing in mind there can be a hundred sites per subdomain, users can log in. We, as developers, have to test frontends across several browsers, but some work may only be required on a section once logged in. I have written a userscript which enables us to save a username

php cookie doesn't update

Deadly 提交于 2019-12-02 13:53:53
问题 I need to update a cookie. I do that in a php file called via ajax. This is is the code: setcookie('items['.$_POST['id'].']'); The cookie does not update, in fact if I write print_r($_COOKIE['items']) after the setcookie function I see that $_COOKIE['items'] is the same that was before the call to setcookie function. How can I do? 回答1: You cannot set and access a cookie in the same instance/page. You have to do a redirect or refresh after setting it. In addition, you should do something like

What does “the value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received” mean?

末鹿安然 提交于 2019-12-02 12:08:45
While learning the concept of Cookies in PHP, I come across the following statement from w3schools PHP Tutorial : The value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received (to prevent URLencoding, use setrawcookie() instead) I did not get the meaning of this statement. I have following doubts regarding the above statement : From where the cookie is being sent to whom and at where the cookie is being received from whom? What actually does happen by means of "Value of the cookie is automatically URLencoded when sending the cookie, and

Cookies aren't persisting in PHP?

主宰稳场 提交于 2019-12-02 11:25:34
问题 How do I get the cookies to persist in php? give_cookie.php <?php if (!isset($_COOKIE["muffin"])) setcookie("muffin", "55", 100 * 60 * 60 * 24 * 30); $_COOKIE["lid"]=true; ?> jar.php <?php var_dump($_COOKIE); if($_COOKIE["lid"]) echo "open"; ?> Running the code in that order gives me output: array(0) { } Notice: Undefined index: lid in jar.php on line 3 Embedding the code from jar.php in give_cookie.php gives me output: array(1) { ["lid"]=> bool(true) } open 回答1: You're supposed to give a

How to make a cookie with PHP [duplicate]

自古美人都是妖i 提交于 2019-12-02 11:21:31
Possible Duplicate: How to set cookies for uuid Hello, I would like to know how to make a cookie in PHP. I have researched the topic for a couple of hours already, yet im a newbie to PHP and dont understand it that much. I have found this script, but dont know how to implant it into my website, can anyone help? setcookie(name, value, expire, path, domain); What do you want to do with your cookie? If you want to track information on the server from request-to-request, you probably want to use a session , which automatically uses cookies. Otherwise, go ahead and use setcookie for cookies that

Cookies aren't persisting in PHP?

百般思念 提交于 2019-12-02 03:38:58
How do I get the cookies to persist in php? give_cookie.php <?php if (!isset($_COOKIE["muffin"])) setcookie("muffin", "55", 100 * 60 * 60 * 24 * 30); $_COOKIE["lid"]=true; ?> jar.php <?php var_dump($_COOKIE); if($_COOKIE["lid"]) echo "open"; ?> Running the code in that order gives me output: array(0) { } Notice: Undefined index: lid in jar.php on line 3 Embedding the code from jar.php in give_cookie.php gives me output: array(1) { ["lid"]=> bool(true) } open You're supposed to give a UNIX timestamp of when the cookie will expired (calculated since the epoch) as the third argument to the

php cookie doesn't update

懵懂的女人 提交于 2019-12-02 03:27:15
I need to update a cookie. I do that in a php file called via ajax. This is is the code: setcookie('items['.$_POST['id'].']'); The cookie does not update, in fact if I write print_r($_COOKIE['items']) after the setcookie function I see that $_COOKIE['items'] is the same that was before the call to setcookie function. How can I do? You cannot set and access a cookie in the same instance/page. You have to do a redirect or refresh after setting it. In addition, you should do something like this instead : setcookie("id","items['.{$_POST['id']}.']"); You have to set the value for the key to access

cURL doesn't set a cookie anymore, but why?

荒凉一梦 提交于 2019-12-01 05:53:20
问题 My cURL script does not work anymore (so keep in mind it DID work before) on my localhost (so it DOES work on my external host, hence: it might be the server settings): This script worked fine before on my localhost (it still does on my host). Nothing changed. Maybe the fact that I've ran this script over 3000 times on my localhost is useful to know. I'm running on windows 7, using WampServer to setup a host. I might have changed a setting, which effects the writing of cookies. But which one?

how to set this cookie to never expire [closed]

巧了我就是萌 提交于 2019-12-01 02:19:23
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 c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^