|
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
2009-03-02, 04:28 PM | #1 |
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 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'); ?> 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 Code:
<?php include('links.php'); ?> <html> <head> ... Code:
<?php include('../links.php'); ?> <html> <head> ... 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'); ?> 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> eg. in your links.txt Code:
paysite1|Paysite One|paysite1.com|http://www.paysiteone.com/index.php?id=blahblah Code:
paysite1|New Site One|newsite1.com|http://www.newsite1.com/index.php?id=blahblah 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 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! |
2009-03-02, 06:13 PM | #2 |
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; } Code:
// Reorder the array keys $lines_temp = $lines; $lines = array(); foreach($lines_temp as $l) { $lines[] = $l; } |
2009-03-03, 12:25 AM | #3 |
Life is good
|
I'll bookmark this page, thanks.
|
2009-03-03, 01:23 PM | #4 |
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/");} ?> 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 Code:
http://www.pathtofile.com/links/?id=glamourmodelsgonebad |
|
|