473,325 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Set cookie and redirect user to a visited subdomain

3
The cookie is not holding and the domain example.com cannot redirect to a.example.com when I type on the address bar. Anyone good at cookies? Any help will be very much appreciated.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="/static/js/jquery-1.3.2.min.js"></script>
  2. <script type="text/javascript">
  3. $(function(){
  4.     var city = readCookie('city');
  5.     if(city !=null && city !=''){
  6.     window.location.href = 'http://' + city + '.example.com';
  7.     }
  8. $('#citygo').change(function(){
  9.     var city = $(this).val();
  10.     window.location.href = 'http://' + city + '.example.com';
  11. });
  12. });
  13.  
  14. function createCookie(name,value,days) {
  15.     if (days) {
  16.         var date = new Date();
  17.         date.setTime(date.getTime()+(days*24*60*60*1000));
  18.         var expires = "; expires="+date.toGMTString();
  19.     }
  20.     else var expires = "";
  21.     document.cookie = name+"="+value+expires+"; path=/";
  22. }
  23. function readCookie(name) {
  24.     var nameEQ = name + "=";
  25.     var ca = document.cookie.split(';');
  26.     for(var i=0;i < ca.length;i++) {
  27.         var c = ca[i];
  28.         while (c.charAt(0)==' ') c = c.substring(1,c.length);
  29.         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  30.     }
  31.     return null;
  32. }
  33. function eraseCookie(name) {
  34.     createCookie(name,"",-1);
  35. }
  36. </script>
  37.  
  38.  
  39. <select id="citygo">
  40.     <option value="0">Select City</option>
  41.     <option value="amsterdam">Amsterdam</option>
  42.     <option value="newyork">New York</option>
  43.     <option value="london">London</option>
  44.     <option value="cardiff">Cardiff</option>
  45. </select>
Dec 3 '13 #1
3 3998
Dormilich
8,658 Expert Mod 8TB
the cookie is not holding because cookies are saved per domain (for security reasons), and since you change the domain …
Dec 4 '13 #2
gmax
3
Any solution Dormilich? Thanks.
Dec 4 '13 #3
Dormilich
8,658 Expert Mod 8TB
sorry, nothing I know in JS. maybe you could do something via server-side scripting.
Dec 4 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Noozer | last post by:
Is it possible to redirect a user to another web page using ASP code located in page body? I have some ASP code that runs after generating some output to the browser. It checks for a condition...
1
by: -------- | last post by:
Hello I've been looking for a small snippet of code which I haven't had much luck finding. I was wondering if anyone is aware of a script that might be able to do the following for me: On my...
0
by: sampriti | last post by:
Hi, Is it possible to redirect user to same webserver until his session ends? Thanks in advance
1
by: New ASP.NET User | last post by:
I want user to redirect to another page after some interval. I used Httpresponse Page object (Response.redirect("default.aspx") but it transfers right a way... Any itdeas... Thanks in...
2
by: John | last post by:
On my web app I require a user to log in so I can validate them. At times I'll be sending emails out for a reporting page in the web app, How can I have the user goto the link I sent to them after...
1
by: vunet.us | last post by:
Imagine: user clicks the link which brings him/her to a secure page (let's call it page "X") which requires login session. If user is not logged in, he/she is redirected to a login page. Question:...
1
by: Jon Paal | last post by:
what is property to redirect user after successful login ? <asp:Login ID="Login1" runat="server" ?????
2
by: sindhudixit | last post by:
Hey, I am having a user fill out a form then the fields are going to uploaded to my database. So, at this point, when the user hits the submit button I want three things to happen: 1. The...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app. When session is invalid, how to redirect user to the login page? I don't want to add the code to redirect user to the login page into every page. Thanks, -Billy
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.