Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

creating and Deleting a new cookie

by tsdesai (Acolyte)
on Jun 26, 2017 at 14:30 UTC ( [id://1193574]=perlquestion: print w/replies, xml ) Need Help??

tsdesai has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am trying to create a new cookie and then delete it later after certain actions. Below is my code that i create cookie

use strict; use CGI; my $q = new CGI; my $cookie = $q->cookie(-name=>'pass', -value=>'xxxx', -expires=>'+1h', -path=>'/'); print $q->header(-cookie=>$cookie);

The above is the pretty much standard code, but the cookie doesn't gets send to the browser. I am not sure why the cookie isn't created. I am going nuts something probably i am missing something silly. I have set the cookies before in different places but not sure why it doesn't work .

Appreciate any help. Thanks, Teju

Replies are listed 'Best First'.
Re: creating and Deleting a new cookie
by kennethk (Abbot) on Jun 26, 2017 at 15:35 UTC
    The simple script above should work. How do you know it isn't being sent to the browser? What browser and what debugger are you using? More likely than not either the browser is configured to block cookies or you have accidentally simplified away your problem in preparing code for this site.

    Is there a particular reason you are using CGI? CGI was removed from CORE specifically because modern frameworks, such as Mojolicious::Lite, actually get you done faster for even simple projects than either hand-rolled or CGI-assisted web page development. A read through CGI::Alternatives is worth your time.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      I know for the fact that they are not being sent to the browser as i can't them created on the cookie. I am using Firefox, nor i can read the values of the cookie that's created.
        When you look at the network transactions in the Network tab of Firefox DevTools (right-click, inspect element), you don't see any mention of your cookie in the Header or Cookies tabs? Sorry, language issues are interfering with my understanding your posts.

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: creating and Deleting a new cookie
by talexb (Chancellor) on Jun 26, 2017 at 15:03 UTC

    What happens when you run this from the command line?

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1193574]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-19 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found