Results 1 to 4 of 4

Thread: Cookies: issue with retrieving?

Hybrid View

  1. #1
    Join Date
    Aug 2005

    Question Cookies: issue with retrieving?

    homegrown perl developer usually on linux, but this is on windows box, but not sure that matters....

    i get:

    Can't call method "cookie" on an undefined value at \cgi-bin\article_admin.pl line 11.

    error when trying to retrieve cookie value (for a cookie of name 'articles' that i set on a previous page) via CGI in order to test whether user should have access to this page. the relevant code snippet is below. not sure why it would have an undefined value? can anyone help, as i'm undoubtedly just being stupid but am working alone right now and very stuck. thanks.

    1#!/usr/bin/perl -w
    3 use strict;
    5 use CGI;
    6 use CGI::Carp qw(fatalsToBrowser);
    8 my $query = new CGI;
    9 my $cgi;
    10 my $cookie_exists ="no";
    11 $cookie_exists = $cgi->cookie('articles');

  2. #2
    Join Date
    Dec 2002
    Pleasanton, CA
    What's the my $cgi for?? (not needed in this example)
    and you don't need line 10 but rather....

    my $cookie_exists = $query->cookie('articles');
    $cookie_exists = 'no' unless ($cookie_exists);

  3. #3
    Join Date
    Mar 2004
    Nedals is right.

    To explain a little more just in case you don't see the error.

    you created a CGI object as $query. Later on in the code you call the cookie method from $cgi as if it were a CGI object. You would need to call cookie() on $query based on the code you gave us.

  4. #4
    Join Date
    Aug 2005
    thanks folks. all working now, and one little bit more knowledge sinks in...
    jack of all trades, master of none.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles