www.webdeveloper.com
Results 1 to 2 of 2

Thread: Set Cookie Redirect

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Set Cookie Redirect

    Would someone show me how to set cookie redirect like craigslist site?

    For example, if I go to craigslist site (http://www.craigslist.org/about/sites/) and click "auburn" under Alabama it will take me to auburn.craigslist.org page. If I exit then go back to craigslist.org it automatically redirect me back to auburn.craigslist.org page.

  2. #2
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    Yeah, just give a cookie upon selection.

    So you would have a select box like so.

    HTML Code:
    <select name="location">
    <option value="GA">Georgia</option>
    <option value="AL">Alabama</option>
    </select>
    Than in php you have.
    PHP Code:
    <?php
    $hour 
    time() + 50400;  //Time you want the cookie to last, currently 14 hours
    setcookie(My_Site_Location$_POST['location'], $hour);
    ?>
    Than at the head of your page you check and redirect

    PHP Code:
    <?php
    $Loc
    =$_COOKIE["My_Site_Location"];
    if(isset(
    $_POST['My_Site_Location']))
    $Loc=$_POST['My_Site_Location'];

    if (empty(
    $Loc))
    {
    header("Location: Website.com/index.php"); 
    } else {
    header("Location: Website.com/$Loc.php"); 
    }
    ?>
    Something to that effect not sure if that 100% correct but it should get you in the right direction.
    Albert Einstein ~ "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction."

    Things To help you on this Site

    1. Place all php code in [php] Tags
    2. Place all html code in [html] Tags
    3. Remember to mark all your Threads Resolved using thead tools at the top when your problem is solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles