Forum Moderators: coopster

Message Too Old, No Replies

How to open in target "_blank" --header("Location: ".$url."");--?

         

tito

12:34 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



Hello,

i do have this piece of code from a 'link of categories' script which redirects to the URL of sites.
I'd like to open the links to a new window, i'm trying with target=\"_blank\" but there's no way, please can you help me?

here's the code:

<?
require("conf/db.php");
$link = mysql_connect($host,$user,$password);
$requete=mysql_db_query($base,"select url from ".$basesites." where id=".$s." ",$link);
$url = mysql_result($requete,0,"url");
header("Location: ".$url."");
exit();
?>

Thanks in advance,
tito

lobo235

4:40 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



If you have this code on a page named openlink.php, for example, you would first want to open this page in a new window and then it would do the header redirect to the url from your DB query. So yo have to create the new window before you redirect because in a redirect there's no way for you to tell it to open a new window. Make Sense?

coopster

5:26 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Exactly. Could you imagine what the internet would be like if you were able to send a header request out to any (or all!) computers and have it pop a window without requesting anything from the server first? hehe, mass hysteria -- you think spam email is bad ...

tito

6:13 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



i see, in fact i was trying to place target=\"_blank\" into the code which call the openlink page by doing this:

echo "<p><a href=\"redirect.php?s=".$id."\" target=\"_blank\">".$sitenom."</a> - ".$description."</p>";

but it doesn't work, what i'm doing wrong?

Thanks for your help,
tito

coopster

6:18 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not sure but whenever I am echoing variables to HTML output I use htmlentities() [php.net].

jatar_k

6:19 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what exactly isn't working?
What does that echo output to the browser?

another thought is you could enclose the string in single quotes instead of double, meaning you wouldn't have to escape double quotes in the string, there are no vars needing to be parsed in there. Also in an echo statement you can put commas between the parts needing to be output so that php doesn't have to concatenate everything first before outputting the string

like so
echo '<p><a href="redirect.php?s=',$id,'" target="_blank">',$sitenom,'</a> - ',$description,'</p>';

tito

7:18 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



jatar_k,
i just want to open the link in a new window, but it keeps opening in the same window.

i've tried with your suggestion and still keeps opening the link in the same window.

that echo output is the only one to call the openlink page, i'm sure, and so by placing the target="_blank" in there should work, but it doesn't, why?

coopster

7:20 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you viewed the source after it has been rendered by the browser to see if anything looks funny?

jatar_k

7:20 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try _new instead see if it helps

tito

9:04 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



found it! damn.. the echo output for opening the link was placed inside the search.php file, out of contest!
now it's fine, sorry for the mess, anyway i've learned that single quotes instead of double and htmlentities(). thanks to your kind support jatar_k and coopster, this is the best place.

tito

jatar_k

9:07 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



glad you found it :)