Masking External Links
Link Cloaking Script
This article is about one of the most common methods of masking external links (in English - link cloaking).
The link cloaking works as follows. While viewing the page, the visitor sees the usual internal link. But, after moving on it - gets on another site.
To date, there are several ways to create such links. But we will consider one of the most successful (from my point of view) that does not require support from the browser.
The idea is to use a redirect and is implemented in two stages:
- 1) in the root of the site (the folder pointed to by DOCUMENT_ROOT) create a folder named pages.
- 2) in this folder we place three files:
- Linkslist.php - it will have an array with external links;
- Redirect.php - analyzes the link on which the transition was made and sends the visitor to an external resource;
- .htaccess - passes all requests to the redirect.php script.
Principle of operation
On the pages of the site you place links like: http: // site_name / pages / get / second_part_address , where the second_word_address can be anything, for example, mypage.html or page1 , etc. It all depends on your imagination.
The address transformation is as follows. At any transition under the link of a kind http: // site_name / pages / get / ......... to it rules from.htaccess will be applied.
Note. The server must have apache mod_rewrite installed and running.
Using the rules in this file, we replace in the address get to redirect.php . Those. Get: http: //site_name/pages/redirect.php/second_part of the address
The script redirect.php on the second part of the address selects an external link and sends the browser redirect.
The described order of address translation is shown in the diagram.
The Script itself
Linkslist.php
<?php
$linksList = array(
'page1.html' => 'http://www.google.com',
'page2.html' => 'http://www.php.net'
);
?>
A common array is declared here. The key of the element is the second part of the address of the internal reference, and the value is the address of the external resource .
Redirect.php
<?php
require_once('linkslist.php');
$request = $_SERVER['REQUEST_URI'];
$dest = explode('/', $request);
$newUrlKey = end($dest);
if (array_key_exists($newUrlKey, $linksList)) {
header('Location:'.$linksList[$newUrlKey]);
}
else {
header('Location:http://www.simplecoding.org');
}
?>
Here we connect a file with an array of links (line 2). After that, select the second part from the address (lines 5, 6) and form the header with a redirect (lines 8-13).
.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^get/(.+) /pages/redirect.php/$1 [L]
</IfModule>
In this file, we created a rule that changes the get to redirect.php in the address.
Conclusion
To date, there are several ready-made solutions that perform the same functions (for example, plugins for WordPress like Hidden Affiliate Links ).
Most importantly, before using the method described in this article, you should clearly understand what the disguise of links will give you.
After all, by and large, the account of disguising the links is very much like cheating a visitor and a search engine. Or do you have a different opinion? Therefore, I suggest first to optimize the site from a large number of external links.
How to protect your site from detecting in it corrupt links such as Sape.com?
This is not just about countering this detector of corrupt links, but also for any other. Working in the form of a separate resource, or built into the search engine algorithm Never mind.
Let's for example not let you define sales links on sites built on the popular LastoBlog engine, and at the same time on the LastoSplog spy engine, too.
The script itself:
As you know, the standard code of Sapa clings to the settings in this way:
global $mysape;
define ('_SAPE_USER',"usersiteidentificator");
require_once ("./data/sape/sape.php");
$sape=new SAPE_client();
$mysape=$sape->return_links();
It is assumed that the folder is stuffed inside the file structure of the engine, and not lying defenseless in its root, hence the path to the file with the client code, pay attention to this aspect.
As well as the fact that the folder is renamed to sape
Now let's add a couple of operators, highlighted in red:
global $mysape;
define ('_SAPE_USER',"usersiteidentificator");
require_once ("./data/sape/sape.php");
require_once ("./data/sape/sape_venality_name.php");
$sape=new SAPE_client( $sape_venality_name );
$mysape=$sape->return_links();
And, of course, in the daddy of sapa we will also put this code
The filename, as you understand, sape_venality_name.php )
<?php
$sape_venality_name=array();
# Документы, работающие с глобалом GET:
$allowed_pages=array("key.php","ping","remoute");
# Разрешённые переменные в УРле иных документов:
$allowed_var=array("");
$tm=explode("?",$_SERVER['REQUEST_URI']);
if (isset($tm[1]) and $tm[0]==str_replace($allowed_pages,"",$tm[0])) {
$k=preg_match_all("/(.*)=(.*)\&/Uis",$tm[1]."&",$am);
$bm=array();
for ($i=0; $i < $k; $i++) {
if ($am[2][$i]=="" or !in_array($am[1][$i],$allowed_var))continue;
$bm[]=$am[1][$i]."=".$am[2][$i];
}
$tm[1]=implode("&",$bm);
$sape_venality_name['request_uri']=
$_SERVER['REQUEST_URI']=($tm[1]=="") ? $tm[0]: implode("?",$tm);
}
?>
After using this code (calling it before launching the Sapa class), our blog or the rest stop responding to the testing of the resource with all the Sources of Sales Links for having them.
Also, if the client code of other exchanges for the sale of links, triggered after the client code of the sap, is attached to the resource, then all links sold through such exchanges also cease to be detected by the detector (in most cases, not 100%, of course).
Tuning the Sapa code
With external control over the operation of the Sapa client code, it is sometimes necessary to set up the encoding, or a number of other points. Normally, in this case, you should create an array with any name, create the keys in the array, and assign them the necessary values, and then give the array to the class. But, as it appears from the printout of the code with red lines, we are already feeding the class some array. And where do I put the encoding?
For example, consider the situation when your site is on UTF .
In this case, in the interval between the launch of the rescue code and the return of the results of its work to the class, it is necessary to insert the necessary key into the born array, in full accordance with the recommendations:
global $mysape; define ('_SAPE_USER',"usersiteidentificator"); require_once ("./data/sape/sape.php"); require_once ("./data/sape/sape_venality_name.php"); $sape_venality_name['charset']='UTF-8'; $sape=new SAPE_client( $sape_venality_name ); $mysape=$sape->return_links();
Need other keys? Pull in by analogy.
When the sales links are not from Sapa:
Hardly vouch for all the brokers of corrupt links, because the client code they have is very different, but theoretically here is such a design (in the complete absence of sap on the site) should help:
require_once ("./data/sape/sape_venality_name.php");
Naturally, in this document we consider only the camouflage of corrupt links to the engines mentioned at the beginning of the document, and also very similar to them. Otherwise, reading this document should be supported by knowledge of php
Comments
Commenting on, remember that the content and tone of your message can hurt the feelings of real people, show respect and tolerance to your interlocutors even if you do not share their opinion, your behavior in the conditions of freedom of expression and anonymity provided by the Internet, changes Not only virtual, but also the real world. All comments are hidden from the index, spam is controlled.