What are the potential pitfalls of embedding a PHP script on external websites using <script> tags?

Embedding a PHP script on external websites using <script> tags can expose sensitive information, such as database credentials, to the public. To prevent this, you should ensure that the PHP script is not directly accessible by users and that any sensitive information is properly secured. Additionally, consider using APIs or other secure methods to interact with the PHP script instead of embedding it directly.

&lt;?php
// Ensure the PHP script is not directly accessible
if (!defined(&#039;MY_APP&#039;)) {
    die(&#039;Direct script access not allowed&#039;);
}

// Secure sensitive information
$db_host = &#039;localhost&#039;;
$db_user = &#039;username&#039;;
$db_pass = &#039;password&#039;;
$db_name = &#039;database_name&#039;;
// Connect to database
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
// Rest of the PHP script
?&gt;