Tracking Cookies, with MySQL and CGI.pm - preCharge Forums
It shows that you are unregistered. Please register with us by clicking Here
preCharge Forums


Nav Green LeftNav Right
preCharge Forums > Website Design & Development > Programming > Perl » Tracking Cookies, with MySQL and CGI.pm


Reply
Tcat Right
 
LinkBack Thread Tools Display Modes Tcat Right
Old 08-19-2006   #1 (permalink)
Ankita
Member
 
Join Date: Jul 2006
Age: 25
Posts: 53
Default Tracking Cookies, with MySQL and CGI.pm

#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use DBI;
use strict;

print header();
print start_html("Welcome");

my $dbh = DBI->connect( "dbi:mysqlroducts", "webserver", "", { RaiseError => 1, AutoCommit => 1 }) or &dienice("Can't connect to database: $DBI::errstr");

# declare some variables
my ($cookie_id, $username);

if (cookie('userID')) { # found a cookie!
my $sth = $dbh->prepare("select * from user_cookies where cookie_id=?") or &dbdie;
$sth->execute(cookie('userID')) or &dbdie;
if (my $rec = $sth->fetchrow_hashref) {
$cookie_id = cookie('userID');
$username = $rec->{username};
}
}
if ($cookie_id) {
print h2("Welcome back, $username!");
} else {
print h2("Welcome!");
print qq(
<form action="cookieform.cgi" method="POST">
This appears to be your first visit. Please enter your name:
<input type="text" name="username">
<input type="submit" value="Enter">
</form>
<br>
);
}

print end_html;
$dbh->disconnect;

sub dienice {
my($msg) = @_;
print "<h2>Error</h2>\n";
print $msg;
exit;
}

sub dbdie {
my($package, $filename, $line) = caller;
my($errmsg) = "Database error: $DBI::errstr<br>
called from $package $filename line $line";
&dienice($errmsg);
}
Ankita is offline   Reply With Quote


Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send cookies to the client Tom Tom .NET 1 06-14-2007 12:02 AM
Tracking 55.1 Million Blogs Eric All Other SE's & Directories 18 10-17-2006 09:07 AM
Order Tracking? Jewls Website Design 7 08-11-2006 03:24 AM
Not Tracking Anymore LouisianaNurse All Things General 5 07-10-2006 07:59 PM
WHERE do I put the tracking code for my blog??? Nail All Things General 0 05-17-2006 08:23 AM


footer left
All times are GMT. The time now is 08:29 PM.

DISCLAIMER: preCharge Risk Management is not responsible for any opinions, advice or comments expressed on the preCharge Community Forums.
preCharge® is a registered trademark of preCharge Risk Management | chargeback protection | Merchant Account Blog

Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC6

Myspace Proxy | Free Advertising | Myspace Codes | Master Resale Rights | Property in Spain

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49