cookie

J

John Bokma

George Mpouras said:
I do not know, maybe I am doing something wrong, but I end up to
conclusion that you can not send any cookie (at lease through CGI)
after the header is printed

That's correct, if you mean with "header is printed" that all header(s)
have been send and a blank line. Hence, you must print your cookie
before that.

In Firefox, install the "Live HTTP Headers" add on to see what's being
send/received.
 
J

John Bokma

George Mpouras said:
print $cgi->redirect( -uri => "http://www.cpan.org", -cookie
=> cookie(-name=>'LastActions', -path=>'/', -secure=>0,
-expires=>'+2h', -value=>{ Book => $cgi->param('Book'), Shelf =>
$cgi->param('Shelf') } ) );

I can imagine that setting a cookie and redirecting to a different
domain at the same time doesn't work. But again, check with Live HTTP
headers add on for firefox.
 
X

Xho Jingleheimerschmidt

Στις 25/2/2014 05:29, ο/η Xho Jingleheimerschmidt έγÏαψε:


Xho,

I hope you understand that you can not redirect if you print the header

That is why I did not print the header when I needed to redirect instead.
I hope you understand that you can not send a cookie after the header is
printed.

That is why I did not print the header when I still needed to figure out
the cookie.

your code do not come even close to work.

I did test it, it works. You did not.

I'm now sorry I've tried to assist a proven troll, liar, and half-wit.

Bye-bye George.

Xho
 
P

Peter J. Holzer

Well I try it. Not only this but several other similar or not
variations. I also can see the requests , but I can not see any cookie
at Firefox cookies.sqlite

It sets a session cookie. Session cookies shouldn't be stored, so it is
not surprising that you don't see it in cookies.sqlite. You should see
it in Preferences -> Privacy -> Cookies, however, and - more importantly
- you should see the effect. If you try to load the script again, you
are immediately redirected.

I do not know, maybe I am doing something wrong, but I end up to
conclusion that you can not send any cookie (at lease through CGI) after
the header is printed

It is true that you can not send any cookie after the header (it needs
to be in the header, but this this is exactly why Xho sends the cookie
in the header and not after it. He has shown you how to do it. Please
make at least a minimal effort to understand the script before repeating
the problem solved by the very script you are looking at.

For not messing this post , I will post a stripped down variation of my
latest try

I don't think including relevant information counts as "messing".

hp
 
P

Peter J. Holzer

#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard -compile -nosticky/; $CGI::DISABLE_UPLOADS=1;
use CGI::Carp qw/fatalsToBrowser/;
my
$cgi = new CGI;
$cgi->autoEscape(1);


# First lets check if there is already a cookie at user browser
my %cookie_data = $cgi->cookie('LastActions');

if ((exists $cookie_data{Book}) && (exists $cookie_data{Time}))
{
# some code goes here
print CGI::redirect("http://www.cpan.org");
exit
}

print
$cgi->header(
-type => 'text/html',
-charset => 'UTF-8',
-encoding => 'UTF-8',
'-Content-Language' => 'el',
-lang => 'el-Greek',
-expires => '+10h',
-nph => 0,
-status => '200 ok'),

You print the header here. Unconditionally (well, almost).

And then you print the HTML body and finally you try to set the cookie
here:
if ( defined $cgi->param('SUBMIT') )
{
print $cgi->redirect( -uri => "http://www.cpan.org", -cookie =>
cookie(-name=>'LastActions', -path=>'/', -secure=>0, -expires=>'+2h',
-value=>{ Book => $cgi->param('Book'), Shelf => $cgi->param('Shelf') } ) );
exit;
}

So that's your mistake. Although you have repeatedly written yourself
that you cannot set the cookie after printing the header and although
Xho showed you how to delay printing the header until you know what
should go into it, you still do it in a way which you know cannot work.
Why?

hp
 
G

George Mpouras

So that's your mistake. Although you have repeatedly written yourself
that you cannot set the cookie after printing the header and although
Xho showed you how to delay printing the header until you know what
should go into it, you still do it in a way which you know cannot work.
Why?

hp


delay printing the header for the very first redirection ? there is no
problem there.

I test xho code (apache at centos 6.5) using firefox as client on
windows 8 box; there was no cookie after the form submission.
So what ? may at his environment worked, but not at mine.

I tired with this thread and I want to get stopped here, ( even more
after his last post )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top