37 users online (0 members and 37 guests)  


  Results 1 to 4 of 4

Related

  1. tracking link clicks    Forum: PHP Forum
    Replies: 15
  2. link counter script...easy?    Forum: HTML Forum
    Replies: 1
  3. Replies: 1
  4. Adding HTML extension to link    Forum: Javascript Forum
    Replies: 10
  1. #1
    jon's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2007
    Posts
    5

    Help with adding named lebel to link tracking counter

    I have a link click counter, works fine but I need to add field "name" to label the URL I have the field inserted already but can't figure out how to get it to display when submitted..records to mysql.
    ------------------------------------------
    Code:
    #!/usr/bin/perl
    ###############################################################################
    use FindBin;
    use lib $FindBin::Bin;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);
    use clickt;
    use DBI;
    $version = "Ver 2.1";
    &get_setup;
    $q = CGI->new;
    clickt::check_access($username, $password, $q->param('username'), $q->param('password'));
    $thetime = time();
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime($thetime);
    $year = "20" . substr($year, 1, 2); 
     
    $template = &get_template;
    $template =~ s/!!weburl!!/$weburl/gi;
    $template =~ s/!!version!!/$version /gi;
     
    ##################################################################################
    print "Content-type: text/html\n\n";
    if ($q->param('fct') eq "") {&start; exit;}
    if ($q->param('fct') eq "addlink") {&addlink; exit;}
    if ($q->param('fct') eq "get_url") {&get_url; exit;}
    if ($q->param('fct') eq "reset") {&reset_url; exit;}
    if ($q->param('fct') eq "delete") {&delete_url; exit;}
     
    ########################################################
    sub delete_url
    {
    $id = $q->param('id');
    if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$dbname";}else{$dsn = "DBI:mysql:$dbname:$mysql_hostname:$mysql_port";}
    $dbh = DBI->connect("$dsn", "$dbusern", "$dbpasswd");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth = $dbh->prepare("DELETE FROM ctracker WHERE urlid = '$id'");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth->execute;
    $sth = $dbh->prepare("DELETE FROM ctracker2 WHERE urlid = '$id'");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth->execute;
    $sth->finish;
    $dbh->disconnect;
    $tmplg = <<ENDOFC;
    <table border="0" cellspacing="1" width="100%" cellpadding="9">
    <tr>
    <td width="907"><font face="Arial" size="2"></font><font face="Arial" size="4"><strong>URL
    Deleted</strong></font><p><a href="$script_url/admin.cgi"><strong><font face="Arial"
    size="2">Click here to continue</font></strong></a></td>
    </tr>
    </table>
    ENDOFC
    $template =~ s/!!data!!/$tmplg/g;
    print $template;
     
    }
     
    sub reset_url
    {
    $id = $q->param('id');
    if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$dbname";}else{$dsn = "DBI:mysql:$dbname:$mysql_hostname:$mysql_port";}
    $dbh = DBI->connect("$dsn", "$dbusern", "$dbpasswd");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
     
    $sth = $dbh->prepare("UPDATE ctracker SET clicks = '0' WHERE urlid = '$id'");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth->execute;
    $sth = $dbh->prepare("DELETE FROM ctracker2 WHERE urlid = '$id'");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth->execute;
    $sth->finish;
    $dbh->disconnect;
    $tmplg = <<ENDOFC;
    <table border="0" cellspacing="1" width="100%" cellpadding="9">
    <tr>
    <td width="907"><font face="Arial" size="2"></font><font face="Arial" size="4"><strong>Count
    Has Been Set to 0</strong></font><p><a href="$script_url/admin.cgi"><strong><font
    face="Arial" size="2">Click here to continue</font></strong></a></td>
    </tr>
    </table>
    ENDOFC
    $template =~ s/!!data!!/$tmplg/g;
    print $template;
    }
     
     
    sub get_url
    {
    $id = $q->param('id');
     
    if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$dbname";}else{$dsn = "DBI:mysql:$dbname:$mysql_hostname:$mysql_port";}
    $dbh = DBI->connect("$dsn", "$dbusern", "$dbpasswd");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth = $dbh->prepare("SELECT * FROM ctracker WHERE urlid = '$id'");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth->execute;
    while ( @row = $sth->fetchrow() )
    {
    $link = $row[1];
    }
    $sth->finish;
    $dbh->disconnect;
    ########################
    $tmplg = <<ENDOLTU;
    <table border="0" cellspacing="1" width="100%" cellpadding="9">
    <tr>
    <td width="907"><font face="Arial" size="2"></font><strong><font face="Arial" size="4">Get
    URL</font></strong><p><font face="Arial" size="2">To count the amount of clicks from
    visitors that goes to</font><br>
    <font color="#0080ff" face="Arial" size="2"><strong>$link</strong></font><br>
    <font face="Arial" size="2">use the link<br>
    </font><font color="#0080ff" face="Arial" size="2"><strong>$script_url/click.cgi?id=$id</strong></font><font
    face="Arial" size="2"><br>
    on your web site instead of<br>
    </font><font color="#0080ff" face="Arial" size="2"><strong>$link</strong></font></p>
    <p><a href="$script_url/admin.cgi"><strong><font face="Arial" size="2">Click here to
    continue</font></strong></a></td>
    </tr>
    </table>
    ENDOLTU
    $template =~ s/!!data!!/$tmplg/g;
    print $template;
    }
     
    ########################################################
    sub addlink
    {
    $newlink = $q->param('newlink');
    if (($newlink eq "") or ($newlink eq "http://"))
    {
    &problem("Please supply a URL to track clicks to.");
    }
    $newlink = &remove_leading_spacing($newlink);
    if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$dbname";}else{$dsn = "DBI:mysql:$dbname:$mysql_hostname:$mysql_port";}
    $dbh = DBI->connect("$dsn", "$dbusern", "$dbpasswd");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth = $dbh->prepare("SELECT * FROM ctracker WHERE curl = '$newlink'");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth->execute;
    $rows = $sth->rows();
    if ($rows > 0)
    {
    &problem("The URL you are trying to add already exists");
    }
     
    $sth = $dbh->prepare("INSERT INTO ctracker SET 
    curl = '$newlink',
    clicks = '0'");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth->execute;
    $sth->finish;
    $dbh->disconnect;
    ####
    $tmplg = <<END_OF_I;
    <div align="center"><center>
    <table border="0" cellpadding="9" cellspacing="1" width="100%">
    <tr>
    <td width="100%"><font face="Arial" size="4"><strong>URL Added<br>
    </strong></font><font face="Arial" size="2">&nbsp;&nbsp;&nbsp; <br>
    <a href="admin.cgi">Click here to continue</a></font></td>
    </tr>
    </table>
    </center></div>
    END_OF_I
    $template =~ s/!!data!!/$tmplg/g;
    print $template;
    }
     
     
     
    sub start
    {
    $table_top = <<ENDTP;
    <table border="0" width="100%" cellpadding="5" cellspacing="1"
    style="border: 1px solid rgb(221,221,221)">
    <tr>
    <td width="10%" bgcolor="#FCE22C" background="$weburl/bar.gif"><strong><font face="Arial"
    size="2">Edit</font></strong></td>
    <td width="5%" bgcolor="#FCE22C" background="$weburl/bar.gif"><strong><font face="Arial"
    size="2">ID</font></strong></td>
    <td width="54%" bgcolor="#FCE22C" background="$weburl/bar.gif"><strong><font face="Arial"
    size="2">URL</font></strong></td>
    <td width="6%" bgcolor="#FCE22C" background="$weburl/bar.gif"><strong><font face="Arial"
    size="2">Clicks</font></strong></td>
    <td width="25%" bgcolor="#FCE22C" background="$weburl/bar.gif"><strong><font face="Arial"
    size="2">Graph</font></strong></td>
    </tr>
    ENDTP
     
    if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$dbname";}else{$dsn = "DBI:mysql:$dbname:$mysql_hostname:$mysql_port";}
    $dbh = DBI->connect("$dsn", "$dbusern", "$dbpasswd");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth = $dbh->prepare("SELECT * FROM ctracker ORDER BY clicks DESC");
    if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
    $sth->execute;
    $rows = $sth->rows();
    $sc = 0;
    while ( @row = $sth->fetchrow() )
    {
    if ($sc == 0) {$highc = $row[2];}
     
    $current_clicks = $row[2];
    if ($current_clicks == 0)
    {
    $gperc = 1;
    }
    else
    {
    $gperc = $current_clicks / $highc * 100;
    }
     
    $sc++;
    $tmiddle = $tmiddle . <<ENDTM;
    <tr>
    <td width="10%" bgcolor="#F9F9F9"><font face="Arial" size="2"><a
    href="$script_url/admin.cgi?fct=get_url&amp;id=$row[0]">U</a> | <a
    href="$script_url/admin.cgi?fct=reset&amp;id=$row[0]">R</a> | <a
    href="$script_url/admin.cgi?fct=delete&amp;id=$row[0]">D</a> </font></td>
    <td width="5%" bgcolor="#F9F9F9"><font face="Arial" size="2">$row[0]</font></td>
    <td width="54%" bgcolor="#F9F9F9"><font face="Arial" size="2"><a href="$row[1]"
    target="_blank">$row[1]</a></font></td>
    <td width="6%" bgcolor="#F9F9F9"><font face="Arial" size="2">$row[2]</font></td>
    <td width="25%" bgcolor="#F9F9F9" align="left"><hr noshade size="5" color="#0000FF"
    width="$gperc%" align="left">
    </td>
    </tr>
    ENDTM
    }
    $sth->finish;
    $dbh->disconnect;
    if ($tmiddle eq "")
    {
    $table_top = ""; 
    $tmiddle = <<END_OF_NL;
    <font face="Arial" size="2"><b>There are currently no links being tracked. <BR><BR></b></font>
    END_OF_NL
    }
    else
    {
    $tmiddle = $tmiddle . "</table><BR>";
    }
     
    ####################
    $tmplg = <<END_OF_AB;
    <table border="0" cellspacing="1" width="100%" cellpadding="9">
    <tr>
    <td width="907"><strong><font face="Arial" size="4">Welcome!</font><font face="Arial"
    size="1"><br>
    </font></strong><font face="Arial" size="2">You have been logged in. The login will
    remember you for 24 hours. After 24 hours you will have to login again. </font></td>
    </tr>
    <tr>
    <td width="907"><font face="Arial" size="2"><strong>U</strong> = Get the url to use
    instead of the usual url you use on your web site<br>
    <strong>R = </strong>Reset counted clicks to 0<br>
    <strong>D </strong>= Delete the link being tracked<br>
    </font><font face="Arial" size="1"><br>
    </font><br>
    $table_top $tmiddle $cdata <form method="POST" action="admin.cgi">
    <input type="hidden" name="fct" value="addlink"><table border="0" width="100%"
    cellspacing="1" cellpadding="5" style="border: medium none rgb(0,0,0)" bgcolor="#D8D8D8">
    <tr>
    <td width="100%" colspan="2" bgcolor="#FCE22C" height="25" background="$weburl/bar.gif"><font
    face="Arial" size="2"><strong>Add a New Link To Track</strong></font></td>
    </tr>
    <tr>
    <td width="11%" valign="top" bgcolor="#FFFFFF"><font face="Arial" size="2"><strong>Url or
    Link:</strong></font></td>
    <td width="89%" bgcolor="#FFFFFF"><input type="text" name="newlink" size="35"
    value="Label">&nbsp;&nbsp;<input type="text" name="newlink" size="57"
    value="<A href="http://"><br">http://"><br>
    <font face="Arial" size="2">Add a new link to count the amount of clicks it receives. When
    you add a link you receive a link from <strong>Click Tracker</strong> in this link's
    place. Use this link instead of the usual link on your web site.</font></td>
    </tr>
    <tr>
    <td width="11%" valign="top" bgcolor="#FFFFFF"></td>
    <td width="89%" bgcolor="#FFFFFF"><input type="submit" value="Add New Link To Be Tracked"
    name="B1"></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
     
    END_OF_AB
     
     
    ####
    $template =~ s/!!data!!/$tmplg/g;
    print $template;
    }
     
    sub problem
    {
    my ($problem_text) = @_;
    $tmplg = <<END_OF_PRB;
    <div align="center"><center>
    <table border="0" cellpadding="9" cellspacing="1" width="100%">
    <tr>
    <td width="100%"><font face="Arial" size="4"><strong>Problem<br>
    </strong></font><font face="Arial" size="2">&nbsp;&nbsp;&nbsp; <br>
    $problem_text</font><p><strong><font face="Arial" size="2">Use the back button of your
    browser to go back.</font></strong></td>
    </tr>
    </table>
    </center></div>
    <br><br>
    END_OF_PRB
     
    $template =~ s/!!data!!/$tmplg/g;
    print $template;
    exit;
    }
     
    sub get_template
    {
    $tmpl = <<END_OF_CTMPL;
    <html>
    <head>
    <title>Control Panel</title>
    <style type="text/css">
    A {COLOR: #0000FF}
    A:visited {COLOR: #0000FF}
    A:active {COLOR: #000000}
    A:hover {COLOR: #000000}
    </style>
    <script LANGUAGE="JavaScript">
    <!-- Hide
    var popupwin = null;
    function popup(loc,ww,hh)
    {
    var mywidth = (ww + 0);
    var myheight = (hh + 0);
    var myspecs = "'menubar=0,status=1,resizable=1,location=0,titlebar=0,toolbar=1,scrollbars=1,width=" + mywidth + ",height=" + myheight + "'";
    if (popupwin == null || popupwin.closed)
    {
    popupwin = window.open (loc, 'popupwin', myspecs);
    }
    else
    {
    popupwin.focus();
    popupwin.location.href = loc;
    }
    }
    // End Hide -->
    </script>
    </head>
    <body bgcolor="#0000A0" background="$weburl/fcbg.jpg" topmargin="0" leftmargin="0">
    <div align="center"><center>
    <table border="0" cellpadding="0" cellspacing="0" width="95%">
    <tr>
    <td width="100%" height="15"></td>
    </tr>
    </table>
    </center></div><div align="center"><center>
    <table border="0" cellpadding="0" cellspacing="0" width="95%">
    <tr>
    <td width="1"><img src="$weburl/c1.gif" width="26" height="18"></td>
    <td width="98%" height="15" background="$weburl/ctop.gif"></td>
    <td width="1" height="15" align="right"><img src="$weburl/c2.gif" width="26" height="18"></td>
    </tr>
    <tr>
    <td width="1" background="$weburl/cl.gif"></td>
    <td width="99%"><div align="center"><center><table border="0" cellpadding="10"
    cellspacing="0" width="100%">
    <tr>
    <td width="100%" bgcolor="#FFFFFF">!!data!!</td>
    </tr>
    </table>
    </center></div></td>
    <td width="1" height="15" align="right" background="$weburl/cr.gif"></td>
    </tr>
    </table>
    </center></div><div align="center"><center>
    <table border="0" cellpadding="0" cellspacing="0" width="95%">
    <tr>
    <td width="1"><img src="$weburl/c3.gif" width="26" height="18"></td>
    <td width="98%" height="15" align="right" background="$weburl/cbot.gif"></td>
    <td width="1" height="15" align="right"><img src="$weburl/c4.gif" width="26" height="18"></td>
    </tr>
    </table>
    </center></div>
    </body>
    </html>
     
    END_OF_CTMPL
    }
     
     
    sub remove_leading_spacing
    {
    my ($ostring) = @_;
    my ($ds, $wfound);
    for ($ds = 0; $ds < length($ostring); $ds++) 
    {
    if ((substr($ostring, length($ostring) - 1, 1) eq " ") and ($wfound ne "true"))
    {
    chop($ostring);
    }
    else
    {
    $wfound = "true";
    }
     
    }
    $chopped_string = $ostring;
    return ($chopped_string);
    }
     
    ######################################################################
    sub get_setup
    {
    $exists = (-e "config.cgi");
    if ($exists > 0)
    {
     
    open (STP, "config.cgi");
    while (defined($line=<STP>))
    {
    if ($line =~ m/#/g)
    {
    $r = pos($line);
    $line = substr($line, 0, $r - 1);
    }
     
    $line =~ s/\n//g;
     
    if ($line =~ /^WEBURL/){$weburl = &get_setup_line($line, WEBURL);}
    if ($line =~ /^SCRIPT_URL/){$script_url = &get_setup_line($line, SCRIPT_URL);}
    if ($line =~ /^USERNAME/){$username = &get_setup_line($line, USERNAME);}
    if ($line =~ /^PASSWORD/){$password = &get_setup_line($line, PASSWORD);}
    if ($line =~ /^DBNAME/){$dbname = &get_setup_line($line, DBNAME);}
    if ($line =~ /^DBUSERN/){$dbusern = &get_setup_line($line, DBUSERN);}
    if ($line =~ /^DBPASSWD/){$dbpasswd = &get_setup_line($line, DBPASSWD);}
    if ($line =~ /^MYSQL_HOSTNAME/){$mysql_hostname = &get_setup_line($line, MYSQL_HOSTNAME);}
    if ($line =~ /^MYSQL_PORT/){$mysql_port = &get_setup_line($line, MYSQL_PORT);}
    }
    close (STP);
     
    }
    }
     
     
    sub get_setup_line
    {
    my ($setup_line, $setup_var) = @_;
    $crit = "\"";
    $setup_line =~ m/$crit/g;
    $r1 = pos($setup_line);
    $setup_line =~ m/$crit/g;
    $r2 = pos($setup_line);
    $setup_line = substr($setup_line, $r1, ($r2 - $r1 - 1));
    $return_val = $setup_line;
    return ($return_val);
    }
    #### END CONFIGURATION ########################################################
    HERE IS THE PART FROM ABOVE I MODIFIED TO ADD THE LABELED NAME FOR THE URL TO TRACK CLICK COUNTS..

    Code:
    <table border="0" cellspacing="1" width="100%" cellpadding="9">
    <tr>
    <td width="907"><strong><font face="Arial" size="4">Welcome!</font><font face="Arial"
    size="1"><br>
    </font></strong><font face="Arial" size="2">You have been logged in. The login will
    remember you for 24 hours. After 24 hours you will have to login again. </font></td>
    </tr>
    <tr>
    <td width="907"><font face="Arial" size="2"><strong>U</strong> = Get the url to use
    instead of the usual url you use on your web site<br>
    <strong>R = </strong>Reset counted clicks to 0<br>
    <strong>D </strong>= Delete the link being tracked<br>
    </font><font face="Arial" size="1"><br>
    </font><br>
    $table_top $tmiddle $cdata <form method="POST" action="admin.cgi">
    <input type="hidden" name="fct" value="addlink"><table border="0" width="100%"
    cellspacing="1" cellpadding="5" style="border: medium none rgb(0,0,0)" bgcolor="#D8D8D8">
    <tr>
    <td width="100%" colspan="2" bgcolor="#FCE22C" height="25" background="$weburl/bar.gif"><font
    face="Arial" size="2"><strong>Add a New Link To Track</strong></font></td>
    </tr>
    <tr>
    <td width="11%" valign="top" bgcolor="#FFFFFF"><font face="Arial" size="2"><strong>Url or
    Link:</strong></font></td>
    <td width="89%" bgcolor="#FFFFFF"><input type="text" name="newlink" size="35"
    value="Label">&nbsp;&nbsp;<input type="text" name="newlink" size="57"
    value="<A href="http://"><br">http://"><br>
    <font face="Arial" size="2">Add a new link to count the amount of clicks it receives. When
    you add a link you receive a link from <strong>Click Tracker</strong> in this link's
    place. Use this link instead of the usual link on your web site.</font></td>
    </tr>
    <tr>
    <td width="11%" valign="top" bgcolor="#FFFFFF"></td>
    <td width="89%" bgcolor="#FFFFFF"><input type="submit" value="Add New Link To Be Tracked"
    name="B1"></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    Last edited by vinyl-junkie; 11-09-2007 at 07:11 AM. Reason: Added code tags

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: Help with adding named lebel to link tracking counter

    I don't understand what you are trying to change/do

  3. #3
    jon's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2007
    Posts
    5

    Re: Help with adding named lebel to link tracking counter

    I made an extra field entry "label" so it will identify the URL "newlink" my problem is I don't know how to make it appear when submitted, I do have the complete program if needed because it does require mysql, there are only 2 other files needed to be fully function.

  4. #4
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: Help with adding named lebel to link tracking counter

    From what you have said,
    You either mean you want the value to be displayed or you want to re-direct the user to the URL.
    $label=param('label');
    print "$label";
    print "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>";
    print "<html><head><title>$page_title</title>";
    print "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://www.somedomain.com'>";
    print "</HEAD><BODY></BODY></HTML>";

    Thats the best I can say because I really don't have a clue what you are trying to achieve



Tags for this Thread