Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Will perl set a value that the browser retains?

Posted on 1999-07-14
3
Medium Priority
?
144 Views
Last Modified: 2010-03-04
I am trying to track customer referal sales. I want a customer to hit a banner link on another site that sends him to my site and sets a CUSTID=somenumber variable value. Then, he can move around my site as he wishes.....if he decides to buy my product can i have him hit a link to a .cgi script that will place the CUSTID=somenumber variable in another form that posts to a script i have that reads the CUSTID=somenumber pair.
 Can this be done in perl, if so, how?
0
Comment
Question by:vernk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
nchen091098 earned 800 total points
ID: 1214158
There are 2 ways to do this.

The vast majority of the time, cookies are enabled on the client's browser, so you can set a cookie on their end.  To do this, have the banner call your script with a query string.  Like YOURSCRIPT.CGI?xxxxxx  where xxxxxx is the CUSTID #.

To set the cookie, put as your server response:

print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n";
print "Set-Cookie: CUSTID=$ENV{'QUERY_STRING'}\;\n\n

Then the id is stored on the clients browser.

To retrieve this cookie, use this standard function:

sub parse_client_cookies
{
      my ($key_value, $key, $value, $var_name, $var_value);
      my @key_value_pairs = split (/;\s/, $ENV{'HTTP_COOKIE'});
      foreach $key_value (@key_value_pairs){
            ($key, $value) = split (/\s*=\s*/, $key_value);
            $key =~ tr/+/ /;
            $value =~ tr/+/ /;
             $key =~ s/%([\da-fA-F][\da-fA-F])/pack("C", hex($1))/eg;
            $value =~ s/%([\da-fA-F][\da-fA-F])/pack("C", hex($1))/eg;
            if($key=~/\AVar\d/){
                  $value = pack "h*", ($value);
                  ($var_name, $var_value) = split (/\s*=\s*/, $value);
                  $cookie_var{$var_name} = $var_value;
            }
      }
}

the CUSTID is stored in the hash as $cookie_var{'CUSTID'}

The second way to do this is to store in a table the IP address of the client with the CUSTID, so you can look up the CUSTID when they make a purchase, but this takes more work.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1214159
you can also set an <input type=hidden> field,
or check $ENV{REMOTE_USER} after the client has responded to a
WWW-Authenticate:
header
0
 

Author Comment

by:vernk
ID: 1214160
Thanx for the help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question