By Tim Perdue on December 10, 2000 The next step was getting the info into the tables. It would be a perfect world if all pages were served through PHP and all of your various web sites existed on one box. Unfortunately, I have an array of servers scattered all…
PHP Tutorials
Whether just getting started or an expert, this vast collection of PHP tutorials will help you create dynamic content for powerful web-based applications in no time.
By Tim Perdue on December 10, 2000 REPORTING Reporting all this information is easy with PHP – just write up some SQL, execute it and use the ShowResults() function (included below) to display it. You can also graph it using the Graphing Lib that I mentioned in a prior article….
By Tim Perdue on December 10, 2000 browser.php <?php // // SourceForge: Breaking Down the Barriers to Open Source Development // Copyright 1999-2000 (c) The SourceForge Crew // http://sourceforge.net // // $Id: tim20001211.php3,v 1.3 2001/05/22 19:22:47 tim Exp $ unset ($BROWSER_AGENT); unset ($BROWSER_VER); unset ($BROWSER_PLATFORM); function browser_get_agent () { global $BROWSER_AGENT; return $BROWSER_AGENT; } function browser_get_version() { global $BROWSER_VER; return $BROWSER_VER; } function browser_get_platform() { global $BROWSER_PLATFORM; return $BROWSER_PLATFORM; } function browser_is_mac() { if (browser_get_platform()==’Mac’) { return true; } else { return false; } } function browser_is_windows() { if (browser_get_platform()==’Win’) { return true; } else { return false; } } function browser_is_ie() { if (browser_get_agent()==’IE’) { return true; } else { return false; } …
By Tim Perdue on December 10, 2000 gif11.php3 <!– Warning – remove everything outside of the <?php tags or your image will break //gif11.php3 accepts these parameters: $c; //correlates to group_id in the database – //unique for each site $s; //correlates to page in the database $b; //random number – forces the gif to load, even if cached //generated by PHP and discarded –> <?php //database connection code //and abstraction layer include(‘database.php’); //browser detection library include(‘browser.php’); $type=0; //impression $page=$s; //move the $s param for the logger $group_id=$c; //ditto for the $c param header(“Expires: Mon, 26 Jul 1997 05:00:00 GMT”); header(“Last-Modified: ” . gmdate(“D, d M Y H:i:s”) . ” GMT”); header(“Cache-Control: no-cache”); header(“Cache-Control: post-check=0,pre-check=0”); header(“Cache-Control: max-age=0”); header(“Pragma: no-cache”); Header( “Content-type: image/gif”); echo readfile ($DOCUMENT_ROOT.”/util/clear.gif” ); // // If eveything resides on the same server, just include // the following code on every page instead of doing the 1×1 gif trick // $sql = “INSERT INTO activity_log ” . “(day,hour,group_id,browser,ver,platform,time,page,type) ” . “VALUES (” . date(‘Ymd’, mktime()) . “,'” . date(‘H’, mktime()) . “‘,’$group_id’,'” . browser_get_agent() . “‘,'” . browser_get_version() . “‘,'” . browser_get_platform() . “‘,'” . time() . “‘,’$PHP_SELF’,’$type’);”; $res_logger = db_query ( $sql ); if (!$res_logger) { echo “An error occured in the logger.n”; echo db_error(); exit; }…
By Tim Perdue on January 3, 2001 One of PHP’s greatest strengths can also be a great weakness in the wrong hands. I’m talking about its forgiving nature. One of the reasons why PHP has become so wildly popular is because it lets very inexperienced web developers build powerful applications…
By Tim Perdue on January 3, 2001 Indenting All your code should be properly indented. This is the most fundamental thing you can do to improve readability. Even if you don’t comment your code, indenting will be a big help to anyone who has to read your code after you….
By Tim Perdue on January 3, 2001 Function Calls Functions should be called with no space between between the function name and the parentheses. Spaces between params and operators are encouraged. $var = myFunction($x, $y); Functions Function calls are braced differently than conditional expressions. This is a case where I’ll…
By Tim Perdue on January 3, 2001 PHP Tags You should always use the full <?php ?> tags to enclose your code, not the abbreviated <? ?> tags, which could conflict with XML or other languages. ASP-style tags, while supported, are messy and discouraged. Strings The proper use of strings…
By Tim Perdue on January 8, 2001 Like most PHP developers out there, I started off using databases to store relatively simple data structures for my dynamic sites. PHP’s slickness and ease of database connectivity is no doubt a major reason for its wild success, and also probably a reason…
By Tim Perdue on January 8, 2001 SELECT * FROM mytable WHERE category_id=1; Even the most rudimentary indexing strategy means you will create a simple index on category_id: CREATE INDEX mytable_categoryid ON mytable (category_id); Very simple right? Now what if you are going to use multiple criteria to select from…