Tutorial Create A Simple Safelink Converter Website With PHP And JQuery

Want to make a website like safelinkconverter.com? At this tutorial, I will share a simple way to create the safelink website. The advantage of making the safelink website to increase your internet advertising income and of course google Adsense. If you’re PHP and javascript expert certainly not difficult to create your own safelink converter website.

Safelink is a simple website that will change all the download links that are on your website automatically become a short URL that redirected to the converter website. in the Safelink website will display ads from Google Adsense and the ads you post.

However, the safety of using the Safelink converter on google Adsense, I am not able to guarantee. My advice is better to use pop-up ads (pop ads, pop cash) on Safelink website.

Here’s a simple way to create a Safelink converter website

Tutorial Create A Simple Safelink Converter Website With PHP And Jquery

Create a link converter script that will change the entire URL on Ahref element into safelink URL

1. Create a folder that will be installed Safelink script with name “blog“. This “blog” folder contains an example HTML page with several links to other sites using the Ahref element.
2. create a file index.php in the folder “blog“.
3. Copy and paste the following code in index.php

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<div>
		<a href="http://alexa.com">link1</a>
		<a href="http://koplojozz.com">link2</a>
		<a href="http://seegatesite.com">link3</a>
	</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" ></script>
 <script type="text/javascript">
 var restricted_link = ["seegatesite.com"];
 $('a').each(function() {
 $(this).attr("href", function(index, old) {
 var baseurlarray = old.split( '/' );
 host = baseurlarray[2];
 if(jQuery.inArray(host, restricted_link) == -1)
 {
 var base64 = window.btoa(old);
 return old.replace(old, "http://localhost/bypass/index.php?go="+base64);
 }
 });
 });
 </script>
</body>
</html>

4. A brief explanation

var restricted_link = ["seegatesite.com"];

The above variables are used to hold the link that will not convert into safelink URL

$('a').each(function() {
....
}

Jquery function above is used to get the entire URL on a web page.

$(this).attr("href", function(index, old) {

.........}

The function above to get the entire href attribute in a HTML element.

  var baseurlarray = old.split( '/' );
  host = baseurlarray[2];

Surely every URL obtained from the script above is not a base URL, but along with the URL path name. Using the split function, we will take the host name URL / base URL. And javascript will check whether the link is allowed to be converted using jQuery.inArray function as the following code

if(jQuery.inArray(host, restricted_link) == -1)
  {
   	var base64 = window.btoa(old);
	return old.replace(old, "http://localhost/bypass/index.php?go="+base64);
  }

As the example above, the safelink website address is http://localhost/bypass/index.php. Variable old is the original URL that we will convert. Then using window.btoa() function. Javascript will encode URL string into base64 encode. Up here the converter safelink script has been completed, the next will make a simple safelink website.

Create a simple converter safelink website

1. Create a new project folder as “bypass”.
2. Add new php file as index.php in the folder “bypass” and copy the following code :

<?php 
$url = base64_decode($_GET['go']); function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); if(curl_exec($ch) === false) { echo 'Curl error: ' . curl_error($ch); die(); } else { $data = curl_exec($ch); } curl_close($ch); return $data; } function get_data_web($url) { $array = array(); $basearray = explode("/", $url); $array['baseurl'] = $basearray[2]; $array['description'] = ''; $array['title'] = ''; $html = file_get_contents_curl($url); $doc = new DOMDocument(); @$doc->loadHTML($html);
	$nodes = $doc->getElementsByTagName('title');
	$array['title'] = @$nodes->item(0)->nodeValue;
	$metas = $doc->getElementsByTagName('meta');
	for ($i = 0; $i < $metas->length; $i++)
	{
		$meta = $metas->item($i);
		if($meta->getAttribute('name') == 'description')
		{
			$array['description'] = $meta->getAttribute('content');
		}
	}
	return $array;
}
$data = get_data_web($url);
?>
<!DOCTYPE html>
<html>
<head>
	<title>Safelink Converter</title>
	<style type="text/css">
 table{
 border: 1px solid grey;
 }
 table tr td{
 border: 1px solid grey;
 padding: 10px;
 }
 .alink{
 margin: 10px;
 padding: 10px;
 color: white;
 background-color: orange; 
 }
 </style>
	<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>

	
<div>

<h2><i style="color:green" class="fa fa-shield"></i> You have requested a link to <?php echo $data['baseurl'] ?> </h2>


<table>
			
<tr>
				
<td colspan="3"><center> <span id="contentlink">Generating link <i class="fa fa-spinner fa-pulse fa-fw"></i></span></center></td>

			</tr>


<tr>
				
<td>Title</td>


<td>:</td>


<td><?php echo $data['title'] ?></td>

			</tr>


<tr>
				
<td>Description</td>


<td>:</td>


<td><?php echo $data['description'] ?></td>

			</tr>

		</table>

	</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" ></script>
 <script type="text/javascript">
 var url = '<?php echo $url ?>';
 setTimeout(function()
 { 
 $("#contentlink").html('<a class="alink" href="'+url+'"> Continue to link</a>')
 }, 5000);
 </script>
	</body>
</html>

3. A brief explanation :

I made two functions using PHP. The first function is file_get_contents_curl I use to get the html content from sites who will be converted using safelink script (especially taking title and meta description of a website). The second function get_data_web() is used to process html content and take the title and meta description of web to be visited.

var url = '<?php echo $url ?>';
	setTimeout(function()
	{ 
		$("#contentlink").html('<a class="alink" href="'+url+'"> Continue to link</a>')
	}, 5000);

