Setting up cookies craigslist style?

Discussion in 'Programming' started by balzak, Jan 21, 2008.

  1. #1
    I want to set up a web site that has works kind of like craigslist.org.


    What I am talking about is if you clear your cookies and go to craigslist.org, you will be brought to their main page with a list of all the locations. For instance, you click on "Denver" and it brings you to denver.craigslist.org.

    Now, whenever you go to craigslist.org, you are automatically forwarded to denver.craigslist.org until you navigate to another location such as atlanta.craigslist.org and from that point on you are automatically forwarded to atlanta.craigslist.org.

    I'm making sense, right?

    Well, I am wondering how I could set this up. Basically, I want to have a site that will have different locations that the user can click on and once that person clicks on a location, whenever they go to the main site again they will automatically be forwarded to the site for that location. It will either be location.domain.com or domain.com/location, it doesn't really matter to me at the moment if I use a subdomain or a subdirectory.


    What is the easiest and least technical way to do this for someone who is unfamiliar with programming languages?

    Thanks in advance.
     
    balzak, Jan 21, 2008 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    Dim location As String = Request.Cookies("location").Value
    If Not String.IsNullOrEmpty(location) Then
           Response.Redirect("http://www.yourdomain.com/" & location)
    End If
    
    Code (ASP):
    The above is a very simple way of achieving what you want with the code to sit in the landing page (assuming you want it to run everytime someone hits the landing page)
     
    AstarothSolutions, Jan 21, 2008 IP
  3. balzak

    balzak Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So, "location" is a variable that is pulled from the cookie that was received from one of the location pages?

    So basically, this code is for the landing page?

    How do I make the cookie for the location pages? I tried looking at the source of craigslist.org for clues but did not see anything.
     
    balzak, Jan 21, 2008 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I would create a sub routine held centrally and then just call it with the location details - the below example is for a cookie that lasts 14 days

    
    Shared Sub AddLocation(ByVal Location As String)
            Dim TheCookie As New HttpCookie("location")
            TheCookie.Value = Location
            TheCookie.Expires = Now.AddDays(14)
            HttpContext.Current.Response.Cookies.Add(TheCookie)
    End Sub
    
    Code (ASP):
    To call it would then just be AddLocation("NewYork") as an example
     
    AstarothSolutions, Jan 22, 2008 IP