Move php variable to new window

I have a page dynamically created by a database. For every thing that is built dynamically, I want to have a link that appears in a new window, and this new window fills the list from the database, based on which element on the first page was clicked. I tried the POST methods and sent the variable to the url (which, as I know, is dangerous). Another thing that makes this unique is that the link that is clicked is not really a page link, but I am doing Javascript to call a function that opens a new window and a new php page, because it would be foolish to open a whole new page for list only. How should I do it? If you need more clarification, I will do my best to make it more clear.

I am creating a table and it will have these links:

<td><a href="#" style="font-weight:normal; font-style:italic" onclick="function()">Do Stuff</a></td>

function function(){ window.open("page.php", "blank"," toolbar=no, width=400, height=350, top=50, left=50, scrollbars=yes"); }

Function () will open a new window with a new php page. The question is how to translate the php variable into a new window.

+3
source share
2 answers

simple ver

echo "<a href=\"#\" onclick=\"window.open('youPopUpPage.php?value=$value');\">link</a>";

to youPopUpPage.php file

$value=$_GET["value"]; # retrive value from calling page

open with js function

<td><a href="#" style="font-weight:normal; font-style:italic" onclick="openPage(<?php echo $value ;?>)">Do Stuff</a></td>


<script type="text/javascript">
function openPage(value){
window.open('youPopUpPage.php?value='+value);}
</script>
+5
source

Make sure you just pass in an identifier that doesn't mean anything to anyone, then do something like this with your links:

echo "<a href='/myaddress?id=".$id."'>my link</a>";

In a new window, you can get the value using:

$id = mysql_real_escape_string($_GET['id']);

Using this identifier, you can look in your database to find the content you need.

+2
source

All Articles