Community Color - Source Code

Source Code Viewer

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.

Options

View: Link Redirect

This is the primary link counter for the directory.

Formatted Code

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.

Link Redirect

001 <?php 002 /** 003 * I track usage on a selection of links in the directory. 004 * This is a quick and dirty page that draws a row from the Link Table. 005 * It forwards the link to the destination of the link and records the event. 006 * The program drops short pages if the link is not found. 007 * 008 **/ 009 // I was calling the variable link_id, but shortened it to l. I still check both 010 $link_id = 0; 011 if (isset($_GET['l'])) { 012 $link_id += (int) $_GET['l']; 013 } elseif (isset($_GET['link_id'])) { 014 $link_id += (int) $_GET['link_id']; 015 } 016 $ad_id=(isset($_GET['a']))? (int) $_GET['a'] : 0; 017 include('/var/www/php/rmHead.php'); // links to 2 018 dbConn(DB_MAIN,'+dir'); 019 // initialize variables 020 $url='https://irivers.com/error.php'; 021 $domain_id = 0; 022 $host = ''; 023 $refer= ''; 024 // check for excessive hits. 025 // The row has the columns: 0: ip_id: 1: ad_hits, 2: link_hits, 3: page_hits, 4: recent_hits, 5: latest_ts 026 $histRow = sqlRow('SELECT * FROM IP_Hits WHERE ip_id = ?',[$rmIP->id]); 027 if($histRow[0] == false) $histRow = [$rmIP->id,0,0,0,0,0]; 028 if ($histRow[5] > ($rmSite->jd - 0.01)) { 029 $histRow[4]++; 030 } else { 031 $histRow[4] = 1; 032 } 033 // echo '
Now = '.$rmSite->jd.PHP_EOL;
034 // print_r($histRow);
035 // echo '
';
036 $histRow[5] = $rmSite->jd; 037 // die('an inglorious death'); 038 if ($histRow[4]++ > 15) { 039 quickPage('Excessive Linking','<h1>Are You a Robot?</h1> 040 <p>This IP Address has accessed a large number of links in a short period.</p> 041 <p>Sadly, this site has suffered steady stream of DDOS attacks from bad actors and I have found it necessary 042 to block users who access an excessive number of pages.<p> 043 <p>If you are a human, thanks for using this directory. The block will release in a few hourss. 044 If you are a robot; Please read the <a href="/robots.txt">robots.txt</a> file and learn basic robot etiquette.</p>'); 045 $url = ''; 046 sqlExec('INSERT INTO IP_Block (ip_id, ts, link_id, ad_id) VALUES (?,?,?,?)',[$rmIP->id,$rmSite->jd,$link_id, $ad_id]); 047 msgHTML(); 048 } elseif ($link_id>0) { 049 $histRow[2]++; 050 $row=sqlRow('SELECT host_nm, path_nm, query_nm, page_id, merchant_id, link_nm, display_nm, ssl_cd FROM Link WHERE link_id=?',[$link_id]); 051 if ($row[0]===false) { 052 $url = ''; 053 } else { 054 if ($row[3] > 0 && $row[0]=='') { 055 $url = 'http://'.$_SERVER['HTTP_HOST'].'/pg.html?pg='.$row[3]; 056 } else { 057 $url='http'.$row[7].'://'.$row[0].$row[1].$row[2]; 058 } 059 } 060 if ($url == '') { 061 // Added 8-2016: The program will report on deleted links. 062 quickPage('Link Not Found','<h2>Link Not Found</h2><p style="text-align: center">System Error. I could not find link #'.$link_id.'.<br />We recorded the event and will try to fix the broken link.<br />Use to the <a href="/contact.html?to=kevind&s=Broken+Link">contact form</a> to tell us about other broken links and problems with the site.</p>'); 063 $sql = 'INSERT INTO Link_Not_Found (link_id, ip_id, ts, site_id, refer_txt) VALUES (?,?,?,?,?)'; 064 sqlExec($sql,[$link_id,$rmIP->id,$rmSite->jd,$rmSite->id,$refer]); 065 } elseif ($row[4] > 0) { 066 // NOTE, I block computers that download the whole site from seeing the merchants 067 header('Location: '.$url); 068 } else { 069 header('Location: '.$url); 070 } 071 if ($link_id > 0) { 072 $sql = 'INSERT INTO Link_Hit (link_id, user_id, ts, ip_id, domain_id, site_id) 073 VALUES (?,?,?,?,?,?)'; 074 sqlExec($sql,[$link_id,$rmUser->id,$rmSite->jd,$rmIP->id, $domain_id, $rmSite->id]); 075 // 11/2017 I stopped updating counter to reduce locks. 076 // sqlExec('UPDATE Link SET hit_cnt = hit_cnt + 1 WHERE link_id = ?',[$link_id]); 077 } 078 } elseif ($ad_id > 0) { 079 $histRow[1]++; 080 // added 8/16 track ad hits. 081 $t= (isset($_GET['t']))? (int) $_GET['t'] : 7; 082 list($url, $status_cd) = sqlRow('SELECT url, status_cd FROM Ad_Def WHERE ad_id = ?',[$ad_id]); 083 $url=str_replace(['k-1274820','pw=269'],['k-'.$rmSite->cj_id,'pw='.$rmSite->al_id],$url); 084 // $chkCnt = sqlValue('SELECT count(*) FROM Ad_Hit WHERE ts > ? and ip_id = ?',[($rmSite->jd - .5), $rmIP->id]); 085 $sql = 'INSERT INTO log.Ad_Hit (ad_id, target_id, site_id, ip_id, domain_id, ts) VALUES (?,?,?,?,?,?)'; 086 sqlExec($sql,[$ad_id, $t, $rmSite->id, $rmIP->id, $domain_id, $rmSite->jd]); 087 if ($status_cd == 1) { 088 quickPage('Ad Expired','<h2>Ad Expired</h2><p>We apologize for the inconvenience, but this ad is no longer active.</p>'); 089 } elseif ($url != '') { 090 header('Location: '.$url); 091 } else { 092 quickPage('Invalid Ad','<h2>Invalid Ad</h2><p>This is an invalid ad. Please visit '.rmGetLink()); 093 } 094 } else { 095 quickPage('Link Forwarder','<h2>Link Forwarder</h2> 096 <p>This is a link forwarding program for the <a href="http://CommunityColor.com">community color</a> project. The links for the site are listed in the <a href="/dir/top">directory</a>.</p>'); 097 } 098 if (isset($_SERVER['HTTP_REFERER'])) { 099 // I want to track down any broken links; so record the HTTP_REFERER. 100 $refer =$_SERVER['HTTP_REFERER']; 101 extract( parse_url($_SERVER['HTTP_REFERER']),EXTR_IF_EXISTS); 102 if ($host != '' && $host != $_SERVER['HTTP_HOST']) { 103 // checkDomain returns a numeric id for each domain. 104 $domain_id = checkDomain($host); 105 } 106 } 107 // update the IP_Hits table. 108 sqlExec('REPLACE INTO IP_Hits VALUES (?, ?, ?, ?, ?, ?)',$histRow); 109 ?>

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 07 2020 05:41:04.. This page has been viewed 1511 Times.

Record of Revisions
idRevbyDateMD5 Hash
80.002016-08-015cd2d4095e87fe5cacb9b351e28cb94e
Moved from Westhost

blog ~ Resource Model ~ shopping