Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2009-03-02, 04:28 PM   #1
asianslave
Aw, Dad, you've done a lot of great things, but you're a very old man, and old people are useless
 
Join Date: Sep 2008
Posts: 28
How to swap out sponsor links the easy way! [SCRIPT]

We've all experienced the pain of having to swap out large numbers of sponsor links when a sponsor goes bust, closes a site, changes their linking codes etc. Normally this requires either painfully going through page by page and swapping out the links by hand, or using error prone methods like site wide Dreamweaver search and replace, or using utilities like sed for the unix geeks. Here's an easy way to dynamically update all your sponsor links using simple text files and php - no mysql required.


Step 1

Make a plain, tab-delimited text file with all your sponsor info. Put one paysite per line, in the format:

campaign|paysite name|paysite domain|url

You can have comment lines beginning with a hash (#)

Here's an example:

Code:
# My paysites

# Paysite 1
# Consoles
paysite1|Paysite One|paysite1.com|http://www.paysiteone.com/index.php?id=blahblah
# No Consoles
paysite1_nc|Paysite One|paysite1.com|http://www.paysiteone.com/index.php?id=blahblah&nc=yes

# Paysite 2
# Consoles
paysite2|Paysite Two|paysite2.com|http://www.paysitetwo.com/index.php?id=blahblah
# No Consoles
paysite2_nc|Paysite Two|paysite2.com|http://www.paysitetwo.com/index.php?id=blahblah&nc=yes
You have two options as to where you can upload this file. The easiest method is to put it in the root directory of your domain. You can also use one links.txt for all the domains on one server or hosting account; if you choose to do this, it might be easier to put this file outside the viewable domain tree, in a directory that is still readable by apache.

For example, my hosting account is laid out like:
/users/seanp/domains/domain1.com
/users/seanp/domains/domain2.com
/users/seanp/domains/domain3.com

I could potentially upload my links.txt to:
/users/seanp/domains/domain1.com/links.txt
or
/users/seanp/domains/links.txt

Your choice of a name for the campaign should be easy to remember and based on the paysite name. Using this system, you can easily swap out both the console and nonconsole versions of a link code (eg. consoles for hubs, no consoles for free sites) - just label your campaigns in an intuitive way.



Step 2

Upload this script in the root directory of every domain that you want to use this link inserting script. You have to edit the value of $sponsors_file to be the absolute path to your links.txt file on your server. Edit the three $default_ variables to point to a hub or something like that; these are used if there is no data found for a given paysite - you want to point your links to a hub at least rather than just having a broken link.

Code:
<?php

// asianslave's dynamic sponsor url thingie v0.1


// The absolute unix path to your links.txt file
$sponsors_file = "/users/seanp/domains/asianslaveslinks.com/links.txt";


// The default link code if a given sponsor link is not found in your links.txt file
$default_url      = 'http://www.asianslaveslinks.com/';
$default_name     = 'this site';
$default_domain   = 'this site';



/*****************************************************************************/

// Load sponsor data into some useful arrays
$lines = file($sponsors_file);


// Trim every element
$count = count($lines);
for($i = 0; $i < $count; $i++) {

	$lines[$i] = trim($lines[$i]);

	// Remove blank elements
	if($lines[$i] == '') {
		unset($lines[$i]);
	}

	// Remove comments
	if(ereg("^#", $lines[$i])) {
		unset($lines[$i]);
	}

}

// Reorder the array keys
foreach($lines as $l) {
	$lines[] = $l;
}



// Put together your data into a useable array
foreach($lines as $line) {
	$parts = explode('|', $line);
	$campaign = $parts[0];

	$links[$campaign]['name']   = $parts[1];
	$links[$campaign]['domain'] = $parts[2];
	$links[$campaign]['url']    = $parts[3];
}

/*** TESTING ***/
/*
echo '<pre>';
print_r($links);
echo '</pre>';
*/





// Functions for printing paysite info

function paysite_url($campaign) {
	global $links, $default_url;

	if($links[$campaign]['url']) {
		echo $links[$campaign]['url'];
	} else {
		echo $default_url;
	}

}



function paysite_name($campaign) {
	global $links, $default_name;

	if($links[$campaign]['name']) {
		echo $links[$campaign]['name'];
	} else {
		echo $default_name;
	}

}



function paysite_domain($campaign) {
	global $links, $default_url;

	if($links[$campaign]['domain']) {
		echo $links[$campaign]['domain'];
	} else {
		echo $default_domain;
	}

}


?>


Step 3

Now you are ready to start using dynamic sponsor urls in your pages!

In any page you want to use your dynamic urls, insert this line above your opening <html> tag:

Code:
<?php include('links.php'); ?>
Note that you MUST use a relative path pointing to links.php.

For example, if you have a domain laid out like this:

Code:
http://www.yourdomain.com/links.txt
http://www.yourdomain.com/links.php
http://www.yourdomain.com/testing.html
http://www.yourdomain.com/testing/testing.html
For http://www.yourdomain.com/testing.html:
Code:
<?php include('links.php'); ?>
<html>
<head>
...
http://www.yourdomain.com/testing/testing.html
Code:
<?php include('../links.php'); ?>
<html>
<head>
...
You can easily dynamically insert the paysite name, domain name or url into your html page using three PHP functions:

paysite_url($campaign)
paysite_name($campaign)
paysite_domain($campaign)

You would insert these into the page like this:
Code:
<?php paysite_url('paysite1'); ?>
<?php paysite_name('paysite1'); ?>
<?php paysite_domain('paysite1'); ?>
If you have been following along so far, try using this test page to see the results:
Code:
<?php include('links.php'); ?>
<html>
<head>
<title>Testing dynamic sponsor links</title>
</head>
<body>
<b>Paysite 1, consoles</b><br>
Paysite 1 name: <?php paysite_name('paysite1'); ?><br>
Paysite 1 domain: <?php paysite_domain('paysite1'); ?><br>
Paysite 1 url: <?php paysite_url('paysite1'); ?><br>
Paysite 1 linked: <a href="<?php paysite_url('paysite1'); ?>"><?php paysite_name('paysite1'); ?></a><br>
<br>
<b>Paysite 1, no consoles</b><br>
Paysite 1 name: <?php paysite_name('paysite1_nc'); ?><br>
Paysite 1 domain: <?php paysite_domain('paysite1_nc'); ?><br>
Paysite 1 url: <?php paysite_url('paysite1_nc'); ?><br>
Paysite 1 linked: <a href="<?php paysite_url('paysite1_nc'); ?>"><?php paysite_name('paysite1_nc'); ?></a><br>
<br>
<b>Paysite 2, consoles</b><br>
Paysite 2 name: <?php paysite_name('paysite2'); ?><br>
Paysite 2 domain: <?php paysite_domain('paysite2'); ?><br>
Paysite 2 url: <?php paysite_url('paysite2'); ?><br>
Paysite 2 linked: <a href="<?php paysite_url('paysite2'); ?>"><?php paysite_name('paysite2'); ?></a><br>
<br>
<b>Paysite 2, no consoles</b><br>
Paysite 2 name: <?php paysite_name('paysite2_nc'); ?><br>
Paysite 2 domain: <?php paysite_domain('paysite2_nc'); ?><br>
Paysite 2 url: <?php paysite_url('paysite2_nc'); ?><br>
Paysite 2 linked: <a href="<?php paysite_url('paysite2_nc'); ?>"><?php paysite_name('paysite2_nc'); ?></a><br>
<br>
</body>
</html>
Say, for example, paysite1.com is a niche paysite which gets canned by the sponsor and redirected to some shitty multi-site pass offer. We just change the offending line in links.txt, and all references to that paysite name, domain or url are changed throughout our domain (or every domain on that server, depending on how we have things set up).

eg. in your links.txt
Code:
paysite1|Paysite One|paysite1.com|http://www.paysiteone.com/index.php?id=blahblah
might be changed to
Code:
paysite1|New Site One|newsite1.com|http://www.newsite1.com/index.php?id=blahblah
You just leave the campaign label the same and change the rest of the data. Easy!



Misc notes:

Yes, this will work with .html files, so you can maintain the illusion that you are serving static html pages for SEs and finickly LL reviewers. You just need to add one line to your .htaccess file:

Code:
AddHandler application/x-httpd-php .htm .html
There is a tiny increase in server load from parsing html pages for PHP, but it's really no different from parsing a file with a .php extention in the same way. However, it's recommended that you make your links.txt file as short as possible - ie don't fill it up with sponsors that you don't actually use. Delete them from the file or comment them out.



I hope this helps someone alleviate the pain of swapping out sponsor links! If you find this helpful and end up using it, feel free to throw up a link to my site http://www.asianslaveslinks.com/ with the anchor text 'Free Asian Porn.' Or, hit me up via pm if you've got an asian site and you'd like to trade links!
asianslave is offline   Reply With Quote
Old 2009-03-02, 06:13 PM   #2
asianslave
Aw, Dad, you've done a lot of great things, but you're a very old man, and old people are useless
 
Join Date: Sep 2008
Posts: 28
Oops, I just realised I made a wee error in the links.php script above.

Replace this part:
Code:
// Reorder the array keys
foreach($lines as $l) {
	$lines[] = $l;
}
with this:
Code:
// Reorder the array keys
$lines_temp = $lines;
$lines      = array();
foreach($lines_temp as $l) {
	$lines[] = $l;
}
asianslave is offline   Reply With Quote
Old 2009-03-03, 12:25 AM   #3
Ramster
Life is good
 
Ramster's Avatar
 
Join Date: Apr 2003
Location: Ottawa, Canada
Posts: 11,699
Send a message via ICQ to Ramster Send a message via AIM to Ramster
I'll bookmark this page, thanks.
__________________
Pornstar Legends | Live Cam Model Shows | Hungarian Girls
Skype: robmurray999
Ramster is offline   Reply With Quote
Old 2009-03-03, 01:23 PM   #4
A.J. Angel
And Lord, we are especially thankful for nuclear power, the cleanest, safest
energy source there is. Except for solar, which is just a pipe dream
 
Join Date: Sep 2008
Posts: 229
I have a similar script set up on my sites with the following code:

Code:
<?php

$path = array(
	"amateursgonebad" => "http://www.amateursgonebad.com/",
	"glamourmodelsgonebad" => "http://www.glamourmodelsgonebad.com/"
	);

if (array_key_exists($_GET["id"], $path)) {
	header("location: " . $path[$_GET["id"]]);}
	else {header("location: http://www.greenguysboard.com/");}

?>
The code is saved in a PHP file and all you need to do is link to the PHP file in question and use a request to call the correct URL:

Example, if the file name is "links.php" and you want to link to the paysite Glamour Models Gone Bad, the URL you would use will be the following:

Code:
http://www.pathtofile.com/links.php?id=glamourmodelsgonebad
If you happen to name the file "index.php", you don't need to write out "index.php". You could just add the request like the following:

Code:
http://www.pathtofile.com/links/?id=glamourmodelsgonebad
The header location code will redirect the surfer if he tries to access the file to whatever URL you put there.
A.J. Angel is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:52 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc