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='http://irivers.com/error.php'; 021 $domain_id = 0; 022 $host = ''; 023 $refer= ''; 024 if (isset($_SERVER['HTTP_REFERER'])) { 025 // I want to track down any broken links; so record the HTTP_REFERER. 026 $refer =$_SERVER['HTTP_REFERER']; 027 extract( parse_url($_SERVER['HTTP_REFERER']),EXTR_IF_EXISTS); 028 if ($host != '' && $host != $_SERVER['HTTP_HOST']) { 029 // checkDomain returns a numeric id for each domain. 030 $domain_id = checkDomain($host); 031 } 032 } 033 if ($link_id>0) { 034 $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]); 035 if ($row[0]===false) { 036 $url = ''; 037 } else { 038 if ($row[3] > 0 && $row[0]=='') { 039 $url = 'http://'.$_SERVER['HTTP_HOST'].'/pg.html?pg='.$row[3]; 040 } elseif ($row[6] == 'p') { 041 $url='http://prosperent.com/api/linkaffiliator/redirect?apiKey=44b70e82e2cec9e8e105be57e63664ab&url=http://'.$row[0]; 042 } else { 043 $url='http'.$row[7].'://'.$row[0].$row[1].$row[2]; 044 } 045 } 046 if ($url == '') { 047 // Added 8/16: The program will report on deleted links. 048 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>'); 049 $sql = 'INSERT INTO Link_Not_Found (link_id, ip_id, ts, site_id, refer_txt) VALUES (?,?,?,?,?)'; 050 sqlExec($sql,[$link_id,$rmIP->id,$rmSite->jd,$rmSite->id,$refer]); 051 } elseif ($row[4] > 0) { 052 // NOTE, I block computers that download the whole site from seeing the merchants 053 if ($rmIP->block > 0) { 054 quickPage('Excessive Linking','<h1>Are You a Robot?</h1> 055 <p>This IP Address has accessed a large number of pages in a short period.</p> 056 <p>If you are a human, thanks for using this directory. please proceed to "<b>'.$row[6].'</b>" by <a href="'.$url.'">clicking here</a>. If you are a robot; please read the 057 <a href="/robots.txt">robots.txt</a> file and learn basic robot etiquette.</p>'); 058 $url = ''; 059 } else { 060 header('Location: '.$url); 061 } 062 } else { 063 header('Location: '.$url); 064 } 065 if ($link_id > 0) { 066 $sql = 'INSERT INTO Link_Hit (link_id, user_id, ts, ip_id, domain_id, site_id) 067 VALUES (?,?,?,?,?,?)'; 068 sqlExec($sql,[$link_id,$rmUser->id,$rmSite->jd,$rmIP->id, $domain_id, $rmSite->id]); 069 // 11/2017 I stopped updating counter to reduce locks. 070 // sqlExec('UPDATE Link SET hit_cnt = hit_cnt + 1 WHERE link_id = ?',[$link_id]); 071 } 072 } elseif ($ad_id > 0) { 073 // added 8/16 track ad hits. 074 $t= (isset($_GET['t']))? (int) $_GET['t'] : 7; 075 $url = sqlValue('SELECT url FROM Ad_Def WHERE ad_id = ?',[$ad_id]); 076 $url=str_replace(['k-1274820','pw=269'],['k-'.$rmSite->cj_id,'pw='.$rmSite->al_id],$url); 077 $chkCnt = sqlValue('SELECT count(*) FROM Ad_Hit WHERE ts > ? and ip_id = ?',[($rmSite->jd - .5), $rmIP->id]); 078 $sql = 'INSERT INTO log.Ad_Hit (ad_id, target_id, site_id, ip_id, domain_id, ts) VALUES (?,?,?,?,?,?)'; 079 sqlExec($sql,[$ad_id, $t, $rmSite->id, $rmIP->id, $domain_id, $rmSite->jd]); 080 if ($url != '') { 081 if ($chkCnt > 24) { 082 quickPage('Large Hit Count','<h1>Large Hit Count</h1> 083 <p>This IP '.$rmIP->ipStr.' has clicked on numerous ads in the last few hours.</p> 084 <p>If you are a human; <a href="'.$url.'">Click here</a> to continue.</p> 085 <p>If you are a computer; Please respect <a href="robots.txt">robots.txt</a>.</p>'); 086 } else { 087 header('Location: '.$url); 088 } 089 } else { 090 quickPage('<h2>Invalid URL</h2><p>This is an invalid Link. Please visit '.rmGetLink()); 091 } 092 } else { 093 quickPage('Link Forwarder','<h2>Link Forwarder</h2> 094 <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>'); 095 } 096 ?>

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 November 21 2017 19:28:05.. This page has been viewed 141 Times.

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

blog ~ Resource Model ~ shopping