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".

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.