Fluoresce Posted April 11, 2009 Share Posted April 11, 2009 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". Quote Link to comment Share on other sites More sharing options...
Fluoresce Posted April 11, 2009 Author Share Posted April 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 11, 2009 Share Posted April 11, 2009 PHP can't affect browser's behaviour. You could echo some javascript, that creates a new window. Quote Link to comment Share on other sites More sharing options...
scarhand Posted April 11, 2009 Share Posted April 11, 2009 You can not open a new window using PHP. You need to use Javascript. Quote Link to comment Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 11, 2009 Share Posted April 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
Fluoresce Posted April 12, 2009 Author Share Posted April 12, 2009 Thanks for the replies, guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.