Thread CGI::Session: Wie änder ich den Cookie Wert ? (9 answers)
Opened by J-jayz-Z at 2005-12-17 13:43

J-jayz-Z
 2005-12-17 17:10
#6320 #6320
User since
2005-04-13
625 Artikel
BenutzerIn
[Homepage] [default_avatar]
Ich dachte mir, ich schau mir mal CGI::Cookie an, aber damit habe ich ebenso Probleme, mit $cookie->value(['eins', 'zwei', 'drei', 'vier']); die Werte zu ändern. Nun gut, was heißt Probleme, ich bekomm es einfach nicht gebacken.:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl -w
use strict;
use warnings;

use CGI;
use CGI::Cookie;
use Data::Dumper;

my $cgi    = CGI->new();
my $cookie = CGI::Cookie->new(
   -name  => 'Prefs',
   -value => { Name => 'foo', Value => 'lala', Login => 1 }
);

my $foo = get_values("Prefs");

if ( $foo->{Login} ) {
   print $cgi->header( -cookie => $cookie ), $cgi->start_html();
   print $cgi->b( "Hello " . $foo->{Name} );
   print $cgi->b( $cgi->br(), $cookie->name() );
   $cookie->value( [ 'bla', 'foo' ] );
}
else {
   print $cgi->header( -cookie => $cookie ), $cgi->start_html(),
     $cgi->b("New Login!");
}

print $cgi->pre( Dumper($foo) );
print $cgi->end_html();

sub get_values {
   my $name    = shift;
   my $bla     = {};
   my $foo     = CGI::Cookie->fetch();
   my $counter = 0;
   for ( 0 .. @{ $foo->{$name}->{value} } ) {
       unless ( $counter % 2 ) {
           if ( $foo->{$name}->{value}->[$_] ) {
               $bla->{ $foo->{$name}->{value}->[$_] } =
                 $foo->{$name}->{value}->[ $_ + 1 ];
           }
       }
       $counter++;
   }
   return $bla;
}
\n\n

<!--EDIT|esskar|1135015806-->
perl -Mstrict -Mwarnings -e 'package blub; sub new { bless {} } sub bar {my $self=shift; $self->{bla}="5065726c2d436f6d6d756e697479"; return $self->{bla};} my $foo=blub->new();print "Hallo ";print pack("H*",$foo->bar()); print "\n"'

http://perl-tutor.de

View full thread CGI::Session: Wie änder ich den Cookie Wert ?