User Tools

Site Tools


hints

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
hints [2014/01/29 18:04] – external edit 127.0.0.1hints [2026/03/21 10:11] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Hints ====== ====== Hints ======
  
-===== PHP Includes  =====+Practical tips and best practices (some are reminders of common knowledge, but worth repeating).
  
-Some people include files like +===== Includes in PHP files ===== 
 + 
 +I've encountered constructions like
  
 include('http://otherdomain/1.html'); include('http://otherdomain/1.html');
Line 11: Line 13:
 virtual('/scj/top/top.html'); virtual('/scj/top/top.html');
  
-or+Having even a few of these—especially 10 per template—significantly impacts performance.
  
-readfile('http://domsin/1.html')+**Why this matters:**
  
 +PHP processes includes before the page is sent to the browser. Remote includes cause page delivery delays. If the remote server slows down, your site slows down too.
  
-moreover they use it may times per page.+Even on the same server, virtual('/scj/top/top.html') creates overhead. For 1 user request, you get multiple server requests: 1 to your domain + 1 per include. With 10 includes, that's 11 total requests for 1 visitor—dramatically increasing server load.
  
-You should NOT use it. 
  
-**Why:**+**The right approach:**
  
-PHP creates page BEFORE user gets it. So if you have something like include('http://otherdomain/1.html') PHP has to load that page each time user load a page with that include. +Always use local includes with absolute file paths:
  
-There 2 downsides of this approach:+include('/home/user/domain/scj/top/top.html');
  
-  * PHP create a regular connection to that host requesting a page. If you have 10 such includes - 1 request to such page generates 10 subrequests loading server. +If you need to include a file from another domain on the same server, use a different path. If it's on another server, ask your admin to set up a cron job to sync the file locally, then include it.
-  * If for some reason PHP won't be able to connect to that domain and load that page - it will wait and first page won't be loaded until PHP gets that include. So if that otherdomain is down - first domain will be virtually down too.+
  
 +**Similar issue:**
  
-**What to do:**+readfile('http://domain/1.html') has the same performance problems as include().
  
-Use only local includes. 
-Ie virtual('/scj/top/top.html') should be include('/home/user/domain/scj/top/top.html'); 
  
-if file is located at another server - ask admin to setup rsync or copy file using crontab and so on. +**Passing parameters to includes:**
- +
  
-**Including local script with parameters**+Most banner rotators use JavaScript includes, but some require PHP includes. Avoid remote includes with parameters:
  
-Let's say you have include like 
- 
-<code> 
 <?php <?php
 include('http://domain.com/banner.php?x=3&y=2'); include('http://domain.com/banner.php?x=3&y=2');
 ?> ?>
-</code> 
  
 +Instead, set parameters locally and include the file:
  
-so you have some parameters here. You can pass it as 
- 
-<code> 
 <?php <?php
 $_GET['x'] = 3; $_GET['x'] = 3;
Line 57: Line 50:
 include('banner.php'); include('banner.php');
 ?> ?>
-</code> 
  
 +This approach passes parameters and keeps the include local rather than remote.
  
-===== Close site for some countries ===== 
  
-Example for .htaccess +===== Deny access for certain countries ===== 
 + 
 +Use .htaccess:
  
 <code> <code>
 RewriteEngine on RewriteEngine on
-RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(RU|CN)$ [NC] +RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(RU|CN)$ [NC]
 RewriteRule ^$ http://google.com [R,L] RewriteRule ^$ http://google.com [R,L]
 </code> </code>
 +
 +===== Rotate pages for returning visitors =====
 +
 +When the same visitor returns to your niche site from different sources, you can show them different page designs. For example, show design 1 to first-time visitors and designs 2, 3, etc. to repeat visitors.
 +
 +Configure this in Settings > CJ Pages by adding multiple design paths, one per line:
 +
 +<code>
 +/home/user/domain/design1.html
 +/home/user/domain/design2.html
 +/home/user/domain/design3.html
 +</code>
 +
 +On the visitor's first visit, they see design1; on their second visit, design2, and so on.
 +
 +If you use internal rotation, you have two options:
 +
 +**Option 1: Automatic rotation in Rotation > Tube > Tube Settings**
 +
 +Enable the option to rotate pages for repeat visitors. The system works as follows:
 +- When a returning visitor (one who came from within your site) visits the index, they see the 2nd page design
 +- If they've seen the 2nd, they see the 3rd, and so on
 +- For categories: if they arrive directly and have already seen that category page, they see the next design
 +
 +Note: This rule only applies if the referrer is your own domain. This ensures that when a visitor clicks from the homepage to a category thumbnail, they see that design on the category page.
 +
 +**Option 2: Create separate page files**
 +
 +Create multiple PHP files like:
 +
 +<code>
 +domain/1.php
 +
 +<?php
 +$_GET['page'] = 1;
 +include('/scj/cgi/index.php');
 +
 +domain/2.php
 +<?php
 +$_GET['page'] = 2;
 +include('/scj/cgi/index.php');
 +?>
 +
 +and set CJPages to:
 +
 +/home/user/domain/1.php
 +/home/user/domain/2.php
 +(and so on)
 +
 +</code>
 +
 +
 +===== Direct links for topsites =====
 +
 +If you link directly to traders instead of using out.php, you can still count clicks using AJAX.
 +
 +Here's an example topsite template:
 +
 +<code>
 +<a target=_blank href='_MEMBER_1_URL' class='domain_css' trader='_MEMBER_1_'>test</a>
 +</code>
 +
 +This renders as:
 +
 +<code>
 +<a target=_blank href='http://somedomain.com/' class='domain_css' trader='somedomain.com'>test</a>
 +</code>
 +
 +The links are direct. To count these clicks, add AJAX code to track them:
 +
 +<code>
 +
 +<script src='/YOUR_FOLDER/includes/js/jquery.js'></script>
 +
 +<script type="text/javascript">
 +$(document).ready(function(){
 + $('.domain_css').each(function(){
 + $(this).on('click', function(){
 + $.get('/YOUR_FOLDER/cgi/out.php?member=' + $(this).attr('trader'),
 + {
 + },
 +   function(data) {
 +   }
 + );
 +
 +
 + });
 + });
 +
 +});
 +
 +</script>
 +
 +</code>
 +
 +
 +
 +Key points:
 +- Replace YOUR_FOLDER with your actual folder path
 +- Each link has class='domain_css' and a trader='somedomain.com' attribute
 +- A click event is attached to this class: $('.domain_css').each(function(){
 +
 +===== Page tracking =====
 +
 +You can track which pages receive traffic and how visitors move through your site. In Trade > Statistics > Page Track, you'll see two columns:
 +
 +- **Inbound Views:** Traffic from outside your site (external referrer)
 +- **Local Views:** Traffic from within your site (internal referrer)
 +
 +You can track pages in two ways:
 +
 +**Option 1: URL parameter**
 +
 +Add &page_track=... to your links
 +
 +**Option 2: Template tags**
 +
 +Use template tags in your HTML:
 +
 +  <!--PAGE_TRACK_CURRENT_PAGE-->
 +  <!--PAGE_TRACK_CATEGORY-->
 +  <!--PAGE_TRACK_any_word-->
 +
 +
 +
hints.1391018664.txt.gz · Last modified: (external edit)