PDA

View Full Version : opening new window after click on banner


Stefan118
09-02-2012, 08:47 PM
I would like to have a counter that writes in a file how often a banner is clicked.
The script below works, but how do I add to this that once the banner is clicked this link in a (new) window opens up?
I've tried everything, but nothing seems to work.

I tried also to put ANOTHER a href with the link that needs to open in the new window after the existing a href.
Then the link works, but the counter doesn't anymore!

Please help???

<?php
if(!file_exists('counter.txt')){
file_put_contents('counter.txt', '0');
}
if($_GET['click'] == 'yes'){
file_put_contents('counter.txt', ((int) file_get_contents('counter.txt')) + 1);
header('Location: ' . $_SERVER['SCRIPT_NAME']);
die;
}
?>

<head>
<title>counter example</title>
</head>

<body>
<a href="?click=yes"><img src="banner.jpg">
</a>
</body>
</html>

John Lester
09-02-2012, 08:51 PM
have you tried putting target="_blank" after yes" ?

Stefan118
09-02-2012, 08:57 PM
Yes, i tried that also...
There will be a new window opened, however... Firefox than says that the page is not redirected correctly, and the counter increases with 21 !!!

I just dont see how to go to another page when the ?click = yes.

Edit:
When using the target="_blank", the new window is called: http://www.mydomain/test.php?click=yes

Edit 2:
Lets say for test that the new page has to be google.com. <a href="http://www.google.com">

kh99
09-02-2012, 09:10 PM
I find that John's suggestion works, like this:

<a href="?click=yes" target="_blank">


but it just creates a new tab in FF each time (I think there is a way to specify that the new window be a smaller popup, if that's what you want).

Edit: so you want a different site to open in a new window? This seems to work for me:

<?php
if(!file_exists('counter.txt')){
file_put_contents('counter.txt', '0');
}
if($_GET['click'] == 'yes'){
file_put_contents('counter.txt', ((int) file_get_contents('counter.txt')) + 1);
header('Location: http://www.google.com');
die;
}
?>

<head>
<title>counter example</title>
</head>

<body>
<a href="?click=yes" target="_blank">Click</a>
</body>
</html>

Stefan118
09-02-2012, 09:32 PM
YES!!!!!!
Thanks Kh99

What i tried was:
header('Location: ' . $_SERVER['http://www.google.com']);

It was in the right direction, but that didn't work!