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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another question regarding cgi & cookies. 1

Status
Not open for further replies.

Dirtrocker

Technical User
Mar 31, 2002
74
US
I have a forum program which I would like to add cookies so folks don't have to enter their name every time.
I have searched all over to try and find out how I would do that, but am clueless.
Here is what I have.
I'd like to make it so the folks don't have to enter their name everytime. Is that possible?
Is there something in the cookies that tells you what they do? The program has a cookie-lib.pl file, but I don't understand what it is for or what it does. Is there someplace that explains it for dummies like me?

print qq~
<tr><td bgcolor=&quot;#E8FFFF&quot; align=&quot;right&quot;>NAME:</td>
<td bgcolor=&quot;#E8FFFF&quot; align=&quot;left&quot;><INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot; SIZE=&quot;30&quot;></td></tr>
<tr><td bgcolor=&quot;#E8FFFF&quot; align=&quot;right&quot;>EMAIL:</td>
<td bgcolor=&quot;#E8FFFF&quot; align=&quot;left&quot;><INPUT TYPE=&quot;text&quot; NAME=&quot;email&quot; SIZE=&quot;30&quot;></td></tr>
~;
}

 
OK I will give you a little explaination and this may help. Cookies just maintain infromation between pages. An example is a login name and password. Each time the server sends the web page data it can send cookie data too. This data can be read by your cgi program. A cookie is just a variable you pass behind the scenes from one page to another.

Cookies can expire or not expire. If you have a program that requires a login each time it is used then the cookie is simple expiring at the end of the session. This means that the cookie as no defined expiration date. You will need to set this to a date in the future. For instance, to have a cookie expire in 1 year you would put 365d.

Now here is some code that sets cookies.
use CGI;
$query= new CGI;
$cookie = $query->cookie(-name=>'sessionID',
-value=>'xyzzy',
This is what you need-> -expires=>'+1h',
-path=>'/cgi-bin/database',
-domain=>'.capricorn.org',
-secure=>1);
print $query->header(-cookie=>$cookie);

Now on the next run of the script the cookie is picked up with this code.

$riddle = $query->cookie('riddle_name');


For more infomation check here.
 
Ok, but where do I put it?
I worked on adding a cookie, followed all the parameters that all the tutorials gave me and still couldn't get it to work.
The name and e-mail is in a cgi script, that I have no problem modifying, it is getting the cookies to work with the name and e-mail I am having troubles with.
Do I put it between the
print qq~
and
~;
}
tags??

OR

Do I put it in this area?

#----------------------------------#
# Post a new message input section #
#----------------------------------#
sub post_new_message
{
print qq~
<a NAME=&quot;post&quot;>
<center>
Forgive me, but I'm not a programmer, webmaster or even have a clue what I am doing. I am a mechanic and just trying to make things work.
 
First you have to set the cookie on the first run of the script. This is usually done when the person submits their login information. Now each time the script is run you have to pick that cookie back up from the server and set the values in the cookie to the values that the program is using.

So when person logins in from the form the script is rerun to verify the login. While it is doing that you can set the login information in the cookie so they dont have to keep entering it. Use the for memtioned technique to set the cookie.

Now you have to look for that cookie again each time the script is run so you will need to pick it up with the line of code that says:
$scriptvariable=query->cookie('loginname');

You can do the same thing for the password. Now you just need to change the name of $scriptvariable to the varible name that the forum uses to authinticate the login.

If you continue to have troubles I will look at it for you on my machine.

My email is ekhaunter@hotmail.com be sure and attach the script code and someway to get in touch with you ie telephone or email addy.
 
Haunter,
I wanted to thank you for all your help. I have learned quite a bit thru this and am greatful for the time you have taken.
Admittedly, I still don't totally understand it all, but at least it is startint to make some sembance of sense to me.
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top