How can the window.open function be effectively used in PHP to display user-specific data in a popup window?

To display user-specific data in a popup window using the window.open function in PHP, you can pass the user-specific data as a query parameter in the URL that opens the popup window. This data can be retrieved on the popup window using JavaScript and displayed accordingly.

<?php
// User-specific data
$user_id = 123;
$user_name = "John Doe";

// Generate URL with user-specific data as query parameters
$url = "popup.php?user_id=$user_id&user_name=$user_name";

// JavaScript to open popup window with user-specific data
echo "<script>";
echo "window.open('$url', 'User Data', 'width=400,height=400');";
echo "</script>";
?>