lazerbrains Posted September 19, 2011 Share Posted September 19, 2011 Have a site, and when people come to it, I would like to redirect them to a page on a different site, the first time they visit. (I am switching domain names, and would like to introduce the new site this way) So when they go to my current domain, I would like to redirect them to the new one, and also create a cookie. Then if they try to go back to my old domain again, it will recognize the cookie, and allow them to proceed as normal. However, I am new to setting cookies, and am not sure how to do this. Or if javascript is even the right choice. Does anyone know how to do this, or have an example they can show me? Quote Link to comment https://forums.phpfreaks.com/topic/247458-set-cookie-to-redirect-to-splashpage-once/ Share on other sites More sharing options...
.josh Posted September 20, 2011 Share Posted September 20, 2011 are you using a javascript framework on your old site, like jquery, mootools or prototype? Quote Link to comment https://forums.phpfreaks.com/topic/247458-set-cookie-to-redirect-to-splashpage-once/#findComment-1270854 Share on other sites More sharing options...
lazerbrains Posted September 20, 2011 Author Share Posted September 20, 2011 are you using a javascript framework on your old site, like jquery, mootools or prototype? Actually, it is a few of sites that are being combined under one new domain. So one of the sites is Joomla, and the other is just a standard HTML based site, a third, but not as important one is using Symfony (PHP framework). It would be nice to have a redirect that could work on all 3, redirect them to the new domain, which announces the change. (only once) After the first time they are redirected, it should allow them to go to the old domain uninterrupted. I was thinking a cookie might be the right tool for the job. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/247458-set-cookie-to-redirect-to-splashpage-once/#findComment-1271009 Share on other sites More sharing options...
.josh Posted September 20, 2011 Share Posted September 20, 2011 yah, cookie is probably a good way to go. For reading and setting a cookie, you can grab a couple of functions for that here. And then basically on your page(s), you would have something like // if cookie doesn't exist, set cookie and redirect user if (getCookie("cookieNameHere") != "redirected") { // set a cookie named cookieNameHere with a value to look for, to expire in a year. // it doesn't really matter what you name the cookie as long as you don't name it some other cookie name being used on your site(s). // it doesn't really matter what value you set it as, as long as you set it with something and look for that same something later. // how long you set the cookie is up to you, based on your own timelines setCookie("cookieNameHere","redirected",365); // redirect user to new site location.href = "new site url here"; } Quote Link to comment https://forums.phpfreaks.com/topic/247458-set-cookie-to-redirect-to-splashpage-once/#findComment-1271100 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.