in reply to Re: cookie retrieval problem
in thread cookie retrieval problem

yes actually now that i have tried it again it worked for me too! :) But this cookie will se to each visitor right? how can it identify me from others?

Replies are listed 'Best First'.
Re: Re: Re: cookie retrieval problem
by bart (Canon) on Feb 29, 2004 at 23:25 UTC
    Ah, that problem again. <grin>

    Well, I can think of basically two approaches. Either you provide a special, different cookie value to each user, either semi-randomly assigned or via a login page, and you can then track any visitor to your site.

    Or, you don't set cookies for everybody, but only for yourself. You can have a special page, which you use to enter the site, but which nobody else knows of. All it has to do is set a cookie, and redirect you to the normal entrance. Every other page only has to read the cookie value. The following code forms the entrance page for the latter approach:

    #!/usr/bin/perl -w use CGI qw(:standard); my $cookie_out = cookie(-name=>'test', -value=>'Nikolas was here!'); print redirect(-cookie=>$cookie_out, -uri => "index.html");
    I'm assuming "index.html" is the normal index page to your site's directory.

    Now if you change the other script so it only reads the cookie (so drop the assignment to $cookie_out), you can visit the above script first, then go to the other script, possibly even by typing in the URL manually, and you'll see the cookie value as set here.

      Thanks guys but i have decided that the best way for my script to identify me is even simpler that using cookies.... here it is....

      if ($host =~ /thes530-.*?\.otenet\.gr|millennium-.*?\.ccf\.auth\.gr/)
      Although my ip from the two providers i use is dynamic this solution works just fine for me :)

      The cookies solution can alsobe done but it wouldn't be as quick and short as this one :)
        It'll work for you, and for thousands of other people using the same ISP. I don't think you really want to discard them, as they're among your more likely visitors.
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re: Re: cookie retrieval problem
by tachyon (Chancellor) on Feb 29, 2004 at 23:22 UTC

    To identify 'you from others' you will need to store a bit of info. Traditionally you will generate a unique session ID for a user that allows you to map that unique session ID to any data you want. You usually just store the session ID in the cookie and store the data on the server in some sort of persistent store - you have MySQL so that is as good as anything. This is one way to maintain state across the stateless HTTP protocol. Super search for 'session management' or similar to see lots of examples.

    CGI::Session may be what you are looking for.

    cheers

    tachyon