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['link_id'])) { 012 $link_id += (int) $_GET['link_id']; 013 } elseif (isset($_GET['l'])) { 014 $link_id += (int) $_GET['l']; 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 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[0].$row[1].$row[2]; 044 } 045 } 046 047 if ($url == '') { 048 // Added 8/16: The program will report on deleted links. 049 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>'); 050 $sql = 'INSERT INTO Link_Not_Found (link_id, ip_id, ts, site_id, refer_txt) VALUES (?,?,?,?,?)'; 051 sqlExec($sql,[$link_id,$rmIP->id,$rmSite->jd,$rmSite->id,$refer]); 052 } elseif ($row[4] > 0) { 053 // NOTE, I block computers that download the whole site from seeing the merchants 054 if ($rmIP->block > 0) { 055 quickPage('Excessive Linking','<h1>Are You a Robot?</h1> 056 <p>This IP Address has accessed a large number of pages in a short period.</p> 057 <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 058 <a href="/robots.txt">robots.txt</a> file and learn basic robot etiquette.</p>'); 059 $url = ''; 060 } else { 061 header('Location: '.$url); 062 } 063 } else { 064 header('Location: '.$url); 065 } 066 if ($link_id > 0) { 067 $sql = 'INSERT INTO Link_Hit (link_id, user_id, ts, ip_id, domain_id, site_id) 068 VALUES (?,?,?,?,?,?)'; 069 sqlExec($sql,[$link_id,$rmUser->id,$rmSite->jd,$rmIP->id, $domain_id, $rmSite->id]); 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 $sql = 'INSERT INTO log.Ad_Hit (ad_id, target_id, site_id, ip_id, domain_id, ts) VALUES (?,?,?,?,?,?)'; 078 sqlExec($sql,[$ad_id, $t, $rmSite->id, $rmIP->id, $domain_id, $rmSite->jd]); 079 if ($url != '') { 080 header('Location: '.$url); 081 } else { 082 quickPage('<h2>Invalid URL</h2><p>This is an invalid Link. Please visit '.rmGetLink()); 083 } 084 } else { 085 quickPage('Link Forwarder','<h2>Link Forwarder</h2> 086 <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>'); 087 } 088 ?>

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 March 08 2017 17:41:36.. This page has been viewed 69 Times.

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

blog ~ Resource Model ~ shopping