0

I am curious to know how sites - craigslist - for instance, can automatically go to a sub-domain after the first time you have chosen your location. Do they use cookies, or something else.

Let's say that I want users to be on a sub-domain after being signed in. How is this accomplished?

I tried posting my question on meta exchange but they suggested to come here.

Gacci
  • 1,388
  • 1
  • 11
  • 23
  • Can you please explain to me how is this a duplicate. I mentioned cookies, does not mean it does use cookies. That was just a thought, maybe I am wrong. – Gacci Dec 21 '18 at 03:44
  • Specifically craigslist does use cookies and an iframe, however the referenced possible duplicate has answers covering multiple methods that accomplish what you are wanting to achieve. – Will B. Dec 21 '18 at 03:48

2 Answers2

0

There are many ways to do an auto redirections.

  1. If your site have your own login system, you can simply store it as part of the user profile in database. And its simply a matter of passing on session id in your redirection attempt.

  2. If there is no login system, you the most obvious way would be cookies with or without server session.

  3. You may also handle the user preferences using localStorage and indexedDB to store information on the client's browser.

Koala Yeung
  • 7,475
  • 3
  • 30
  • 50
0

Redirection

You can redirect visitors whenever you want to other sites under different cases asigned even from your back-end language or directly from the front-end content, just doing one of this:

  1. Back-End using PHP, the following line should be the FIRST thing sent to Front-End:

<?php header("Location: http://www.example.com/") ?>

  1. Front-End using JavaScript:

window.location.replace("http://www.example.com");

  1. Front-End using HTML meta (the first parameter in content is the amount of seconds after which the visitor will be redirected):

<meta http-equiv="refresh" content="0; url=http://www.example.com/" />

DavidTaubmann
  • 3,223
  • 2
  • 34
  • 43
  • Thank you David. I am fairly familiar with the concepts you mentioned. However, what I looking for is to guarantee a sub-domain once the user is logged in. While I can redirect the user can still remove the sub-domain and be logged in, or am I taking the wrong approach. – Gacci Dec 21 '18 at 04:47
  • Then you should deffinitely check Cross-Domain Sessions – DavidTaubmann Dec 21 '18 at 04:48