473,387 Members | 1,416 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,387 software developers and data experts.

php set subdomain cookies and redirect

3
I have the cookies and subdomain selection for header:

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. function createCookie(name,value,days) {
  14. if (days) {
  15.     var date = new Date();
  16.     date.setTime(date.getTime()+(days*24*60*60*1000));
  17.     var expires = "; expires="+date.toGMTString();
  18. }
  19. else var expires = "";
  20. document.cookie = name+"="+value+expires+"; path=/";
  21. }
  22. function readCookie(name) {
  23. var nameEQ = name + "=";
  24. var ca = document.cookie.split(';');
  25. for(var i=0;i < ca.length;i++) {
  26.     var c = ca[i];
  27.     while (c.charAt(0)==' ') c = c.substring(1,c.length);
  28.     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  29. }
  30. return null;
  31. }
  32. function eraseCookie(name) {
  33. createCookie(name,"",-1);
  34. }
  35. </script>
  36. <select id="citygo">
  37. <option value="0">Select City</option>
  38. <option value="amsterdam">Amsterdam</option>
  39. <option value="newyork">New York</option>
  40. <option value="london">London</option>
  41. <option value="cardiff">Cardiff</option>
  42. </select>
Now I need to work on the server side to set cookies to remember and redirect to a visited subdomain. The code below is not working but should be something like that. Would someone show me how to set cookie? Any help will be very much appreciated.

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. if (isset($_COOKIE["city"])) { 
  3. if ($_COOKIE["city"] == 'city') { 
  4. header("window.location.href = 'http://' + city + '.example.com'"); 
  5. ?>
Dec 4 '13 #1
0 4296

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

Similar topics

0
by: Lucifer | last post by:
Hi I have some code for checking for cookies, that sets a cookie on page1 and checks for it on page2. and its based on the code by MS: ...
0
by: Leon | last post by:
How do I point a sub-domain to a sub-directory or .aspx page of my site using asp.net? I'm using a shared hosting service, that does not offer subdoman forwarding. however, you can write your...
4
by: Leon | last post by:
Is it possible to allow my website user's to enter the site using a subdomain name such johndoe.mywebsite.com then a automated script in the Global.asax file within the Application_BeginRequest...
2
by: Abdul Qadir Khan | last post by:
Hi, We have different web sites e.g www.abc.com, www.xyz.com I want to read cookies written by www.abc.com from www.xyz.com and vice versa. Please advise. Thanks AQ.
1
by: Michael Horton | last post by:
SQL Version: 2000 OS Version: Server 2003 I've got a sub-domain (test.mydomain.com) that I use for testing. In it I've got some un-common files available for download (.car extension) along with...
3
by: Maximus | last post by:
I have a registration form, when after registering, the user would get a subdomain http://username.domainname.com I created a wildcard DNS which happened to redirect *.domainname.com to the...
2
by: flip79 | last post by:
Hello and sorry for my english, I'm italian... I manage a site with a normal address like: www.mysite.com I'm using a cookie to store nicks of my users, with a code like this: ----...
2
tolkienarda
by: tolkienarda | last post by:
hi all i have a wildcard subdomain that will redirect all subdomains to one page. this page is a php script that will read the what subdomain they entered and if it is valid it will redirect to...
8
by: stiv | last post by:
I want to give users of my site the option to register for a subdomain redirection service. I scanned the Internet for some script, but didn't really find anything that works. Tried the PHP script...
3
by: gmax | last post by:
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. <script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.