Web Analytics Made Easy -
StatCounter Cookies - CodingForum

Announcement

Collapse
No announcement yet.

Cookies

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cookies

    I am having problems creating and reading cookies. I am by no means an expert, so I would appreciate anyone who could give me some advice. I am using a script from Matt's archives call 'cookie.pl', and it worked the first time I used it. Now I have it in another app and it works sometimes, and sometimes it does'nt. I also tried CGIm, and the cookie function did not work at all. Here is what I am doing now, trying to save a password:

    if (&GetCookies('password')) {
    $cookiePass=$Cookies{'password'};
    }
    else {
    &SetCookies('password',$User_password);
    }

    I am most likely missing something simple....
    Thanks,
    T.Davis

  • #2
    I am only used to using CGI cookie() like so:

    use CGI qw/:standard/; #place at top of script


    my $name = "Jimbo";
    my $cookie = cookie(-name => $name, -value => 'value', -expires => '+1y');
    print header(-cookie => $cookie);

    To retrieve:
    my $value = cookie("Jimbo");

    After using "print header(-cookie => $cookie);", you should not print the content type, because that already sets the content type (text/html) for you.
    Printing the content type before that will stop it creating the cookie.

    -Stu
    if ($ENV{'QUERY_STRING'} eq "Afrow UK") {
    print "$ENV{'QUERY_STRING'} rocks!";
    } else {
    print qq~$ENV{'QUERY_STRING'} sucks :)~;
    }

    Comment


    • #3
      That worked, but...

      That wrote my cookie, no problem, but after I record that cookie, I want to proceed to another perl display program, like so...

      $redirect = $nextprogram . $parameters;
      print "Location: $redirect\n\n";

      But this display the value of $redirect, instead of the HTML that is in the perl program whose value is $nextprogram.

      How do I get around this?

      Thanks for your help!!
      T.Davis

      Comment


      • #4
        You mean you want to redirect the user to another page?
        The simplest way to achieve this is by using a meta tag:

        print qq~<meta http-equiv="refresh" content="2;url=thankyou.html" />~;

        2 seconds after the browser executed this, the browser will move to the thankyou.html page. Note that this page (containing the code) will still be stored in the history (re-accessible via the Back button).

        -Stu
        if ($ENV{'QUERY_STRING'} eq "Afrow UK") {
        print "$ENV{'QUERY_STRING'} rocks!";
        } else {
        print qq~$ENV{'QUERY_STRING'} sucks :)~;
        }

        Comment


        • #5
          that worked, but...

          Is there any difference in Windows operating system? I mean, the PC that I work on during the day is Windows 2000, and the one I work on at night is Windows 98. I can find the cookies folder easy enough on both, but the Win98 does not seem to be writing the cookie, although cookies certainly is turned on, because there are thousands in the folder.

          Anyway, you have already helped a great deal. Working with cookies seems to be a little inconsistent. One more thing though, when I redirect per your suggestion, it works fine, but the browser displays the cookie write code just before going to the "thankyou.html" page.

          Try it for yourself. Go to http://www.fsasteps.com, and click the Information/Birthdays option on the menu at the top. That takes you to a password entry screen. Use DAVIT132 as the user, and BoZmkdI as the password (if you would be so kind).

          Again,
          thanks for your help
          T. Davis

          Comment

          Working...
          X