w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
   » Home » Name of Cookie
How to use Rack middleware to simultaneously set cookie and send response with cookie in effect
you need to setup your middleware in your application.rb config.middleware.insert_before "ActionDispatch::Cookies", "GeoFilterMiddleware" and in your middleware do something like this: def call(env) status, headers, body = @app.call(env) if from_uk?(env) Rack::Utils.set_cookie_header!(headers, 'country', { :value => 'UK', :path => '/'}) end [status, headers, body] end

Categories : Ruby On Rails

What are the obvious vulnerabilities to using a session identifier cookie and a user_id cleartext cookie?
Well, you can always pass the User Id in cookie; however, another way to edit self is to allow "self" or "me" in the URIs to resolve to the sessions current user for example /users/me/profile/ instead of /users/42/profile/ - then however you need to make sure that no data is cached as it would be quite confusing for the users to see another users' profile data as their own. Actually in my latest project we used both of these approaches simultaneously.

Categories : Javascript

Update jquery cookie pb after addClass , some div shouldn't take class cookie created
have a look at var $qsts = $(".quest").show(); var $anrs = $(".ans").hide(); $('.quest').click(function(){ var $ans = $(this).next().toggle(10); $anrs.not($ans).hide(); }); $('.ans').change(function(){ var $ans = $(this).closest('.ans'); var $act = $ans.prev().toggleClass('question-active', $ans.find('input:checkbox:checked').length > 0) var items = JSON.parse($.cookie('question-active') || '[]'); var qstName = $act.get(0).className.match(/(questiond*)/)[1]; if($act.hasClass('question-active')){ if($.inArray(qstName, items) == -1){ items.push(qstName) } } else { items.splice($.inArray(qstName, items), 1) } $.cookie('question-active', JSON.stringify(items)) }); var items = JSON.parse($.cookie('question-act

Categories : Jquery

Loss of '+' characters when fetching cookie using perl's CGI::Cookie->fetch
Cookie values are url escaped, which means that spaces are replaced with the + character and other punctuation marks are replaced with %xx codes. The CGI::Cookie::fetch method decodes the value, and the spaces in your cookie value are restored. You can use the raw_fetch method if you don't want the cookie values to be decoded.

Categories : Perl

jQuery: remove a cookie when closing the browser (session cookie)
There is some code that worked for me. It should expire when you close the browser because of the date to expire being before now: var vEnd = new Date(); vEnd.setDate(vEnd.getDate() - 1); var endOfCookieText = "; expires=" + vEnd.toGMTString() + "; path=/"; document.cookie = escape('testCookie') + "=" + escape("eat cookies") + endOfCookieText; FIDDLE MODIFIED Note that the fiddle gives a bunch of load errors on the console for me.

Categories : Javascript

Adding cookie to HttpServletRequest and retrieving cookie from HttpServletResponse using Mockito
For the request: construct the array, adding any Cookies you want, then add the behaviour to the mock: final Cookies[] cookies = new Cookies[] { ... }; final HttpServletRequest request = mock(HttpServletRequest.class); given(request.getCookies()).thenReturn(cookies); ... pass to controller/servlet etc ... For the response you create the mock and then verify the addCookie call by either using an ArgumentCaptor to capture the actual cookie passed to addCookie: final ArgumentCapor<Cookie> captor = ArgumentCaptor.forClass(Cookie.class); verify(response).addCookie(captor.capture()); final List<Cookie> cookies = captor.getValue(); ... perform asserion on cookies ... Or build the expected cookie and verify: final Cookie expectedCookie = ... verify(response).addCookie(expe

Categories : Java

HttpWebRequest: Add Cookie to CookieContainer -> ArgumentException (Parametername: cookie.Domain)
CookieContainers can hold multiple cookies for different websites, therefor a label (the Domain) has to be provided to bind each cookie to each website. The Domain can be set when instantiating the individual cookies like so: Cookie chocolateChip = new Cookie("CookieName", "CookieValue") { Domain = "DomainName" }; An easy way to grab the domain to is to make a Uri (if you aren't using one already) that contains your target url and set the cookie's domain using the Uri.Host property. CookieContainer gaCookies = new CookieContainer(); Uri target = new Uri("http://www.google.com/"); gaCookies.Add(new Cookie("__utmc", "#########") { Domain = target.Host });

Categories : C#

SessionAuthenticationModule Cookie Handler not creating HttpOnly secure cookie
I am using the same implementation and do not see your issue using Fiddler2. However maybe the issue is related to your debugging tool? In IE10 debugging tools the secure and http only flags are only displayed when the cookies are first received. If you check using Chrome debugging tools you should see the flags displayed correctly on all requests.

Categories : Asp Net Mvc

Cookie Code not removing opened element of cookie
Fixed it by using $.map and .join() var openClose = $('.openClose'); openClose.on('click', function() { var cook = ReadCookie('slideHide'), miniParent = $(this).parent().parent().parent().children('.main-content'), miniDisp = miniParent.css('display'); if (miniDisp ==="block") { KillCookie('slideHide'); $(this).parent().parent().parent().children('.main-content').slideUp(); var slide = cook+","+ "#"+$(this).parent().parent().parent().attr("id"); SetCookie('slideHide', slide, 100); } else { $(this).parent().parent().parent().children('.main-content').slideDown(); KillCookie('slideHide'); var newCookie=[], a= $('.module').children('.main-content').filter(":hidden"), c = $.map(a,function(n,i){ return "#"+$(n).p

Categories : Javascript

jQuery cookie plugin creates same cookie instead of read it
$.cookie is only read access if no other parameters (but the cookie's name) are supplied to the method [See the source] If you're interested in reading it, just supply $.cookie('UniqueID') and remove the second parameter. As an FYI, path (and other cookie properties) are only relevant when assigning a value, not retrieving. In other words, you don't need to supply path:'/' to get cookies that are applied to that path, document.cookie should natively perform that check.

Categories : C#

Does a persistent tracker cookie become a session cookie if I setMaxAge(-1)
setMaxAge public void setMaxAge(long expiry) Sets the maximum age of the cookie in seconds. A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age. A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted. Thank you all for your assistance.

Categories : Java

Check if a cookie exists NOT using the jQuery cookie plugin
create a function that returns null or false if the cookie doesn't exist : function getCookie(c_name) { var c_value = document.cookie, c_start = c_value.indexOf(" " + c_name + "="); if (c_start == -1) c_start = c_value.indexOf(c_name + "="); if (c_start == -1) { c_value = null; } else { c_start = c_value.indexOf("=", c_start) + 1; var c_end = c_value.indexOf(";", c_start); if (c_end == -1) { c_end = c_value.length; } c_value = unescape(c_value.substring(c_start, c_end)); } return c_value; } var acookie = getCookie("cookiename"); if (!acookie) { alert("Cookie not found."); } FIDDLE

Categories : Jquery

Create new cookie or add new cookie if one exists using jquery/javascript (or php?)
Your Code seems little strange to me... And if you try it like this: $(document).ready(function() { $("#button").click(function() { if ($.cookie('cookie_1') == null) { $.cookie('cookie_1', $('#phrase_here').text(), {expires: 7}); } else { $.cookie('cookie_2', $('#phrase_here').text(), {expires: 7}); } }); });

Categories : Javascript

Cookie duplicated in document.cookie
The problem was that I had earlier set a cookie with the jquery plugin, which sets the current path as that path for the cookie. The above .Net code sets the path of the added cookie to "/", so there was two different cookies present, which was invisible to me when viewing the document.cookies variable. My solution was to set the path of the jquery cookie to be "/".

Categories : Javascript

Creating a subdomain Auth cookie then redirecting to subdomain loses the cookie in asp.net MVC4
I have good news and bad news. The bad news is-- you can't do it. See here for an explanation. Essentially your server is setting a cookie for a domain it does not contain, so the cookie is rejected. The good news is-- you don't want to do this anyway. Your design violates OWASP 2013 A4 (unsecure and unvalidated direct object reference). In this case you are storing user's access permissions as the domain of the cookie, which a hacker can easily modify. Find a different way to designate subdomain access. There are all kinds of ways to do this. Here is one way that is pretty close to your plan: Store the subdomain in the cookie value itself. Create a secure document container that lists the subdomains to which the user is granted access. You could for example store the subdomain

Categories : Asp Net

Cookie Header in PhoneGap: Refused to set unsafe header "Cookie"
The short answer is no, you can't set the Cookie header. The reason for this is that Chrome is your User Agent, so it is required by the HTTP specification to disallow modifications to headers which have security implications. One solution would be to perform an action that allows the server to set the cookie on your XmlHttpRequest object. You say you're already trying to do this but it's not working. I suspect that's because you need to set withCredentials on your ajax request. Add the xhrFields attribute, as follows. var token; $.ajax({ url: "https://server.com/AuthService/api/account/login", crossDomain: true, xhrFields: {withCredentials: true}, type: 'post', async: false, data: { username: "username", password: "password" } }).done(func

Categories : Javascript

Cookie being set, or not set.? Cookie Set to Array()
You don't say if this is what you're doing, but -- If you set the cookie and try to read the cookie during the same execution of the script, the $_COOKIE array will not yet be populated by the cookie. You won't see it till the next time the browser sends a request to the script.

Categories : PHP

In iOS Safari, cookie data gets destroyed on closing browser from background. I don't want to lose cookie data on closing the browser?
You cant use cookies for that. As @Gajotres was suggesting, you need localStorage API. That way your data will persist till your browser's cache is cleared. To set an array (in your case history_url_array) in localStorage, use var obj = [ {"name" : "blah", "age" : "20" }, {"name" : "blee", "age" : "25" } ] localStorage["names"] = JSON.stringify(obj) On page refresh, to get your array back from localStorage, var obj= JSON.parse(localStorage["names"]) The reason for the use of JSON.parse and JSON.stringify - localStorage takes in only string, so you need to parse obj into string. On getting it back from your localStorage, use JSON.parse to re-parse it to JSON. But mind the browser support. IE has been shaky in its support for HTML 5 components. Here's the su

Categories : Javascript

PHP: Can't Set Cookie
Are you sure the php interpreter doesn't send a char before the setcookie() call for some reason? The function send a HTTP header, so it have to appear before any printing on the page.

Categories : PHP

Cookie not set in mvc 4
Ignore this - see the update below It looks like you are never able to set the cookie. The Accept action in your LandingController is, I assume, the only thing that sets the cookie. However you can never get there because the custom Authorize filter (LandedAttribute) that you've created stops the application from getting there (because the cookie is not set). You probably want to add an [AllowAnonymous] on that action to allow it through so that the cookie can be set. e.g. [AllowAnonymous] public ActionResult Accept() { // body of the action here. } UPDATE I just realised your LandedAttribute is attempting to read the outgoing cookies, not the incoming cookies. You have HttpContext.Current.Response. Use the cookies on the Request, not the Response Your Controller action should

Categories : C#

Getting value from a cookie
Try this library https://github.com/carhartl/jquery-cookie Also see this SO post How to set/unset cookie with jQuery? Example from their docs Read cookie: $.cookie('the_cookie'); // => "the_value" $.cookie('not_existing'); // => undefined

Categories : Javascript

CakePHP Cookie Not Being Set
It turns out cookies arent set until the View is rendered. I had no view for my save_position action, so an error page was showing, which didnt set the cookie. Once I added a save_position.ctp file everything worked okay.

Categories : Cakephp

Odd Cookie Behaviour
The problem is in your call to setcookie. The third argument expects a timestamp, not a duration. Here, your cookie expires before even existing. You should try : setcookie('admin', $cookieValue, time() + 3600, '/');

Categories : PHP

Cookie is not delete in mvc(c#)
You're changing the value of the cookie, but you're not adding it to the response again! FormsAuthentication.SignOut(); HttpCookie c = Request.Cookies[FormsAuthentication.FormsCookieName]; c.Expires = DateTime.Now.AddDays(-1); // Update the amended cookie! Response.Cookies.Set(c) Session.Clear(); /* Get rid of this, it will break the above by clearing * the cookie collection that you've just updated. */ // Request.Cookies.Clear(); // Response.Cookies.Clear();

Categories : C#

Cookie not set with jQuery
What you are doing wrong is the cookie.js doesn't link to a javascript file, it links to a GitHub Gist page https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js Just copy the code into JSFiddle and then alert(myCookie); // Will work Demo CDN : http://cdn.jsdelivr.net/jquery.cookie/1.3.1/jquery.cookie.js

Categories : Jquery

Not able to clear cookie what ever I do using PHP
$_SERVER['HTTP_COOKIE'] is a semi-colon delimited list of key-value pairs in the form: key1=value1;key2=value2;key3=value3;... You split the string at the ;, but not the = I think you might be looking for something like: $name = 'keepsignin'; if (isset($_SERVER['HTTP_COOKIE'])) { $cookies = explode(';', $_SERVER['HTTP_COOKIE']); foreach ($cookies as $cookie) { list($cookie_id, $cookie_value) = explode('=', $cookie); if($cookie_id === $name){ self::set_cookie($cookie_id, $value, $expiry, $path, $domain); } } } Note the use of list() to assign $cookie_id and $cookie_value in one operation.

Categories : PHP

JS set cookie not being read in PHP
put this code in your index.php page if(isset($_COOKIE['uniqueID'])=='') { $uniquenum = rand(1000, 10000); setcookie('uniqueID',$uniquenum,time() + (86400 * 7)); // 86400 = 1 day } than fetch cookie value using if(isset($_COOKIE['uniqueID']) && !empty($_COOKIE['uniqueID'])) { }

Categories : PHP

Using javascript to set cookie in IE
The following sample code will demonstrate setting a cookie of your choosing directly, without requiring input from the user. To store a cookie from your site, simply put a call to the javascript function in your HTML page, like this: <script type="text/javascript">cookieSet();</script> The real work is done by the cookieSet() javascript function, which can be either in the area of your HTML page, or in a separate javascript file: var cookieText = "Put your desired cookie value here"; var cookiePrefix = ""; var myPage = location.href; var wwwFlag = myPage.indexOf('www'); if (wwwFlag > 0) { cookiePrefix = "www"; } var cookieName = cookiePrefix + "cbCookie"; function cookieSet() { if (document.cookie != document.cookie) { index = document.cookie.indexOf(cookieName); } els

Categories : Javascript

PHP Expire cookie
If you want to delete a cookie, then just set $expire time to be in the past: setcookie("loggood", "", time() - 3600); setcookie("user", "", time() - 3600); Notes from PHP documentation: When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser.

Categories : PHP

Can't read cookie except in IE
SOLVED The problem was in the ports used. What was happening was that the requests were being made to port 8081 (there was a proxy forwarding requests to the final destination, listening in port 8081), but apparently only IE has no problemas with that port for http requests. So we changed our nginx server (in http://mysub.mydomain.com) to redirect the requests to port 80. I know I didn't say anything about ports or the proxy in my question, but that's because I don't know enough about cookies and didn't think it had anything to do with it - my bad. And sorry for that. Anyway, this was the solution to my problem.

Categories : Javascript

php cookie not rewrite the new value
Can you try this, it works for me. I edited the code a bit, sorry for obfuscating it with one line if-statements. I also set the cookie time to 1 day so it won't disappear when testing the code. And remember, you have to update the page to read the new cookie, it will be one step behind $lng. <?php $allowed = array('en', 'de'); $chosen = $_GET['lng'] ? $_GET['lng'] : ($_COOKIE['lang'] ? $_COOKIE['lang'] : 'en'); $lng = in_array($chosen, $allowed) ? $chosen : 'en'; setcookie("lang", $lng, time()+24*60*60, '/'); var_dump($_COOKIE['lang']); echo $lng; ?>

Categories : PHP

How to set a cookie in casperJS
Probably, the page has not received the cookie. You can try using the same code in load.started event listener. Also, add a evaluate script to check the existence of the cookie on each stage of the page load. That might help.

Categories : Javascript

My Cookie is not set correctly
You need to define what username contains. Otherwise it will be NULL $username = $get_array['username'] Assuming $userdata is not empty, because otherwise the sql query will never be executed UPDATE It is a really bad idea to call md5($username) as a session id, because this id will be the same every time you login and you can impersonate another account if you know the username

Categories : PHP

var from javascript cookie being ignored
window.time=sec in the line: document.cookie = 'window.time=sec; expires=Thu, 2 Aug 2091 20:47:11 UTC; path=/; ;domain=.nekamera.ru' is never actually interpreted by the parser, but only stored as a string. What you want to do is store the time in a string format, then parse that string into a variable in subsequent requests. Set cookie: document.cookie = 'time=' + sec + '; expires=Thu, 2 Aug 2091 20:47:11 UTC; path=/; ;domain=.nekamera.ru' Read cookie: // from w3schools function getCookie(c_name) { var c_value = document.cookie; var c_start = c_value.indexOf(" " + c_name + "="); if (c_start == -1) { c_start = c_value.indexOf(c_name + "="); } if (c_start == -1) { c_value = null; } else { c_start = c_value.indexOf("=", c_start) + 1;

Categories : Javascript

Set Cookie File Name
You can't decide what file name a cookie should have when it's saved, that's up to the browser. The only thing you can do with cookies is storing information in them and reading it later again.

Categories : Javascript

Set cookie using JavaScript if not already set
This would be one way to check if the cookie is already set: if (document.cookie.indexOf("language=") < 0) setCookie("language", "fr"); Note that this will also not set the cookie if any cookie has a name ending on language. Edit: Here is a proper function to check if a cookie with a certain name already exists. function cookieIsset(name) { var cookies = document.cookie.split(";"); for (var i in cookies) { if (cookies[i].indexOf(name + "=") == 0) return true; } return false; } With which you could just do if (!cookieIsset("language")) setCookie("language", "fr"); How to onload: In your <head> area add the following: <script type="text/javascript"> document.onload = function () { // code ... }; </script>

Categories : Javascript

Getting cookie value or getting data from DB?
They both serve a different purpose. Cookies are used to store preferences and are disposable in a sense that if they aren't available (like the client deleted them) the preferences switch to defaults. Database on the other hand would store data that should persist through-out the application's life. For example, user login data. You can't save that as cookies for security reasons as well as that you may lose them any time. Cookies can only save text whereas you can practically save anything in a database as binary objects. Any preferences saved with Cookies would only take effect if the user uses the same browser that the cookies were stored on. So, databases are also more suited for any preferences that should be mobile.

Categories : Java

Setting a cookie from url
Nevermind i got it working like so: var url = "(location.href.match(/utm\_source=google/ig))"; if (location.href.match(/utm\_source=google/ig)){ $('body').addClass('test'); $.cookie('number', 'url'); } if ($.cookie('number')) { $('body').addClass('test'); }

Categories : Jquery

How to set more than one cookie in nodejs?
According to the setHeader example in the docs, you can specify an array of values. Since this commit it should work for writeHead as well.

Categories : Javascript

Cookie through a form and GET
Enclose your productname variable in quotes, like this $result=mysql_query("SELECT * FROM products WHERE prodname='$prodname'")or die('ln 61 :'.mysql_error()); Because there might be case when your product name be two words with a space, where query fails

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.