Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Management > Scripts and Software
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-03-2008, 07:11 PM
Junior Member
 
Join Date: Jan 2008
Posts: 6
Default outgoing link with a advertisement in it

Hi,

I'm looking for a script that automatically ads a banner (frame) on every outgoing link on my website.

(such as you guys seem to use : http://www.developertutorials.com/dt...p?id=7684&vt=0)

However the banner should be easy replaceble or even a banner rotation (?) and there should be a feature in which i can list sites which should not have a banner frame on their links added.

Anyone know where i can find or buy it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-03-2008, 07:42 PM
Junior Member
 
Join Date: Jan 2008
Posts: 6
Default

something like this but then automaticaly added to each outgoing link
http://www.programmershelp.co.uk/showproducts.php?e=2
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-03-2008, 07:50 PM
BigAlReturns's Avatar
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 291
Send a message via MSN to BigAlReturns
Default

I'm not involved in the DT website programming, just the forum, so I can't tell you how its done here, but I can offer you some ideas.
It depends what language you're using for your backend, and how it functions, but it is probably a job for regex. There may be other ways, but using PHP as backend, and assuming your page content is all stored in a string prior to being printed (this is the best way of doing it anyway), you can use preg_replace on the page string.
The idea of this is to convert every <a href="http://www.xyz.com"> into <a href="http://www.yoursite.com/framescript.php?url=http://www.xyz.com">. framescript.php is a page that simply has two frames, one specified by you If we can accomplish this, then we can easily go back and use another preg_replace to revert excluded URLs back to there non-framed form.
preg_replace takes the basic form shown below:

preg_replace ( mixed $pattern , mixed $replacement , mixed $subject )

Where $pattern is a regular expression, specifying where to do replacements, $replacement is what the matched patterns should be replaced with, and subject is the string/array that the replacement is to be performed upon.
I'm a little out of practice with regex, but the pattern you want to match would be something like:

href="(http://(www\.)?[a-zA-Z0-9\-]{2,64}\.((com)|(net)|(org)))

It looks complex, and is slightly, but if you do a bit of reading up on regex it should come clear. Basically it matches the part of the anchor tag up to the closing quote marks ".
The second part, $replacement, says what we should replace it with. We can use the notation $1 to represent the contents found in the first set of brackets of $pattern, $2 for the second set of brackets etc. The order of bracket numbers is in order of appearance of the opening bracket. Our $replacement would look something like:
href="http://www.mysite.com/framescript.php?url=$1
If we feed in our page string to $subject, then this should perform the replacement for us.
Now we need to deal with the exclusions you want. $pattern can not only be a pattern string, as above, but also an array of patterns. We'll take advantage of this by making an array of excluded websites:
$prefix="href=\"http://www.mysite.com/framescript.php?url=((www\.)?";
$suffix=")"
$exclude[0]=$prefix . "excludedsite1.com" . $suffix;
$exclude[1]=$prefix . "excludedsite2.net" . $suffix;
Then using preg replace to replace matched pattern with the contents of the first brackets. This finds instances of excluded sites being redirected to the frame page, and sets them back to regular links.
Now this is totally untested, and off the top of my (rusty) head, so don't expect to copy paste and use! Hopefully though it gives an insight into regex, and how you can use it to solve your problem. It's a slightly tricky subject, but there are many many good tutorials out there, so try reading round a few. I found the best way to learn was to set myself some challenges, and complete them with reference handy, then try similar challenges with no reference. Good luck, it's not a simple task you've set yourself here!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-03-2008, 07:51 PM
BigAlReturns's Avatar
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 291
Send a message via MSN to BigAlReturns
Default

If you want any more explanations, or some info on how to do the framing page in PHP then just ask!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-03-2008, 08:23 PM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 708
Default

Thanks BigAl. That's well beyond my meagre programming skills, but it is useful to know the basics behind how to do that sort of thing as I had no idea even where to start when I saw javaneeded's post pop up.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-04-2008, 08:40 AM
Junior Member
 
Join Date: Jan 2008
Posts: 6
Default

Thx a bunch guys, now before i read the post i started a javascript :

wfb.js
Quote:
function wfbframe(title)
{
var anchorTags = document.getElementsByTagName("a");
var returnLink = window.location;

for(var i=0; i < anchorTags.length; i++)
{
var anchorTag = anchorTags[i];

if(anchorTags[i].id != 'adworldnoframe')
{
anchorTag.href = 'linkout/o.php?out=' +
anchorTag.href ;
}

}
}
and then added this lines in my website :
Quote:
<script src="http://mysite.com/linkout/wfb.js"></script>
<script language="javascript">wfbframe('Click to Return');
</script>
The result was that all link on my page where added the prefix . => linkout/o.php?out=

To be able to split it in 2 frames with an advertisement i did with a free php i found on your guys site : cjlinkoutv1

Now everthing is working like it should.

The only detail i dont yet have is to exclude certain domains from getting a prefix.

I would try out BigAlReturns suggestion, bt im afraid that im to noobish to be able to get it working

So i was hoping someone could help me with adjusting the javascript file in adding a test to see if the domain it wants to add a prefix to is not in the exclude domain list.
I tried some things about but it didnt work.

Anyhow thx for the help guys!

Last edited by javaneeded : 01-04-2008 at 09:07 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-04-2008, 05:56 PM
BigAlReturns's Avatar
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 291
Send a message via MSN to BigAlReturns
Default

Seems like a good solution you've got started - it could be bypassed by users with JS turned off, or those who use an extension like Greasemonkey, but in the vast majority of cases it'll work just fine.
As to developing it to have certain exclusions, I'd take a similar approach to the one in my example, i.e. create an array of exclusions, and test if the URL matches any of these before performing the replacement. The problem you have is that you can't use a simple does a.href==excludedURL, because the href is likely to contain a specific page, whereas you want to be able to exclude sites by the domain, not by the page. The best solution to this is to use regex - I couldn't tell you how to use regex in JS, but if you know/find out, then I could certainly write the matching pattern for you, which is the trickiest bit anyway.
So basically,
Code:
			 				function wfbframe(title)
{
    var anchorTags = document.getElementsByTagName("a");
    var returnLink = window.location;

    for(var i=0; i < anchorTags.length; i++)
    {
        var anchorTag = anchorTags[i];

        if(anchorTags[i].id != 'adworldnoframe')
        {
if (!regexmatch excludedarray versus anchorTag.href) {  // this is where you need to find out the JS regex functions!!
            anchorTag.href = 'linkout/o.php?out=' +
                anchorTag.href ;
}
        }

    }
}
Hope that helps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-04-2008, 06:43 PM
Junior Member
 
Join Date: Jan 2008
Posts: 6
Default

Thx, i looked somestuff up but im totally not familiar with regex (even javascript is totally odd for me and comes down to testing untill it works , i only had some basic pascal ages ago )

Altho i totally get what you are trying to do, and would be great if it worked i rather would take the simple road. I only which to exclude 1 to 3 links i have on my site which turn up odd with the frame. Exact links like in http://www.google.com/maps ; how can i add for instance that url to be excluded?



something offtopic : i used the script for 12 hours on my site and lot of my sponsers stats said that 30% is now traffic without cookies; does this script or the php framing affect cookies? (would be odd tho)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-04-2008, 07:19 PM
BigAlReturns's Avatar
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 291
Send a message via MSN to BigAlReturns
Default

If it's just a simple exclusion like that, I would do it like this:
Code:
							 function wfbframe(title)
{
    var anchorTags = document.getElementsByTagName("a");
    var returnLink = window.location;

    for(var i=0; i < anchorTags.length; i++)
    {
        var anchorTag = anchorTags[i];

        if(anchorTags[i].id != 'adworldnoframe')
        {
if (anchorTag.href!='http://www.google.com/maps' AND anchorTag.href!='another URL') {  // add more URLs here in the same way
            anchorTag.href = 'linkout/o.php?out=' +
                anchorTag.href ;
}
        }

    }
}
As for the cookies issue, I think this is related to how cookies are stored on a users computer. They're associated with the URL from which they are set, and while this probably should be (standards-wise) the URL of the framed page (the site which you're linking to), some browsers might associate it with the URL of your framescript page. This means that when users return to the linked-to site, there is no cookie associated with that URL, obviously a major problem if you're using affiliate programs.
Unfortunately, while I can explain it, I don't see any way of dealing with it, as it's an issue with browsers rather than with your code. A possible solution might be to detect on your framescript page what browser is being used, and only show frames if its a browser that "works", otherwise redirect to the URL itself, without frames. This can be done pretty simply, but you'd have to do some testing to find out which browsers worked with the cookies, and which didn't.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-04-2008, 08:01 PM
Junior Member
 
Join Date: Jan 2008
Posts: 6
Default

Ok thx,
it does exclude one site when filling in the first site and removind the 'AND' .

But as soon i add the the next site and the AND in the format you gave the script stops working appearently since no link on the site get formated.

Te cookies wont form a real problem if i exclude a few domains
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Link Exchange linkmore Search Engine Optimization 4 Today 01:48 AM
sometimes a link wont work.. why? cvsouth HTML/CSS 5 01-19-2008 09:39 PM
Link Exchanges Norton Search Engine Optimization 4 12-08-2007 07:44 PM


All times are GMT -5. The time now is 11:20 PM.


Website Design by Ducani Media Group
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.