This page lets you view source code from my server. The program uses a brute force code formatter to color code elements. NOTE: I wrote this program while trying to learn the vim text editor. This is not my usual coding style.
Use this select box to select a file.
A short program produces an SVG page counter
Below is the code all formatted with bright colors. The program links to files opened with include() and expands those opened with require(). Clicking on the require line should change visibility. You can view the database schema with schema viewer.
svg counter
001 <?php
002 /**
003 * Occasionally I want to put visible web counters on a page.
004 * I created this counter so that I could see how many hits I had on my tumblr
005 * blogs: @see http://prog.communitycolor.com/svgCounts.html
006 *
007 * This code is very simple. sing SVG.
008 *
009 */
010 //rmHead.php includes the PHP connection string and parses the session cookie.
011 include('/var/www/php/rmHead.php'); // links to 2
012 $num = -1; // -1 indicates an error
013 $src = (isset($_GET['t']))? $_GET['t'] : '';
014 if ($rmUser->id ==3) {
015 // I am user 3. I don't want the system to track my hits on the site.
016 // Display large placeholder number if I see the counter.
017 $num = 7654321;
018 } elseif ($src == '') {
019 // Display is sequence if the referenced number is not found.
020 $num = 1234567;
021 } else {
022 if (strlen($src) > 6) {
023 // might be a SQL inject attack.
024 $num = -2;
025 } else {
026 $num=sqlValue('SELECT counter_seq FROM log.SVG_Counter WHERE counter_cd = ?',[$src]);
027 }
028 if ($num === false or $num==0) {
029 // This is a new counter.
030 $ref = (isset($_SERVER['HTTP_REFERER']))? $_SERVER['HTTP_REFERER'] : 'x';
031 $num = -1;
032 // Insert the new counter.
033 $sql='INSERT INTO log.SVG_Counter (counter_cd, counter_nm, counter_url, add_ts, counter_seq)
034 VALUES (?,?,?,julianday(\'now\'),1)';
035 // ?,?,?),',[$src,$src],'log');
036 // 2-2018 I no longer automatically create a new counter for unknown source.
037 // sqlExec($sql,[$src,$src,$ref]);
038 } else {
039 sqlExec('UPDATE log.SVG_Counter SET counter_seq = counter_seq+1 WHERE counter_cd=?',[$src]);
040 }
041 }
042 $digits = sprintf('%1$07d',$num);
043 $str = '';
044 $bPos=5;
045 for ($i=0; $i<7; $i++) {
046 $str .= '<rect x="'.$bPos.'" y="2" height="18" width="14" />
047 <text x="'.($bPos+7).'" y="15">'.$digits[$i].'</text>
048 ';
049 $bPos += 16;
050 }
051 header("Content-type: image/svg+xml");
052 echo '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
053 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
054 <svg viewBox="0 0 120 32" version="1.1"
055 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
056 <desc>iRivers.com Hit Counter</desc>
057 <style type="text/css" >
058 text {
059 text-anchor: middle;
060 margin: 1px;
061 padding: 2px;
062 font-family: Arial, Helvetica, sans-serif;
063 font-size: 14px;
064 font-weight: bold;
065 stroke: #eef;
066 fill: #ffe;
067 }
068 rect {
069 stroke:#777;
070 fill: #333;
071 }
072 </style>
073 <a xlink:href="http://prog.communitycolor.com/svgCounts.html" target="_top">
074 <rect x="0" y="0" width="120" height="20" style="fill:rgb(77,66,55);stroke-width:2;stroke:rgb(22,22,22)" />
075 '.$str.'
076 </a>
077 </svg>';
078 msgHTML();
079 ?>
Use "view source" from your browser to grab the output. Feel free to link to this project and check out the Resource Model for information on PHP coding or my tumblr blog for picture of Arizona, Colorado or Utah.
File last modified at February 26 2018 18:58:47.. This page has been viewed 1157 Times.