Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: creating and Deleting a new cookie

by kennethk (Abbot)
on Jun 26, 2017 at 15:35 UTC ( #1193593=note: print w/replies, xml ) Need Help??


in reply to creating and Deleting a new cookie

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.

Replies are listed 'Best First'.
Re^2: creating and Deleting a new cookie
by tsdesai (Acolyte) on Jun 26, 2017 at 17:02 UTC
    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.

        I am sorry, i am unable to explain properly.I have just checked the network tab as you mentioned and it says no cookies for this request. I am really unsure what i am doing wrong. I have gone through various examples. I have also tried to run from command prompt as one of the monks suggested, all i can see is the output of the html page but no luck while creating cookies. I would really appreciate any help on this. Many Thanks, Teju
        Hello, Thank you for your input. The line !/usr/bin/perl always there in my code except that i accidentally didn't put on the forum. I have just managed to work with one additional change and its started to work. As i have multiple print statement in the code as in I am setting the cookie and then redirect the user to the url. It either redirects or writes the cookie. though, i have found work around to it , I am not sure whether that is the right way to do it. My code after the cookies started working.
        use strict; use CGI; my $q = new CGI; my $returnurl; my $pass=$q->cookie('pass'); my $JsessCookie = $q->cookie(-name=>$pass, -value=>'', -path=>'/', -ex +pires=>'-1h'); my $tempcookie = $q->cookie(-name=>'tempc', -value=>'', -path=>'/'); my $url="https://test.com/return=$returnurl"; #tried the below but doesn't redirect <b>shows 302 status</b> #print $q->redirect(-cookie=>[$JsessCookie,$tempcookie],-uri=>$url); #<b>this is the working redirection code- but not sure whether its the + right way forward</b> print $q->header(-cookie=>[$JsessCookie,$tempcookie]); print qq~<meta http-equiv="refresh" content="0;URL=$url">\n;
        Many Thanks for all your help so far

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1193593]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2017-11-23 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (328 votes). Check out past polls.

    Notices?