1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

onclick, how to update data in MsSQL

Discussion in 'C#' started by ludwig, Jun 23, 2006.

  1. #1
    Hi guys,

    I am trying to think of a way to create a links directory where I can have direct links to any website, but I also need to count the clicks so that I can sort them by most visited or something else. I need to keep the data.

    My database is an MsSQL one and I use ASP. NOw how can I create that link lets say
    <a href="siteURL" onclick='MyASPpage' target='blank'>siteTITLE</a>

    I don't need to have 2 popups but I need to cound the hits, this is what Google does and I want to do it with ASP.

    Is this possible or no??? If no how Google does it??? What type of solution I can think of to do this function???
    SEMrush
    Thanks in advance
     
    ludwig, Jun 23, 2006 IP
    SEMrush
  2. ServerUnion

    ServerUnion Peon

    Messages:
    3,615
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ServerUnion, Jun 23, 2006 IP
  3. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #3
    yeah, I'd like to modify a ready made script, but unfortunately I don't know PHP and I want to have total control over the directory
     
    ludwig, Jun 23, 2006 IP
  4. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    use the onmousedown event in the link to capture the click. you shouldn't really rely on a popup though. you need to inititate a silent postback or request. you can do this by having your javascript load a fake image variable using a url.
     
    DanInManchester, Jul 5, 2006 IP
  5. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ludwig, i wrote a script (well, modified an existing script) to do exactly this. no wait i wrote it, it's all MINE muahahahahaha!

    seriously here goes.

    page name: tester.asp

    
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <script> 
    function clk(n) { if(document.images){ (new Image()).src="http://your-website.com/yourtestpage.asp?ID="+n; } return true;} 
    </script> 
    
    Example Link: 
    
    <a href="http://insert-your-hyperlink-here.com" onmousedown="return clk(123456789)">Your website name.</a> 
    </body>
    </html>
    
    Code (markup):
    now here's the tricky part. you have to say the magic words "Simsalbimbamba Saladu Saladim".

    poof.

    ok. what this does is pulls up "http://your-website.com/yourtestpage.asp?ID=123456789" on the onmousedown function, because you're passing that number in the "return clk" variable. you can change this to be a numeric affiliate id of any number.

    basically, behind the scenes, "http://your-website.com/yourtestpage.asp?ID=123456789" can then update a database anyway you see fit, while the user is directly taken to "http://insert-your-hyperlink-here.com". if they hit the back button from this page, they'll go directly back to the originating page, it will be a referrer in every sense of the word.

    here's just a sample of what i did with "yourtestpage.asp". I just threw together a quickie access database for testing, (did someone say quickie? :D) you can obviously take it from here and modify this to your liking and update your MsSql db as you see fit. I've got a field in the DB that is auto-populated with the current date/time, and i pass it referrers, IP addresses, and the affiliate id.

    page name: yourtestpage.asp
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    <!--#include virtual= "/adovbs.inc"-->
    <% Set DSNConn = Server.CreateObject("ADODB.Connection") 
    dsnconn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=E:\Prime_Web_Dev\znum.mdb"
     znum = request("ID")
     z2 =request.servervariables ("REMOTE_ADDR")
      z3 =request.servervariables ("HTTP_REFERER")
      
     
    sql = "insert into znum (znum, zrefer, zclient) values ('"&z2&"', '"&z3&"', "&znum&")"
      '   Create ADO Recordset Component  '             
              Set oRs = Server.CreateObject("ADODB.Recordset")
              oRs.Open sql, dsnconn,3,3 
    %>
    <body>
    </body>
    </html>
    
    
    Code (markup):
    hope this helps! and just remember, You are Elastigirl! My God! Pull yourself together! Go! Confront the problem! Fight! Win! And call me when you get back, dahling, I enjoy our visits.

    VG
     
    vectorgraphx, Jul 5, 2006 IP
    ludwig likes this.
  6. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #6
    Hey VG,

    Good news for you and I, it works perfectly on my PC, hope it'll work online with a really slow connection also.

    Currently I am developing the script so that it doesn't count the clicks from one and the same IP in 1 day, etc.

    This much, will get back to you when I am finished.

    I'll send you the link

    Thanks again
     
    ludwig, Jul 10, 2006 IP
  7. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,607
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #7
    have pass-through script page. <a href="redirect.asp?urlid=10302">Funky Town</a>. Then in the redirect.asp, increment the urlID "Counter" field, pull the URL that is associated to the urlID, and redirect to that url :)
     
    ccoonen, Jul 10, 2006 IP
  8. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,607
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #8
    only issue with this it doesn't track referals on target="_blank" and redirect (that's why php is preffered, you can force "spoof" the referer with php)
     
    ccoonen, Jul 10, 2006 IP
  9. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    the issue with redirects is that you lose the benefit of having real external links on your page. Google uses the mouse down event to track clicks of its links and it uses real links in the page. Not sure how this works in terms of the target as I haven't really picked through their code.
     
    DanInManchester, Jul 11, 2006 IP
  10. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #10
    Man, the thing is that as I have already told you I don't need that simple redirects. I want to provide a direct link to the URL

     
    ludwig, Jul 11, 2006 IP
  11. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #11
    The script written by VG is well enough and needs some modifications and it will work just perfectly. All other things, such as continuos clicks from one and the same IP are the extension part of the project.

    Thus if you modify the script above you get what you wish, no PHP or CGI or "spoof" are needed.


     
    ludwig, Jul 11, 2006 IP
  12. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #12
    Hi Dan,

    you are right, I tested it and it doesn't matter you have _blank or no. It works just like in Google.

    The only problem that I am afraid I might encounter is that some people (like me at my office) have really slow internet connection and it might not have the time to count all the clicks.

    In a couple of days I'll have the script online and will place a link here for those who are interested whether it works right or no :)

     
    ludwig, Jul 11, 2006 IP
  13. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #13
    ludwig, Jul 11, 2006 IP
  14. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #14
    Seems to work but cant be sure about the logging itself.
     
    DanInManchester, Jul 11, 2006 IP
  15. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #15
    well it takes about a few seconds before it logs, if the user doesn't do anything lets say for 5 secs, it logs for sure. I'll try to count the time also
     
    ludwig, Jul 11, 2006 IP
  16. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #16
    If you make the taget equal to self you may get an idea as to whether this works with slow reponse times. I would expect it does as placing the request itself would be fairly quick. even if your script is fairly slow to complete.
    If you request a page and the user moves away before it complte the execution doesn't stop.

    I pulled apart google's code and it looks essentially the same as yours but with some parameters ....

    function clk(url,oi,cad,ct,cd,sg)
    {
    if(document.images)

    {
    var e = window.encodeURIComponent ? encodeURIComponent : escape;var u="";
    var oi_param="";
    var cad_param="";
    if (url) u="&url="+e(url).replace(/\+/g,"%2B");
    if (oi) oi_param="&oi="+e(oi);
    if (cad) cad_param="&cad="+e(cad);
    new Image().src="/url?sa=T"+oi_param+cad_param+"&ct="+e(ct)+"&cd="+e(cd)+u+"&ei=tr20RN3VEISCiALm5oDKDg"+sg;
    }
    return true;}
     
    DanInManchester, Jul 12, 2006 IP
  17. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #17
    Wow, you did spend time on it, unfortunately I have been very busy with my work at 3 offices and didn't have the opportunity to work on it myself.

    As I said I'll try to do my best to complete the task as needed.

    All I know is that there is nothing impossible in this world, you just need to really want it.

    THANK YOU GUYS
     
    ludwig, Jul 12, 2006 IP