Forum Moderators: open

Message Too Old, No Replies

Localhost and cookies

Just a quickie

         

chris_f

2:31 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


Does anyone know if cookies are stored when viewing a localhost site?

I have setup the development environment my laptop. I also test my sites on the laptop using http://localhost/sites/sitename/default.aspx

Simply, will my machine store cookies of the local sites?

Chris.

JuDDer

2:45 pm on Jul 14, 2002 (gmt 0)

10+ Year Member



yep - try it

Nick_W

2:49 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


Shouldn't be a problem at all. Is it a Windows thing? On linux you can set up http://yoursite.com which makes it really easy to transfer to a live server...

Just curious ;)

Nick

Lisa

5:34 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


I remember this problem from the 90's, localhost will not store cookies, the RFC will not allow it because you are using a name resolution and that name doesn't have an extension. Cookies are designed for second level and down. First level domains will not work. Hence localhost has no root extension. But you can get around this by using an IP address like http://127.0.0.1/sites/sitename/default.aspx

If you try this address it should work. 127.0.0.1 is your computer.

dcheney

5:45 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


You can also add an secondary entry to your hosts file. Something like this:

127.0.0.1 localhost
127.0.0.1 yourtestname

Then just use http://yourtestname/ and all should be well.

Lisa

5:51 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yourtestname will not work either... You must have an extension on the domain or use an IP address.

JuDDer

5:55 pm on Jul 14, 2002 (gmt 0)

10+ Year Member


I have no problems storing cookies from local sites at all.

eg,
http://mysite,
http://anothersite
http://localhost
http://127.0.0.1

etc etc all running locally, setting and reading cookies no problems at all. All local sites served through IIS5.

dcheney

6:02 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can simply replace "yourtestname" with "yourtestname.edu" if that is really a concern. On my system (win98se) current versions of Opera, NN, and IE all accept cookies perfectly with a no-extension machinename. (Normally I test with a no-extension machinename, but I've been doing some language testing with something like "yourtestname.cl" and cookies still work fine.)

[edited by: dcheney at 6:04 pm (utc) on July 14, 2002]

Lisa

6:03 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using MSIE5/6 and ISS5? Try using Netscape or Mozilla. Do cookies still work?

[cis.ohio-state.edu...]

Perhaps later version of Microsoft apps ignore the RFC. That would make me mad. Why can't Microsoft follow the RFCs. The reason for this RFC was security. By the breaking the RFC guidelines they introduce security issues.

Xoc

2:55 am on Jul 15, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To test domains on your local machine, there is an easy solution: Open the file \winnt\system32\drivers\etc\hosts. It doesn't have an extension. It will probably have an existing line that reads:

127.0.0.1 localhost

It is this line that makes the mapping between the domain "localhost" and the 127.0.0.1 IP address, which is the loopback IP address.

So all you have to do is add another line:

127.0.0.1 www.domain.com

This will map www.domain.com back to the local machine as well. Of course, use your domain, not domain.com. I use this all the time. It essentially acts as DNS (Domain Name Service) for the local machine.

[edited by: Xoc at 7:52 pm (utc) on July 15, 2002]

chris_f

7:34 am on Jul 15, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow, what a response. Thanks Alot.

>>> Is it a Windows thing? Yep!

>>> If you try this address it should work. 127.0.0.1 is your computer. Will try it

>>> Are you using MSIE5/6 and ISS5? I'm using IIS5 with the browsers Netscape 6.2, Opera 6.03 (latest one), MSIE 6 and MSIE 7ALPHA (a very poor looking browser. I'm hoping they scrap the project and conserntrate on getting IE6 working).

Xoc, Where on earth do you get all this knowledge from? I'll give you idea a go.

I'll be busy tomorrow night trying to get this working.

Thanks again.
Chris.

Xoc

7:58 pm on Jul 15, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remember that if that line is in the hosts file, then Windows will only look for that domain on the local machine. So you won't be able to see what it looks like on the server after you post the files unless you remove the line. So my convention is to add an "l" (lowercase L) to the domain name for the local machine, as in lwww.domain.com. So this domain is the local machine, whereas, www.domain.com is the content on the server.

After you have the line in there, cookies should work fine since you are now working with a third level domain.

I found this by searching on the Microsoft web site when I was trying to figure out how to test web sites. I found this article [support.microsoft.com]. The Microsoft web site is an amazing source of knowledge, and I always search there when I have a question about how to do something with a a Microsoft product. After that, I try the Google Microsoft Search [google.com], which expands the search to the entire web. Of course, coming here is another solution.

tomasz

8:18 pm on Jul 15, 2002 (gmt 0)

10+ Year Member



I am using cookies as well and don't have any problems.
Look in your cookies folder and you should find entry like this 'localuser@localhost[1]'

chris_f

4:47 pm on Jul 16, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok. Thanks guys. It must be a coding issue.

chris_f

5:05 pm on Jul 16, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok. This is interesting. My project doesn't seem to hold it's cookies. If I do:

Response.Cookies("VisitedBefore").Value = "Confirmed"

Dim VisitedBefore As String
If Request.Cookies("VisitedBefore") Is Nothing Then
VisitedBefore = "No"
ElseIf Request.Cookies("VisitedBefore").Value = "Confirmed" Then
VisitedBefore = "Yes"
Else
VisitedBefore = "Error"
End If

Response.Write(VisitedBefore)

I get the Yes response.

If I then remove the line which creates the cookie I get the no response dispite the fact that I haven't deleted my cookies and it should be there from the last run of the code.

Chris.

JuDDer

5:20 pm on Jul 16, 2002 (gmt 0)

10+ Year Member



You may be having problems because you are not setting an expiry date for your cookie - might be worth looking into as I would imagine that the cookie is either expiring right away, or as soon as your session has terminated on the server.

Added:
Your may try something like this to set the expiry date of the cookie:

Response.Cookies("VisitedBefore").Value = "Confirmed"
Response.Cookies("VisitedBefore").Expires=Date()+5

Xoc

5:40 pm on Jul 16, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is certainly true that if you don't set an expiration date, the cookie is supposed to be killed as soon as the web browser is closed. It also changes which category the cookie falls under in the IE security settings. This becomes a session cookie (meaning browser session) as opposed to a permanent cookie.

Brett_Tabke

5:54 pm on Jul 16, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



>hosts

What I do, is keep two sets of hosts files. One hosts file uses all my online sites mapped to local hosts/ips. The other hosts file is the stock file I use for net surfing.

I use a batch file to copy either hosts file to the live "hosts" file in \windows. By then making an icon to the batch files, I can toggle in/out the mode I'm in.

Unfortunatly, this only works with Opera and Mozila. IE caches dns info for a very long time and you either have to reboot with IE, or crash (task list kill) and restart explorer. (any way of nuking IE's resolved dns info?). Another way, is to flip on a proxy serve and back - that reresolves ips<->domains from the hosts file.

chris_f

6:02 pm on Jul 16, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Of course,

Solved now. Thanks.

Chris.