Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: CGI Cookie creation problem

by Nicko2004 (Initiate)
on Jun 19, 2012 at 14:33 UTC ( #977082=note: print w/replies, xml ) Need Help??


in reply to Re: CGI Cookie creation problem
in thread CGI Cookie creation problem

Hi, Sorry I did miss a few things. I updated my code as what is listed below but still no cookie is created. Thanks for your reply!

use CGI (); #Create Cookie $mc_cookie_domain_name = ".sample.com"; $mc_path_script = "/"; $mc_cookie_expiration_time = "+2h"; $mc_cookie_name = "Sample_Cookie"; #$mc_cookie_value = $mc_form_member_name; $mc_cookie_value = "Logged In"; my $cgi = CGI->new(); my $cookie = $cgi->cookie(-name => $mc_cookie_name, -value => $mc_cook +ie_value, -expires => $mc_cookie_expiration_time, -domain => $mc_cook +ie_domain_name); print $cgi->redirect(-url => 'https://www.sample.com/cgi-bin/confirm_a +ccount_2.pl', -cookie => $cookie); #End of Create Cookie

Replies are listed 'Best First'.
Re^3: CGI Cookie creation problem
by muba (Priest) on Jun 19, 2012 at 14:49 UTC

    Are you sure? When I run this script from the command line it gives me pretty much what you'd expect:

    G:\>type x.pl use CGI (); #Create Cookie $mc_cookie_domain_name = ".sample.com"; $mc_path_script = "/"; $mc_cookie_expiration_time = "+2h"; $mc_cookie_name = "Sample_Cookie"; #$mc_cookie_value = $mc_form_member_name; $mc_cookie_value = "Logged In"; my $cgi = CGI->new(); my $cookie = $cgi->cookie(-name => $mc_cookie_name, -value => $mc_cook +ie_value, -expires => $mc_cookie_expiration_time, -domain => $mc_cookie_domain_n +ame); print $cgi->redirect(-url => 'https://www.sample.com/cgi-bin/confirm_a +ccount_2.p l', -cookie => $cookie); #End of Create Cookie G:\>perl x.pl Status: 302 Found Set-Cookie: Sample_Cookie=Logged%20In; domain=.sample.com; path=/; exp +ires=Tue, 19-Jun-2012 16:45:45 GMT Date: Tue, 19 Jun 2012 14:45:45 GMT Location: https://www.sample.com/cgi-bin/confirm_account_2.pl G:\>

      Hello Muba, Thank you for your reply. Yes, I am absolutely positive no cookie was created when I ran the script using internet explorer from the website. www.sample.com is not the website by the way I am scratching my head trying to work out why as I have used this script without problems in the past, albeit without the earlier mistakes I missed out on. Any thoughts as to why? IT appears to work but no cookie is created. Thanks in advance.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://977082]
help
Chatterbox?
[1nickt]: The best way is to scope it tightly so it just goes away when you are finished with it.
[perldigious]: but... but... perldigious is the unvirtuous kind of lazy in this case. :-)
[perldigious]: Just kidding. Thanks 1nickt, I'll go ahead and do it the right way. An extra set of brackets and a little extra indentation isn't too much to ask.
[karlgoethebier]: perldigious: perhaps a block if you are paranoid ;-)
[choroba]: but undef %hash and %hash = () both work, too, but the first one keeps the memory allocated, while the latter makes it available for other parts of the program.
[choroba]: iirc
[perldigious]: karlgoethebier: Well it is a pretty old and complicated (for me) bit of code I wrote (poorly by my current standards), so I'm expecting everything to break when I add the scoping and find out what else is undesireably scope changed. :-)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-07-21 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (335 votes). Check out past polls.