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!

goboating? Need a hand, with Development ENV

Status
Not open for further replies.

Haunter

Programmer
Jan 2, 2001
379
US
Hey,

Just let me say you are an excellent poster. All of your post have helped. OK, enough with the sucking up. hehe.

I have a development environment set up like yours. Apache as the desktop server. I run scripts, html, pHp fine. I am not quit sure how to set it up so I can fiddle with cookies locally on my machine. I have set the cookie domain to 'localhost'; but no success in getting a cookie set on my desktop environment. I have also tried 127.0.0.1 as the domain but still no success at Apache sending a cookie back to me. Do you have any solutions? Is it a configure thing I can do to make it work. Any suggestions at all would be helpful. I dont want to have to upload to the server to test.
 
If you can run CGIs, then apache is not the problem. There must be something wrong with the way you are trying to set the cookies or you don't have cookies enabled in your browser.

I did a straight install of apache on the Win NT machine I'm sitting in front of. (ending a sentence with a preposition is a typically southern habit). With ExecCGI enabled in httpd.conf, the following code sets and resets cookies on my machine.
Code:
#!perl
use CGI;
$query = new CGI;
$thisCGI = $query->url();

# try to read the cookie via the CGI.pm method
$cook1 = $query->cookie(-name=>'cook1');
$cook2 = $query->cookie(-name=>'cook2');

# swap meal components each time.
$cook1 = ($cook1 eq 'eggs' ? shrimp : eggs);
$cook2 = ($cook2 eq 'toast' ? grits : toast);

$cookie1 = $query->cookie(-name=>"cook1",
	-value=>"$cook1",
	-expires=>"+1h");

$cookie2 = $query->cookie(-name=>"cook2",
	-value=>"$cook2",
	-expires=>"+1h");


# print the cookie in the header.
print $query->header(-cookie=>[$cookie1,$cookie2]);
print $query->start_html(-title=>'Low Country Breakfast');
print &quot;<P>In the South Carolina low country, 
       we eat $cook1 and $cook2 with coffee for
       breakfast.</P>&quot;;
print $query->end_html;


You should be able to put a copy of that in your cgi-bin, and run it. Upon each refresh of the browser, the cookies should flip back and forth, cookie1 between eggs and shrimp and cookie2 between grits and toast.

If this does not help, post a little code and let's take a look.:cool:

ps - For all you grammar sharks out there, I believe Winston Churchill once said about ending sentences with prepositions, &quot;that is one rule, up with I shall not put&quot;.
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I will have to dig further into the problem. I used your code and did not get the desired result. The program did not exchange the cookies. I can see that the cookies are being set in the standard form. They are not being returned properly. I have had this problem on other servers and setting the domain properly has solved the problem. I think that this is the problem I am having now but the requirement of two &quot;.&quot; in the domain name is stumping me for my localhost.

This is the code that I was using.

use CGI;
$q = new CGI;
$cookie = $form_data{'cookie'}; #<--get data from form
$usr=$form_data{'name'}; #<--get data from form
$eml=$form_data{'email'}; #<--get data from form
$info{'uaid'}=&quot;$usr&quot; ; #<--populate hasd uaid
$info{'eml'} = &quot;$eml&quot; ; #<--populate hash eml
%session_id = $q->cookie('talktome');#<--get the cookie if exists
$account_id=$session_id{'uaid'}; #<--set account id from info in cookie
$account_email=$session_id{'eml'}; #<--set email id from info in cookie
###Use the above data somewhere else in program
#If they dont want a cookie then print standard HTTP Header#
if (!($cookie)){

print &quot;Content-type: text/html\n\n&quot;;
#Now just let the program run.....
}
#####If they want a cookie Then set it! ######
elsif ($cookie eq &quot;Yes&quot;){
$cookie= $q->cookie ( -name=>'talktome',
-path=>'/',
-value=>\%info,
#-domain=>&quot;$domainforcookie&quot;,
-expires=>'365d');
print $q->header(-cookie=>$cookie);

}


 
Never mind goboating I resolved the problem. It seems that emliminating the domain did the trick. I appreciate you time.

ty
 
I'm glad you got it working.

Can you expound a little on the root cause of the problem and how you tweaked it?

Was the problem in the apache setup?
Or, in the browser?
Or, ???

I am still in the fog and since I am using a similar approach I may eventually bump my head on the same problem.

Thanks, 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I think the problem existed in the fact that I was trying to set the domain for the cookie to be -domain='localhost';

It did not recognize the domain and therefore did not send the cookie. When I commented out the code referring to the domain it set cookies fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top