vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   opening new window after click on banner (https://vborg.vbsupport.ru/showthread.php?t=287395)

Stefan118 09-02-2012 08:47 PM

opening new window after click on banner
 
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 Code:

<?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:

Code:

<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:

Code:

<?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!


All times are GMT. The time now is 05:05 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01023 seconds
  • Memory Usage 1,724KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete