Rupert Burr
Rupert Burr

Reputation: 1

PHP page to remember visitor's selection to forward them automatically on their next visit

After extensive research, I can't find the solution anyway for this, and it's frustrating and after days of smashing the keyboard, shouting at the sky and taking long meandering walks to calm down - we've all been there! But what's worse, I'm pretty sure my hairline has receded a fair bit from all this...

What I have found, either sniff out the IP to automatically redirect you or uses a form to set the cookie, non of which help, unfortunately.

I've tried and tried to get something working but I just can't get my head around this one.

Help me Obi Wan Kenobi your my only hope, thank you!

Upvotes: 0

Views: 793

Answers (1)

KARASZI István
KARASZI István

Reputation: 31467

First of all you need to identify the user. The easiest way is to store an HTTP cookie in the visitors' browser.

You can set this with PHP, JavaScript, it does not matter because the stored cookie will be the same regardless of the method you select. But you need to aware of that the maximal age of the HTTP cookie needs to be set to a month or so.

On the second visit you check the stored cookie on the server side and redirects the user to the selected page (but keep in mind that an option should be there to change this first decision).

So, the steps:

  1. check whether a cookie exists ($_COOKIE array in PHP)
  2. if does not exist show the selection page
  3. if the user selected store his/her decision with setcookie for example
  4. if it does exist, redirect to the previous selection with header("Location ...") redirect

Upvotes: 1

Related Questions