Thread: cookie!!

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    does any one know how to use cookie in perl...
    can teach me how to create the cookie in one page & the other page will know that the cookie had being created...eg other page can just use if($cookie) to koe if this person entering is authenticated
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    71
    Rep Power
    15
    I recommend you to use cookie-lib.pl
    http://www.egr.uri.edu/~kovacsp/cookie-lib/
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    pepe thank for telling mi about the website..
    but still I dont understand how can I use the script?
    the cgi-lib & cookie-lib is text file...
    how do i download & put it in in order to use it??pls help mi once again...thank!!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    71
    Rep Power
    15
    Download cookie-lib.txt, rename it to cookie-lib.pl and upload it to your cgi-bin directory.
    You can use this library from your perl script by putting:

    require "cookie-lib.pl";

    line in your script. You can see syntax for using it at above link.
    Here is simple script.cgi that reads cookie called "idcheck", and if cookie does not match your variable it sets the cookie.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>


    #!/usr/bin/perl

    require "cookie-lib.pl";

    &get_cookie;

    if ($cookie{'idcheck'} eq "oldvisitor" ) {

    print "Location: <A HREF="http://www.mydomain.com/index.htmlnn";" TARGET=_blank>http://www.mydomain.com/index.htmlnn";</A>

    }

    else{

    $cookie{'idcheck'} = $FORM{'oldvisitor'};

    &set_cookie(1026432000, ".mydomain.com","/",0);

    print "Location: <A HREF="http://www.mydomain.com/welcome.htmlnn";" TARGET=_blank>http://www.mydomain.com/welcome.htmlnn";</A>

    }

    [/code]


    [This message has been edited by Pepe (edited November 29, 2000).]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    pepe i had downloaded the cookie-lib.txt & had renamed it with cookie-lib,pl....
    ANd try with the script you had wrote..
    but it did not work & prompt the error
    >>>
    cookie-lib.pl did not return a true value at
    script.cgi at line2.
    >>>
    Name "main::FORM" use only once: possible typo at script.cgi at line8.

    Pls give me some comment on the error....thank
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    71
    Rep Power
    15
    I had one error in previous code. This one works, I tried it, just change URLs to your own.
    First time visitors will see /index.shtml and all returning visitors will go to /index.shtml
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    #!/usr/bin/perl
    require "cookie-lib.pl";
    &get_cookie;
    if ($cookie{'idcheck'} eq "oldvisitor" ) {
    print "Location: <A HREF="http://www.upitnik.net/index.shtmlnn";" TARGET=_blank>http://www.upitnik.net/index.shtmlnn";</A>
    } else {
    $cookie{'idcheck'} = "oldvisitor";
    &set_cookie(1026432000, ".upitnik.net","/",0);
    print "Location: <A HREF="http://www.upitnik.net/index2.shtmlnn";" TARGET=_blank>http://www.upitnik.net/index2.shtmlnn";</A>
    }
    [/code]

IMN logo majestic logo threadwatch logo seochat tools logo