0

I have a site at mysite.com/index.html and replicated site at mysite.com/test.html.

I need to set cookie for visitor who visited mysite.com/test.html , so if he types in browser mysite.com ,he will be redirected to mysite.com/test.html for next 30 days.

I'm using jquery.cookie.js plugin

I have placed in mysite.com/test.html following code:

$.cookie('test', 'test', { expires: 30, path: '/' })

And on mysite.com/index.html

$(function() {
    if ($.cookie('test')) window.location.href = 'http://www.mysite.com/test.html';
});

I'm very new to js and jquery,so please tell me if it's a correct way to set cookie,read and redirect.

Thank you.

yas
  • 143
  • 1
  • 1
  • 8
  • what is the problem you are having? – Ibu Oct 17 '13 at 23:06
  • @Ibu I'm asking if its a correct way,because I'm very new to jquery,but I need to make sure that this will do the job.Thanks – yas Oct 17 '13 at 23:10
  • I don't see why it shouldn't, try it on your page and see for yourself. By the way it would be much better to do redirection on the server side, this will save you one extra request – Ibu Oct 17 '13 at 23:12
  • You might prefer `window.location.replace`, see http://stackoverflow.com/a/506004/73027 – codemonkeh Oct 17 '13 at 23:15
  • @Ibu Can I place this 'if(isset($_COOKIE["test"])) { header("Location: http://mysite.com/test.html" . $_COOKIE["test"]) }' in head on html page to make a server side redirect? And thanks for reply. – yas Oct 17 '13 at 23:16

0 Answers0