Then using javascript setTimeout function set 5 seconds will bring up the link that will be visited.

Up here the script to run smoothly. How to use safelink converter script in WordPress? Paste the code below to widget bar WordPress

<script
 src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
 <script type="text/javascript">
 var restricted_link = ["seegatesite.com"];
 $('a').each(function() {
 $(this).attr("href", function(index, old) {
 var baseurlarray = old.split( '/' );
 host = baseurlarray[2];
 if(jQuery.inArray(host, restricted_link) == -1)
 {
 var base64 = window.btoa(old);
 return old.replace(old, "http://localhost/bypass/index.php?go="+base64);
 }
 });
 });
 </script>

Up here how to make the Safelink website has been completed. But how to implement it on Blogspot?

To blogspot many articles you can find on google search engine, but I’ll summarize how to create Safelink website on blogger that I obtained from here

1. Create new Blogspot blog in blogger.com
2. Create a new page and give the name “go“.
3. Add the following script for a while and publish

<script src="LINK-JAVASCRIPT" type="text/javascript"></script>

4. Create new javascript file and save as safelink.js

var Base64 = {
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    encode: function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        input = Base64._utf8_encode(input);
        while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
        }
        return output;
    },
    decode: function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        while (i < input.length) {
            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            output = output + String.fromCharCode(chr1);
            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }
        }
        output = Base64._utf8_decode(output);
        return output;
    },
    _utf8_encode: function (string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            } else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        return utftext;
    },
    _utf8_decode: function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
        while (i < utftext.length) {
            c = utftext.charCodeAt(i);
            if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            } else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
        return string;
    }
}
var encode = document.getElementById('encode'),
    decode = document.getElementById('decode'),
    output = document.getElementById('output'),
    input = document.getElementById('input');
var User_ID = "";
var protected_links = "";
var a_to_va = 0;
var a_to_vb = 0;
var a_to_vc = "";

function auto_safelink() {
    auto_safeconvert();
}

function auto_safeconvert() {
    var a_to_vd = window.location.hostname;
    if (protected_links != "" && !protected_links.match(a_to_vd)) {
        protected_links += ", " + a_to_vd;
    } else if (protected_links == "") {
        protected_links = a_to_vd;
    }
    var a_to_ve = "";
    var a_to_vf = new Array();
    var a_to_vg = 0;
    a_to_ve = document.getElementsByTagName("a");
    a_to_va = a_to_ve.length;
    a_to_vf = a_to_fa();
    a_to_vg = a_to_vf.length;
    var a_to_vh = false;
    var j = 0;
    var a_to_vi = "";
    for (var i = 0; i < a_to_va; i++) {
        a_to_vh = false;
        j = 0;
        while (a_to_vh == false && j < a_to_vg) {
            a_to_vi = a_to_ve[i].href;
            if (a_to_vi.match(a_to_vf[j]) || !a_to_vi || !a_to_vi.match("http")) {
                a_to_vh = true;
            }
            j++;
        }
        if (a_to_vh == false) {
            var encryptedUrl = Base64.encode(a_to_vi);
            a_to_ve[i].href = "http://safelinkweb.blogspot.com/p/go.html?url=" + encryptedUrl;
            a_to_ve[i].rel = "nofollow";
            a_to_vb++;
            a_to_vc += i + ":::" + a_to_ve[i].href + "\n";
        }
    }
    var a_to_vj = document.getElementById("anonyminized");
    var a_to_vk = document.getElementById("found_links");
    if (a_to_vj) {
        a_to_vj.innerHTML += a_to_vb;
    }
    if (a_to_vk) {
        a_to_vk.innerHTML += a_to_va;
    }
}

function a_to_fa() {
    var a_to_vf = new Array();
    protected_links = protected_links.replace(" ", "");
    a_to_vf = protected_links.split(",");
    return a_to_vf;
}

Change http://safelinkweb.blogspot.com/p/go.html with your new Blogspot page URL.
5. Upload the safelink.js in yourjavascript.com.
6. See step number 3, change the link-javascript with safelink.js you have uploaded at yourjavascript.com

7. Reopen new page that you created earlier on blogspot (step 2) and add the following script under the javascript that you created earlier

<center>
<div class="fitur-body">
Please Wait and Click Continue For Go To Link Target.<br>
<script type="text/javascript">
//<![CDATA[
function changeLink() {
 var e = Base64.decode(res);
 window.open(e, "_blank")
}
var currentURL = location.href,
 str = currentURL,
 res = str.replace("http://safelinkweb.blogspot.co.id/p/go.html?url=", "");
document.write('<button target="_self" class="btn btn-success" style="display: block;" id="download" onclick="changeLink()">Continue</button>');
onload: generate();
//]]>
</script>
</div>
</center>  

don’t forget to change http://safelinkweb.blogspot.co.id/p/go.html with your new Blogspot page.

8. Copy the following javascript into the main Blogspot / your blog download so that the Safelink script can work well.

<script src="LINK-Javascript" type='text/javascript'/>
<script type="text/javascript">
//<![CDATA[
protected_links = "facebook.com,twitter.com"; 
auto_safelink();
//]]>
</script>

Change the variables of protected links with a link you do not want to be turned into Safelink website url

9. Edit your main blogspot template Template > Edit > HTML and change <body> to be : <body onload=”auto_safeconvert()”>

10. Save and see the result.

Download the full example  project here

Easy, right? Thus my article Tutorial Create A Simple Safelink Converter Website With PHP And Jquery.

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: