I want to trigger javascript alert using PHP. Is it possible
I want to use it in head section, for displaying it at load time.
Of course this is possible.
All you are doing is outputting JavaScript, it's all the same thing.
The only issue is that you are nesting <script>
tags, which is an HTML error, so get rid of the tags in the echo
string.
<script type="text/javascript">
<?php
$valid="valid";
if(!isset($valid))
echo "alert('Hi');";
?>
</script>
By the way, as i'm sure you already know, this specific code will ALWAYS echo the "alert('Hi');"