Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Cookies Question 1

Status
Not open for further replies.

Supra

Programmer
Dec 6, 2000
422
US
As I understand it, if I use the following header..
Code:
Content-Type: text/html
Set-Cookie: Username=Justin;
Set-Cookie: Password=Password2;
..those cookies should remain until I close the browser since I didn't set an expiration date. So correct me if I'm wrong, but shouldn't navigating to a different page on my website send the cookie along? I have my website set to use index.pl as the index of each directory. So if a user logs in, then navigates to a different area of the site with the above header set, shouldn't that cookie persist? I'm new with this type of thing, but that's what the tutorial I read made it seem like. Also, I do realize that you shouldn't store the username and password in the cookie without encryption of some sort. I do have an encryption method that I developed myself. Thanks in advance for help with this newbie question ;|
 
Don't dream of ``rolling your own'' cookies. Use the cookie-generation from the CGI module. It will take care of relevant quoting and layout, leaving you only needing to specify the data. Details here.
 
Well I already know how to handle the cookies so that module doesn't do me any good. It just simplifies the creation and retrieval of cookies. I can already create them and get them, I just need to know if they are sent in this manner. Any idea?
 
My guess is that what ishnid suggests is that 'rolling your own' is what has you in this predicament.

Trust me, I too was once a fan of reinventing the wheel, and one day I woke up, and smelt the proverbial roses. It doesn't just simplify the creation of headers and cookies, it creates them in a proven and tested format that is in use by thousands of websites all over the world.

For kicks, try a corresponding script in using the CGI module, and compare the output, that at least would identify where the issue is with your own, if indeed it is a server side problem.

an hypothesis is ..., the Content-Type header should have two newline characters at the end.

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Hmm, I'm not reinventing any wheels here, I'm just writing out the header instead of having a module do it for me. I've written tons of programs using Winsock that emulate a browser and not had any issues whatsoever with cookies. The issue I'm getting here is that the cookie doesn't seem to be sent when I click a link. You don't need 2 newline characters after the Content-Type line. You need 2 newline characters after the entire header. Content-Type is nothing more than a parameter which is specifying what type of content the document contains. It can be first, last, or in the middle of the header it doesn't matter. I am set on doing this the "hard" way, but I appreciate your help regardless. When I figure out the problem I'll post back.
 
With that code, the cookie will be present in the directory the script that set it is located in, along with its subdirectories. You need to set the `path' of the cookie too to have it appear site-wide.

You say you're not "reinventing any wheels". This is the definition of reinventing programming wheels. The code to do what you want is already bundled with Perl as standard. Plus you're also creating your own encryption code. CPAN and its modules are the biggest reason there is for using Perl. Not making use of them places huge limits on you.

Don't get me wrong. I'm not trying to say that your code is necessarily inferior to others' (though CGI is used and tested by many, many very, very good programmers). But unless you've a particular academic interest in encryption or network protocols, you're wasting time not using the modules for these types of tasks.
 
I see your point, but I just generally don't like to use modules when I don't have to. I guess I just like to have everything as low-level as possible. But I do see your point and it makes sense. As for the cookies, I haven't worked on the site since my last post due to sheer lack of time, but I will try specifying a path as soon as I do, thanks! I know my encryption code won't be nearly as good as many others out there, however I think it's pretty good for a case-sensitive 2-way encryption method. I just wanted to create a website completely from scratch using only Notepad, and I want every script to be as original as possible. Not that using modules isn't original - I mean they are part of Perl after all - but I just like to do things the hard way I guess. Thanks again for your help ishnid, I will try it soon!
 
Supra said:
I haven't worked on the site since my last post due to sheer lack of time
Free up some time by using modules instead of grubbing about with low level coding? [wink]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top