MySQL
  Home arrow MySQL arrow Page 3 - Logging with PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Logging with PHP
By: Tim Perdue
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2003-02-06

    Table of Contents:
  • Logging with PHP
  • The Design
  • Source Code
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Logging with PHP - Source Code


    (Page 3 of 4 )

    <!--

      //gif11.php accepts these parameters:
    $c; //correlates to fld_affil_num in the database -
       //unique for each site
    $s; //correlates to fld_special in the database
    $b; //random number - forces the gif to load, even if cached
       //generated by PHP and discarded
    -->

    <?php

    //gif11.php
    //don't have any extra spaces outside the <? ?>
    //  or you could have a broken gif come back

    Header( "Content-type: image/gif");
    passthru( "cat clear.gif" ); //send a 1x1 gif

    $logger_action=5;  //impression
    $logger_special=$s; //move the $s param for the logger
    $fld_affil_num=$c; //ditto for the $c param

    include('connect.inc'); //connect to the DB SERVER
    include('logger.inc'); //Exanded below

    ?>


    PHP Code to generate the GIF URL:

    <?php

    srand((double)microtime()*1000000);
    $random_num=rand(5,95);
    ?>
    <P>
    <IMG SRC="http://www.yourserver.com/util/gif11.php?c=4&s=phpbuildercom&b=<?
    echo $random_num; ?>" height=1 width=1>


    connect.inc:

    <?php

    //
    //Connect to the PostgreSQL database
    //


    $conn = pg_pconnect("user=myname dbname=my_db");

    //I use a persistent connection instead of opening
    //and closing the connection tens of thousands
    //of times/day

    if (!$conn) {
      echo "An error occured.\n"; //amateur error detection
      exit;
    }

    ?>


    logger.inc:

    <?php

    //
    //ACTIONS - 1=get 2=click-thru 3=clickin 4=jump2zip 5=impression
    //

    if (!$logger_action) {echo "error in logger"; exit;}
    if (!$logger_special) {echo "error in logger"; exit;}

    //
    //The following should be on one long line...
    //

    $logger_sql="insert into tbl_activity_log values (".date("Ymd", mktime()).", ". //PHP method to build date
      "'".date("H", mktime())."', ". //PHP method to get hour
      "'$REMOTE_ADDR', ".     //Get the IP address of client
      "$logger_action, ' ".    //action as set up in gif11.php
      "$logger_special', ".    //ditto
      "$fld_affil_num);";     //which web site

    $res_logger = pg_Exec ($conn, $logger_sql);

    if (!$res_logger) {
      echo "An error occured in the logger.\n";
      echo pg_ErrorMessage();
      exit;
    }

    ?>


    adclick.php:

    <?php

    $goto_location="Location: ".$goto."&b=".$b;

    Header($goto_location);

      $logger_action=2; //adclick
      $logger_special="adclick";
      $fld_affil_num=$c;

      include('connect.inc');
      include('logger.inc');

    ?>


    reporter.php:

    <?php

    //
    //This is just a tiny sample of the reporting you can do
    //

    Function ShowResults($result) {

    //I apologize to the author of this code -
    //I believe I found it in the code exchange, but I
    //can't find it now! --Tim

      if ($result) {
        $rows = pg_NumRows($result);
        $cols = pg_NumFields($result);

        echo( "<table border=1>\n");
        /* Create the headers */
        echo( "<tr>\n");
        for($i = 0; $i < $cols; $i++) {
          printf( "<th>%s</th>\n", pg_FieldName($result, $i));
        }
        echo( "</tr>");
        for($j = 0; $j < $rows; $j++) {
          echo( "<tr>\n");
          for($i = 0; $i < $cols; $i++) {
            printf( "<td>%s</td>\n", pg_result($result, $j, $i));
          }
          echo( "</tr>");
        }
        echo( "</table>");
      } else {
        echo(pg_errormessage());
      }

    //
    //The following should be one long line
    //

    $report_sql="SELECT fld_date, fld_special, count(*) AS IMPRESSIONS ".
      "FROM tbl_activity_log ".
      "WHERE fld_action=5 AND fld_affil_num=$affil ".
      "GROUP BY fld_date, fld_special;";

    $res_click_report = pg_Exec ($conn, $report_sql);

    if ((!$res_click_report) || (pg_NumRows($res_click_report) < 1)) {
      echo "An error occured.\n";
      exit;
    }

    ShowResults($res_click_report);

    }

    ?>

    More MySQL Articles
    More By Tim Perdue


     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT