Jump to content

[SOLVED] Can You Open a New Window with a PHP Redirect?


Fluoresce

Recommended Posts

On my Web site, all of the links to external sites look like this:

 

visit.php?id=11

 

When someone clicks a link, they are sent to visit.php, which:

 

  • counts the click by updating my database
  • selects the URL of the site
  • redirects the visitor to the site

 

Here's what the code on visit.php looks like:

 

<?php
$conn = mysql_connect('localhost','', '') or trigger_error("SQL", E_USER_ERROR);
mysql_select_db('', $conn) or trigger_error("SQL", E_USER_ERROR);
$id = intval($_GET['id']);
mysql_query("UPDATE linktable SET linkcount = linkcount+1 WHERE id=$id"); 
$href = "SELECT url FROM linktable WHERE id=$id";
$qry = mysql_query($href);
list($href) = mysql_fetch_row($qry);
eval("\$href = \"$href\";");
header("Location:$href");
mysql_close($conn);
?>

 

Note that the external links have a tracking variable attached, hence the use of eval(). The links look like this:

 

http://www.example.com/?tracking=$var

 

Here's my problem.

 

I want a new window to open when the visitor is redirected. I know that this is considered bad practice, but it's absolutely necessary in this instance. I have to figure out a way.

 

Anyone know how I can do this? I can't seem to incorporate target="_blank".

On my Web site, all of the links to external sites look like this:

 

visit.php?id=11

 

When someone clicks a link, they are sent to visit.php, which:

 

  • counts the click by updating my database
  • selects the URL of the site
  • redirects the visitor to the site

 

Here's what the code on visit.php looks like:

 

<?php
$conn = mysql_connect('localhost','', '') or trigger_error("SQL", E_USER_ERROR);
mysql_select_db('', $conn) or trigger_error("SQL", E_USER_ERROR);
$id = intval($_GET['id']);
mysql_query("UPDATE linktable SET linkcount = linkcount+1 WHERE id=$id"); 
$href = "SELECT url FROM linktable WHERE id=$id";
$qry = mysql_query($href);
list($href) = mysql_fetch_row($qry);
eval("\$href = \"$href\";");
header("Location:$href");
mysql_close($conn);
?>

 

Note that the external links have a tracking variable attached, hence the use of eval(). The links look like this:

 

http://www.example.com/?tracking=$var

 

Here's my problem.

 

I want a new window to open when the visitor is redirected. I know that this is considered bad practice, but it's absolutely necessary in this instance. I have to figure out a way of doing it.

 

Anyone know how I can do this? I can't seem to incorporate target="_blank".

 

Oops! This post was a mistake.

Open the link in a new window/tab before redirecting....

 

<a href="http://www.somesite.com/visit.php?id=11" target="_blank">sometext</a>

 

New window is a bad pratice, don't throw some javascript at it to make it worst.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.