开发者

wordpress, category redirect using cookies

What I want to achieve: When a person comes to the site and selects a particular category, the next time they come to the site (returning user) - the page will open up on that category section.

I would think this would be fairly easy to do via setting a cookie when the v开发者_JAVA技巧isitor clicks on the category link (or when the category page loads). When they return the following time, the cookie is read and then the page redirects accordingly.

Unfortunately my knowledge of PHP and cookies is limited, (hence my search for answers) so I need to ask if anyone can help me out!

Anyone have any ideas?

Thanks!


The first thing you need to do is set the cookie for the category so each time you are displaying the category page you want to run code like the following:

  <?php
    $expire=time()+60*60*24*30;
    setcookie("cat", "/cat1", $expire);
  ?>

Then when a user hits your home page you want to check if that cookie is set.

<?php
   if (isset($_COOKIE["cat"]))
   {
       //Redirect to that page stored in the cookie
       $_COOKIE["cat"]; //Theres what you need you can handle the redirect how you like
   }
?>


Take a look at this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