Hit Counter on a button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • burg226
    New Member
    • Jun 2007
    • 8

    Hit Counter on a button

    Greetings, newbie here. I have a PHP page where someone will submit there resume by entering their name, email address, attach a file and click the submit button. What i need is an invisible hit counter on the "submit" button that will show how many times the "submit" button has been clicked. Any ideas? Thanks for any help. Much appreciated.
    Below is the code i am currently using...[php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <html>
    <head>
    <title>Submit Your Resume</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <?php
    if ($_SERVER['REQUEST_METHOD ']=="POST"){
    // we'll begin by assigning the To address and message subject
    $to="resume@job .ca";
    $subject="Sendi ng My Resume From job.ca";
    // get the sender's name and email address
    // we'll just plug them a variable to be used later
    $from = stripslashes($_ POST['fromname'])."<".stripslas hes($_POST['fromemail']).">";
    // generate a random string to be used as the boundary marker
    $mime_boundary= "==Multipart_Bo undary_x".md5(m t_rand())."x";
    // store the file information to variables for easier access
    $tmp_name = $_FILES['filename']['tmp_name'];
    $type = $_FILES['filename']['type'];
    $name = $_FILES['filename']['name'];
    $size = $_FILES['filename']['size'];
    // here we'll hard code a text message
    // again, in reality, you'll normally get this from the form submission
    $message = "Please find my resume attached: $name";
    // if the upload succeded, the file will exist
    if (file_exists($t mp_name)){
    // check to make sure that it is an uploaded file and not a system file
    if(is_uploaded_ file($tmp_name) ){
    // open the file for a binary read
    $file = fopen($tmp_name ,'rb');
    // read the file content into a variable
    $data = fread($file,fil esize($tmp_name ));
    // close the file
    fclose($file);
    // now we encode it and split it into acceptable length lines
    $data = chunk_split(bas e64_encode($dat a));
    }
    // now we'll build the message headers
    $headers = "From: $from\r\n" .
    "MIME-Version: 1.0\r\n" .
    "Content-Type: multipart/mixed;\r\n" .
    " boundary=\"{$mi me_boundary}\"" ;
    // next, we'll build the message body
    // note that we insert two dashes in front of the
    // MIME boundary when we use it
    $message = "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary }\n" .
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $message . "\n\n";
    // now we'll insert a boundary to indicate we're starting the attachment
    // we have to specify the content type, file name, and disposition as
    // an attachment, then add the file content and set another boundary to
    // indicate that the end of the file has been reached
    $message .= "--{$mime_boundary }\n" .
    "Content-Type: {$type};\n" .
    " name=\"{$name}\ "\n" .
    //"Content-Disposition: attachment;\n" .
    //" filename=\"{$fi leatt_name}\"\n " .
    "Content-Transfer-Encoding: base64\n\n" .
    $data . "\n\n" .
    "--{$mime_boundary }--\n";
    // now we just send the message
    if (@mail($to, $subject, $message, $headers))
    echo "Thank you. Your message has been sent.";
    else
    echo "Failed to send";
    }
    } else {
    ?>
    <p><img src="http://www.is2.ca/web_images/is2logo.jpg" alt="is2 logo" width="159" height="100" align="baseline " /></p>
    <p>To submit your resume to the branch, please enter your name, email address and attach your resume below:</p>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
    enctype="multip art/form-data" name="form1">
    <p>From name: <input type="text" name="fromname" ></p>
    <p>From e-mail: <input type="text" name="fromemail "></p>
    <p>File: <input type="file" name="filename" ></p>
    <p><input type="submit" name="Submit" value="Submit"> </p>
    </form>
    <?php } ?>
    </body>
    </html>[/php]
    Last edited by ronverdonk; Apr 30 '08, 12:31 PM. Reason: warning: use code tags!
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    PLEASE!!! Put code tags around your post. Click Edit on your last post and put [PHP ] [/PHP ] (remove spaces) around all that code! Then we will read it.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      warning:

      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      MODERATOR

      Comment

      • aktar
        New Member
        • Jul 2006
        • 105

        #4
        Hi Burgs, welcome to bytes.

        Please explain what is it that you want to achieve

        Comment

        • burg226
          New Member
          • Jun 2007
          • 8

          #5
          Sorry about the code tags, i had no idea. Like i said i'm new to this site. So what i'm trying to acheive is a hidden counter or a counting system of some sort that will let me know how many times the submit button has been clicked. Any ideas....please ? Anybody?

          Comment

          • aktar
            New Member
            • Jul 2006
            • 105

            #6
            Originally posted by burg226
            So what i'm trying to acheive is a hidden counter or a counting system of some sort that will let me know how many times the submit button has been clicked
            Yes, that was evident from your first post but what I'm trying to find out is why you want to count the hits. Perhaps there are alternative solutions to your problem than counting hits?

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              Originally posted by burg226
              Sorry about the code tags, i had no idea. Like i said i'm new to this site. So what i'm trying to acheive is a hidden counter or a counting system of some sort that will let me know how many times the submit button has been clicked. Any ideas....please ? Anybody?
              Okay, clear. Now let's get more practical.

              Do you want to count the submit hits just for the session of that particular user or do you want to count all submits by all users of your site? In the first case you can keep the counter in storage and it will be destroyed when the user logs out or the browser session ends.

              In the second case you have to keep the counter in a file or database and that requires some server side actions.

              Ronald

              Comment

              • burg226
                New Member
                • Jun 2007
                • 8

                #8
                Originally posted by ronverdonk
                Okay, clear. Now let's get more practical.

                Do you want to count the submit hits just for the session of that particular user or do you want to count all submits by all users of your site? In the first case you can keep the counter in storage and it will be destroyed when the user logs out or the browser session ends.

                In the second case you have to keep the counter in a file or database and that requires some server side actions.

                Ronald
                I need it to count all submits by all users of the site...on-going thanks. Any ideas???

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  So you will store your counters in a database, right? Now there are 2 ways of doing this:

                  1. the 'catching' script, i.e. the script that receives the posted values, first updates the counter stats in the database and then processes the posted values.

                  2. after submit use Ajax to go to the server, update the stats and then submits the form. For this one the process would be:

                  a. user fills in form
                  b. user hits submit button
                  c. submit button hit routed to JS routine, which:
                  - uses Ajax to go to server hit counter update routine
                  - returns to issuing JS routine
                  - JS routine submits form

                  I can show the setup code for the latter. I will not go into your code you have shown. You'll have to write your own form and form handling code. Interested?

                  Ronald

                  Comment

                  • burg226
                    New Member
                    • Jun 2007
                    • 8

                    #10
                    Originally posted by ronverdonk
                    So you will store your counters in a database, right? Now there are 2 ways of doing this:

                    1. the 'catching' script, i.e. the script that receives the posted values, first updates the counter stats in the database and then processes the posted values.

                    2. after submit use Ajax to go to the server, update the stats and then submits the form. For this one the process would be:

                    a. user fills in form
                    b. user hits submit button
                    c. submit button hit routed to JS routine, which:
                    - uses Ajax to go to server hit counter update routine
                    - returns to issuing JS routine
                    - JS routine submits form

                    I can show the setup code for the latter. I will not go into your code you have shown. You'll have to write your own form and form handling code. Interested?

                    Ronald
                    Either of these sound great to me. Show me the code. The only problem is I have no idea how to incorporate this into my code. Would anyone be willing to help me on this?

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      The 1st option is the easiest. It starts in your code somewhere after statement 9. It updates a counter (and nothing else!) in table 'hits'. You can work out the adaptation of that code yourself[php]if ($_SERVER['REQUEST_METHOD ']=="POST"){
                      /** ----------------------------------------------
                      * increment the hit counter in the database
                      * ----------------------------------------------- */
                      // open server connection and select database
                      $conn = mysql_connect(S QL_HOST, SQL_USER, SQL_PASS)
                      or die("Cannot connect to server: ".mysql_error() );
                      mysql_select_db (SQL_DB,$conn)
                      or die("Cannot select database: " . mysql_error());
                      // update the hit counter in table 'hits'
                      $result=mysql_q uery("UPDATE hits SET counter=counter +1")
                      or die("Cannot increment hit counter: " . mysql_error());
                      mysql_close($co nn);

                      // ..... the rest of your code ..............
                      //
                      // we'll begin by assigning the To address and message subject[/php]Ronald

                      Comment

                      • burg226
                        New Member
                        • Jun 2007
                        • 8

                        #12
                        Originally posted by ronverdonk
                        The 1st option is the easiest. It starts in your code somewhere after statement 9. It updates a counter (and nothing else!) in table 'hits'. You can work out the adaptation of that code yourself[php]if ($_SERVER['REQUEST_METHOD ']=="POST"){
                        /** ----------------------------------------------
                        * increment the hit counter in the database
                        * ----------------------------------------------- */
                        // open server connection and select database
                        $conn = mysql_connect(S QL_HOST, SQL_USER, SQL_PASS)
                        or die("Cannot connect to server: ".mysql_error() );
                        mysql_select_db (SQL_DB,$conn)
                        or die("Cannot select database: " . mysql_error());
                        // update the hit counter in table 'hits'
                        $result=mysql_q uery("UPDATE hits SET counter=counter +1")
                        or die("Cannot increment hit counter: " . mysql_error());
                        mysql_close($co nn);

                        // ..... the rest of your code ..............
                        //
                        // we'll begin by assigning the To address and message subject[/php]Ronald
                        Awesome thanks. Now if i could only figure out MYSQL we'd be in business. I have an SQL database but have no idea how to access, modify or use it.

                        Comment

                        • ronverdonk
                          Recognized Expert Specialist
                          • Jul 2006
                          • 4259

                          #13
                          Then you'd better first determine what sort of SQL database (Oracle, DB2, MySQL, PostgreSQL, etc.) and then follow some beginner's tutorial on that database. You'll find many of those on the web.

                          Ronald

                          Comment

                          • goraya
                            New Member
                            • Jul 2008
                            • 1

                            #14
                            Hiiiii all,
                            I am so excited to share a very good sitecounters website with you all that i found over the internet. This has so many different kind of counter style, play, music, fashion, computers etc. But the good thing is this, you can make your own sitecounters. You just have to chose font color, style and background color.

                            I had a tough time to find out a pale background color sitecounters for my website but i found the following site and made my own.

                            http://www.sitecounter s.info/

                            You can also see the demo on the following URL.

                            http://www.sitecounter s.info/pages/demo.php

                            This sitecounters site also provide a very good and real time statistic.

                            i would share more sitecounters site as i will find more good then this one


                            <table border="0" cellspacing="0" cellpadding="0" ><tr> <td colspan="2"><a href="http://www.sitecounter s.info" target="_blank" ><img src="http://sitecounters.in fo/pages/counter.php?id= 78" border="0" alt="www.siteco unters.info"></a></td> </tr> <tr class="style1" style="CURSOR: hand" onClick='window .open("http://www.sitecounter s.info/admin/");'> <td valign="top" bgcolor="#B4CE4 2"><div align="center"> <font size="1" face="Arial, Helvetica, sans-serif">COUNTER</font></div></td> <td valign="top" bgcolor="#3D1DA 4"><div align="center"> <font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif">STATS</font></div></td> </tr> </table>

                            Comment

                            Working...