open new window php

5

On the site I have several banner ads. When I click on a banner, I'm redirected to a page that counts clicks on the banner. After this count I'm redirected to the page before the click on the banner and a new tab with the banner link opens. For this I have the following:

// $go_to_url é o link do banner
echo "<script>window.open('".$go_to_url."', '_blank');</script>";

// redirecciona para a página anterior ao clique no banner
$last_url = $_SERVER['HTTP_REFERER'];
echo "<script>window.location.replace('".$last_url."');</script>";

So far so good, but there is a problem that can happen, the browser asks permission to open pop-up windows, and in this case the client does not have time to accept because it is soon redirected to the previous page. Is there any way around this problem? For example when using the header () function of php, but this function does not allow to open another tab.

    
asked by anonymous 11.08.2014 / 12:30

2 answers

7

Good morning, I suggest that the new page be opened in another window and your page be in the browser. You can do this: assuming your page is index.php

on your page:

<a href="index.php?redir_to=<?php echo $go_to_url; ?> target="_blank">">Banner</a>

in php do the following

<?php
    $redir_to = $_GET['redir_to'];
    //GRAVAR O CONTADOR PARA $redir_to EM BD OU txt conforme seu caso

    header("Location: $redir_to");
?>
    
11.08.2014 / 13:37
3

Another alternative would be to do click accounting for ajax:

HTML:

<a href="<?php echo $go_to_url; ?>" class="anuncio" target="_blank">Anúncio</a>

jquery:

$('.anuncio').click(function() {
    $.get('contabiliza.php', { url: $(this).attr('href') });
});

PHP: post.php

<?php
if (isset($_GET['url'])) {
// proceder com a contabilidade.
}
?>

The advantage of this method is that the link is completely transparent.

    
11.08.2014 / 15:37