cookie help

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default cookie help

    Hi,

    I'm trying to set cookie information after a login, then redirect to the
    page I want called after creating the session cookie. I've tried setting
    the information manually using:
    <i>
    $cookie = $cgi->cookie(CGISESSID => $session->id);
    print $cgi->header( -cookie=>$cookie );
    </i>
    But I get the following error when I try the redirect:
    <i>
    Status: 302 Moved Location...
    </i>
    When I try to use the header module:
    <i>
    $CGI::Session->header($cgi);
    </i>
    I get the following error:
    <i>
    Software error:
    Can't call method "header" on an undefined value at C:/Program
    Files/Apache Group/Apache2/htdocs/create_session.cgi line 33.
    </i>
    Below is the full script. If someone can point out what I can do to get
    this working, I'd really appreciate the help.

    Thanks,
    Glenn

    create_session.cgi
    ------------------
    #!c:/Perl/bin/Perl.exe

    use CGI;
    use CGI::Session;
    use CGI::Carp qw(fatalsToBrowser);

    # READ IN LOGIN VALUES

    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
    }

    # following is for debugging..verifies passed values
    #die_nice("login=$FORM{'login'}, pswd=$FORM{'pswd'}\n<p>");

    # SET "login" AND "pswd" in session
    #CGI::Session->name("CGISESSID"); -- this should be default
    $session = new CGI::Session("driver:File", undef,
    {Directory=>"/windows/temp"});
    foreach $key (sort (keys(%FORM))) {
    if ($FORM{$key} eq "") {
    die_nice("Please fill out the field for <b>$key</b>.");
    }
    $session->param($key, $FORM{$key});
    }

    $cgi = new CGI;
    #$cookie = $cgi->cookie(CGISESSID => $session->id);
    #print $cgi->header( -cookie=>$cookie );
    $CGI::Session->header($cgi);

    # REDIRECT BACK TO INDEX
    my $url = '/index.cgi';
    print $cgi->redirect($url);

    exit;

    sub die_nice {
    print "Content-type:text/html\n\n";
    print "<html><head><title>Login Failed</title></head><body>";
    my ($err_msg) = @_;
    print "<h2><b>Error</b></h2><p>";
    print "$err_msg<p>";
    print "<br>Use the BACK button to return to the form with your
    current fields filled in\n";
    print "</body></html>";
    exit;
    }

    bagsmode Guest

  2. Similar Questions and Discussions

    1. HTTP::Cookie won't store sent cookie
      Hi all, My script requests http://foo.bar.com/ with code that looks a little like this: my $ua = LWP::UserAgent->new; my $cookie_jar =...
    2. get cookie through img src
      I can't get cookie information from domainx.com in this setup. The visitor follows this clickpath: domainx.com (SETcookie.php) -> domainy.com...
    3. Why my cookie die ??:(
      Hi I have another problem, this time my cookie die, dont know why :(. In my code on first page I set cookie something like this <?php...
    4. Cookies set one time, I delete cookie, cookie is never set again!
      I am having this problem: My PHP script will set a cookie, it's there in my /Cookies folder. I delete the cookie (I have to for testing purposes,...
    5. authentication cookie vs session cookie
      Hi, What are the differences between authentication and session cookies? In my web.config file, I set the cookieless attribute for the...
  3. #2

    Default Re: cookie help


    "bagsmode" <[email protected]> wrote in message
    news:[email protected]..
    > Hi,
    >
    > I'm trying to set cookie information after a login, then redirect to the
    > page I want called after creating the session cookie. I've tried setting
    > the information manually using:
    > <i>
    > $cookie = $cgi->cookie(CGISESSID => $session->id);
    > print $cgi->header( -cookie=>$cookie );
    > </i>
    > But I get the following error when I try the redirect:
    > <i>
    > Status: 302 Moved Location...
    > </i>
    > When I try to use the header module:
    > <i>
    > $CGI::Session->header($cgi);
    > </i>
    > I get the following error:
    > <i>
    > Software error:
    > Can't call method "header" on an undefined value at C:/Program
    > Files/Apache Group/Apache2/htdocs/create_session.cgi line 33.
    > </i>
    > Below is the full script. If someone can point out what I can do to get
    > this working, I'd really appreciate the help.
    >
    > Thanks,
    > Glenn
    >
    > create_session.cgi
    > ------------------
    > #!c:/Perl/bin/Perl.exe
    >
    > use CGI;
    > use CGI::Session;
    > use CGI::Carp qw(fatalsToBrowser);
    >
    > # READ IN LOGIN VALUES
    >
    > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    > @pairs = split(/&/, $buffer);
    > foreach $pair (@pairs) {
    > ($name, $value) = split(/=/, $pair);
    > $value =~ tr/+/ /;
    > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    > $FORM{$name} = $value;
    > }
    >
    > # following is for debugging..verifies passed values
    > #die_nice("login=$FORM{'login'}, pswd=$FORM{'pswd'}\n<p>");
    >
    > # SET "login" AND "pswd" in session
    > #CGI::Session->name("CGISESSID"); -- this should be default
    > $session = new CGI::Session("driver:File", undef,
    > {Directory=>"/windows/temp"});
    > foreach $key (sort (keys(%FORM))) {
    > if ($FORM{$key} eq "") {
    > die_nice("Please fill out the field for <b>$key</b>.");
    > }
    > $session->param($key, $FORM{$key});
    > }
    >
    > $cgi = new CGI;
    > #$cookie = $cgi->cookie(CGISESSID => $session->id);
    > #print $cgi->header( -cookie=>$cookie );
    > $CGI::Session->header($cgi);
    >
    > # REDIRECT BACK TO INDEX
    > my $url = '/index.cgi';
    > print $cgi->redirect($url);
    >
    > exit;
    >
    > sub die_nice {
    > print "Content-type:text/html\n\n";
    > print "<html><head><title>Login Failed</title></head><body>";
    > my ($err_msg) = @_;
    > print "<h2><b>Error</b></h2><p>";
    > print "$err_msg<p>";
    > print "<br>Use the BACK button to return to the form with your
    > current fields filled in\n";
    > print "</body></html>";
    > exit;
    > }
    >
    You should be calling header() with the given object reference $session.
    Example: $session->header();



    HongKongHooker Guest

  4. #3

    Default Re: cookie help

    HongKongHooker wrote:
    > "bagsmode" <[email protected]> wrote in message
    > news:[email protected]..
    >
    >>Hi,
    >>
    >>I'm trying to set cookie information after a login, then redirect to the
    >>page I want called after creating the session cookie. I've tried setting
    >>the information manually using:
    >><i>
    >>$cookie = $cgi->cookie(CGISESSID => $session->id);
    >>print $cgi->header( -cookie=>$cookie );
    >></i>
    >>But I get the following error when I try the redirect:
    >><i>
    >>Status: 302 Moved Location...
    >></i>
    >>When I try to use the header module:
    >><i>
    >>$CGI::Session->header($cgi);
    >></i>
    >>I get the following error:
    >><i>
    >>Software error:
    >>Can't call method "header" on an undefined value at C:/Program
    >>Files/Apache Group/Apache2/htdocs/create_session.cgi line 33.
    >></i>
    >>Below is the full script. If someone can point out what I can do to get
    >>this working, I'd really appreciate the help.
    >>
    >>Thanks,
    >>Glenn
    >>
    >>create_session.cgi
    >>------------------
    >>#!c:/Perl/bin/Perl.exe
    >>
    >>use CGI;
    >>use CGI::Session;
    >>use CGI::Carp qw(fatalsToBrowser);
    >>
    >># READ IN LOGIN VALUES
    >>
    >>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    >>@pairs = split(/&/, $buffer);
    >>foreach $pair (@pairs) {
    >> ($name, $value) = split(/=/, $pair);
    >> $value =~ tr/+/ /;
    >> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    >> $FORM{$name} = $value;
    >>}
    >>
    >># following is for debugging..verifies passed values
    >>#die_nice("login=$FORM{'login'}, pswd=$FORM{'pswd'}\n<p>");
    >>
    >># SET "login" AND "pswd" in session
    >>#CGI::Session->name("CGISESSID"); -- this should be default
    >>$session = new CGI::Session("driver:File", undef,
    >>{Directory=>"/windows/temp"});
    >>foreach $key (sort (keys(%FORM))) {
    >> if ($FORM{$key} eq "") {
    >> die_nice("Please fill out the field for <b>$key</b>.");
    >> }
    >> $session->param($key, $FORM{$key});
    >>}
    >>
    >>$cgi = new CGI;
    >>#$cookie = $cgi->cookie(CGISESSID => $session->id);
    >>#print $cgi->header( -cookie=>$cookie );
    >>$CGI::Session->header($cgi);
    >>
    >># REDIRECT BACK TO INDEX
    >>my $url = '/index.cgi';
    >>print $cgi->redirect($url);
    >>
    >>exit;
    >>
    >>sub die_nice {
    >> print "Content-type:text/html\n\n";
    >> print "<html><head><title>Login Failed</title></head><body>";
    >> my ($err_msg) = @_;
    >> print "<h2><b>Error</b></h2><p>";
    >> print "$err_msg<p>";
    >> print "<br>Use the BACK button to return to the form with your
    >>current fields filled in\n";
    >> print "</body></html>";
    >> exit;
    >>}
    >>
    >
    >
    > You should be calling header() with the given object reference $session.
    > Example: $session->header();
    I tried that in place of "$CGI::Session->header($cgi);", however I got
    the exact same error. When I looked at Session.pm, it seemed it needed a
    parameter. Additionally, I turned strict on at one point and kept
    harping on using the full module names, that's why I used $CGI::Session
    in place of just plain $session. However, they both amount to the same
    error.

    ~Glenn

    bagsmode Guest

  5. #4

    Default Re: cookie help

    bagsmode wrote:
    > HongKongHooker wrote:
    >> "bagsmode" <[email protected]> wrote in message
    >> news:[email protected]..
    >>
    >>> Hi,
    >>>
    >>> I'm trying to set cookie information after a login, then redirect to the
    >>> page I want called after creating the session cookie. I've tried setting
    >>> the information manually using:
    >>> <i>
    >>> $cookie = $cgi->cookie(CGISESSID => $session->id);
    >>> print $cgi->header( -cookie=>$cookie );
    >>> </i>
    >>> But I get the following error when I try the redirect:
    >>> <i>
    >>> Status: 302 Moved Location...
    >>> </i>
    >>> When I try to use the header module:
    >>> <i>
    >>> $CGI::Session->header($cgi);
    >>> </i>
    >>> I get the following error:
    >>> <i>
    >>> Software error:
    >>> Can't call method "header" on an undefined value at C:/Program
    >>> Files/Apache Group/Apache2/htdocs/create_session.cgi line 33.
    >>> </i>
    >>> Below is the full script. If someone can point out what I can do to get
    >>> this working, I'd really appreciate the help.
    >>>
    >>> Thanks,
    >>> Glenn
    >>>
    >>> create_session.cgi
    >>> ------------------
    >>> #!c:/Perl/bin/Perl.exe
    >>>
    >>> use CGI;
    >>> use CGI::Session;
    >>> use CGI::Carp qw(fatalsToBrowser);
    >>>
    >>> # READ IN LOGIN VALUES
    >>>
    >>> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    >>> @pairs = split(/&/, $buffer);
    >>> foreach $pair (@pairs) {
    >>> ($name, $value) = split(/=/, $pair);
    >>> $value =~ tr/+/ /;
    >>> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    >>> $FORM{$name} = $value;
    >>> }
    >>>
    >>> # following is for debugging..verifies passed values
    >>> #die_nice("login=$FORM{'login'}, pswd=$FORM{'pswd'}\n<p>");
    >>>
    >>> # SET "login" AND "pswd" in session
    >>> #CGI::Session->name("CGISESSID"); -- this should be default
    >>> $session = new CGI::Session("driver:File", undef,
    >>> {Directory=>"/windows/temp"});
    >>> foreach $key (sort (keys(%FORM))) {
    >>> if ($FORM{$key} eq "") {
    >>> die_nice("Please fill out the field for <b>$key</b>.");
    >>> }
    >>> $session->param($key, $FORM{$key});
    >>> }
    >>>
    >>> $cgi = new CGI;
    >>> #$cookie = $cgi->cookie(CGISESSID => $session->id);
    >>> #print $cgi->header( -cookie=>$cookie );
    >>> $CGI::Session->header($cgi);
    >>>
    >>> # REDIRECT BACK TO INDEX
    >>> my $url = '/index.cgi';
    >>> print $cgi->redirect($url);
    >>>
    >>> exit;
    >>>
    >>> sub die_nice {
    >>> print "Content-type:text/html\n\n";
    >>> print "<html><head><title>Login Failed</title></head><body>";
    >>> my ($err_msg) = @_;
    >>> print "<h2><b>Error</b></h2><p>";
    >>> print "$err_msg<p>";
    >>> print "<br>Use the BACK button to return to the form with your
    >>> current fields filled in\n";
    >>> print "</body></html>";
    >>> exit;
    >>> }
    >>>
    >>
    >>
    >> You should be calling header() with the given object reference $session.
    >> Example: $session->header();
    >
    >
    > I tried that in place of "$CGI::Session->header($cgi);", however I got
    > the exact same error. When I looked at Session.pm, it seemed it needed a
    > parameter. Additionally, I turned strict on at one point and kept
    > harping on using the full module names, that's why I used $CGI::Session
    > in place of just plain $session. However, they both amount to the same
    > error.
    >
    > ~Glenn
    >
    OK, using "$session->header($cgi);" I get the following error:
    <b>
    Software error:

    Can't locate auto/CGI/Session/File/header.al in @INC (@INC contains:
    C:/Perl/lib C:/Perl/site/lib .) at C:/Program Files/Apache
    Group/Apache2/htdocs/BGMNbrs_create_session.cgi line 34
    </b>

    If I use "$session->header();", no argument as you suggest, I get:
    <b>
    Software error:

    Can't locate auto/CGI/Session/File/header.al in @INC (@INC contains:
    C:/Perl/lib C:/Perl/site/lib .) at C:/Program Files/Apache
    Group/Apache2/htdocs/BGMNbrs_create_session.cgi line 34
    </b>

    i.e. same thing.

    ~Glenn

    bagsmode Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139