Home > Questions and Answers > General Questions

Target Trimming to Root Domain (1)


12-18-2012 06:24 AM #1 moneycometh (Member)
Target Trimming to Root Domain

Hi Stackers,

I'm building my first landing page and don't know html or php. I'm groping around in the dark here. It's for a coupon style landing page. I got the idea from Maynzie.

I've added a target trimming to root domain code to it and also added a fix by another reader called gorkem on ctrtard's post. This is his fix:

"thanks for this post. it is great..

BUT, It does not handle;

https://www.ctrtard.com/sites/

if there is a slash after sub-directory, it does not work. I am working on it now, will fix it soon.

Instead of using the code for last slash, I did this;

$first_slash = stripos($target, “/”);
$target = substr($target, 0, $first_slash);

it worked great even if there is 5 sub directory."

Here is the code by ctrtard: [PHP]<?php
function trim_url_to_root_domain($target) {
/** Trim Url to Root Domain
* by ctrtard.com 8/1/2011
*
* This function is mainly useful for PPV. You can pass it a URL (target) and it
* will trim it down to the root domain. Unlike most other examples I've found,
* It handles subdomains and squirrely, or malformed URLs like "//something.domain.com"
* The result is a nice looking domain for dynamic keyword insertion into your
* landing pages.
*
* Usage:
* echo trim_url_to_root_domain("http://mytarget.com");
* or
* echo ucfirst (trim_url_to_root_domain("http://mytarget.com")); // uppercase first letter
*
*/
// trim http, https, and //
$target = str_replace("http:", "", $target);
$target = str_replace("https:", "", $target);
$target = str_replace("//", "", $target);

// check for dots
$dots = substr_count($target, '.');
if ($dots > 1) { // if there are more than 1 dots, we need to remove subdomain
$first_dot = strpos ($target, ".");
$target = substr($target, $first_dot+1, strlen($target));
}

// find the last slash, this should be the slash just before directory info
$last_slash = strripos($target, "/");
if ($last_slash > 0 ) {
$target = substr($target, 0, $last_slash);
}

// find last slash one more time, to handle targets like /domain.com
$last_slash = strripos($target, "/");
if ($last_slash !== FALSE ) {
$target = substr($target, 1, strlen($target));
}

// normalize target so it's all lower case
$target = strtolower($target);

return $target;
}
?>[/PHP]

Here is my landing page: [PHP]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>My Website</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css?v=2">
<script src="js/behavior.js"></script>
</head>
<center>
<body>
<div style="width:750px; height:400px; border-width: 10px; border-style: dashed; border-color: red; font-family: Arial; font-weight: normal; text-align: center; color: #ff0000;">



<?php
$target = $_GET['t202kw'];
?>

<span style="color:#ff0000; font-size:60px;font-weight: bold;">LIMITED OFFER</span><br><span style="color:#0000ff; font-size: 40px;">For<?php echo ucfirst (trim_url_to_root_domain($target)); // uppercase first letter ?> Visitors!!!</span> <br>
<span style="color:#ff0000; font-size:40px;">One Off</span> <span style="font-size: 40px; text-decoration: underline;">Special Deal</span> <span style="color: #ff0000; font-size: 40px;">For an iPad 4!</span> <br>
<IMG SRC="http://hotoffer.me/opt-ipad4.jpg" align="left" alt="ipad4" width="400" height="170"> <p><del><span style="color: #ff0000;font-size: 30px;">$599</span></del>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;<span style="color: #0000ff; font-size: 70px;">$79</span>
<form name="counter" style="margin: 0px;">
<span style="font-size: 20px;">Offer Ends In
<input value="103.2" name="d2" style="border: 0px none;
background-color: rgb(255, 255, 255); font-size: 28px; color: blue;
font-weight: bold; width: 77px; padding-top: 5px;" type="text">
Seconds
</span>
</form>
<script>

<!--

//

var milisec=0

var seconds=60

document.counter.d2.value='120'

function display(){

if (milisec<=0){

milisec=9

seconds-=1

}

if (seconds<=-1){

milisec=0

seconds+=1

}

else

milisec-=1

document.counter.d2.value=seconds+"."+milisec

setTimeout("display()",100)

}

display()

-->

</script><BR CLEAR=ALL>
<a href="http://www.mb01.com/lnk.asp?o=5205&c=918271&a=93917"><span style="text-decoration: underline; font-weight: normal; color: #0000ff; font-size: 60px; font-weight: bold;">CLICK HERE NOW</span></a>

</div>

<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
<script>window.jQuery || document.write("<script src='js/libs/jquery-1.5.1.min.js'>\x3C/script>")</script>

</body></center">
</html>
<?php
function trim_url_to_root_domain($target) {
/** Trim Url to Root Domain
* by ctrtard.com 8/1/2011
*
* This function is mainly useful for PPV. You can pass it a URL (target) and it
* will trim it down to the root domain. Unlike most other examples I've found,
* It handles subdomains and squirrely, or malformed URLs like "//something.domain.com"
* The result is a nice looking domain for dynamic keyword insertion into your
* landing pages.
*
* Usage:
* echo trim_url_to_root_domain("http://mytarget.com");
* or
* echo ucfirst (trim_url_to_root_domain("http://mytarget.com")); // uppercase first letter
*
*/
// trim http, https, and //
$target = str_replace("http:", "", $target);
$target = str_replace("https:", "", $target);
$target = str_replace("//", "", $target);

// check for dots
$dots = substr_count($target, '.');
if ($dots > 1) { // if there are more than 1 dots, we need to remove subdomain
$first_dot = strpos ($target, ".");
$target = substr($target, $first_dot+1, strlen($target));
}

// find the last slash, this should be the slash just before directory info
$first_slash = strripos($target, "/");
if ($first_slash > 0 ) {
$target = substr($target, 0, $first_slash);
}

// find last slash one more time, to handle targets like /domain.com
$last_slash = strripos($target, "/");
if ($last_slash !== FALSE ) {
$target = substr($target, 1, strlen($target));
}

// normalize target so it's all lower case
$target = strtolower($target);

return $target;
}
?>[/PHP]

Is this correct? What and where do I need to add to CPVLAB to make it work?

How do I test it, to see if it is working correctly?

Any help would be appreciated.


Home > Questions and Answers > General Questions