Una cosa del genere:
whattime.php
Codice PHP:
<?php
      
# start the session, and clear any existing values
      
session_start();
      
$_SESSION['js_count']   = 0;
?>

<HTML>
      <head>
            <title>PHP & Javascript - Example</title>
            <STYLE type='text/css'>
                  /* set Body display properties to make things pretty */
                  body, p, th, td {
                        font-family: Tahoma, Arial, Helvetica, sans-serif;
                        font-size: 11px;
                  }
            </STYLE>
            <SCRIPT type="text/javascript">    
                  function attach_file( p_script_url ) {
                        // create new script element, set its relative URL, and load it
                        script = document.createElement( 'script' );
                        script.src = p_script_url;

                        document.getElementsByTagName( 'head' )[0].appendChild( script );
                  }
            </SCRIPT>
      </head>    
      <body>

            
            [url="javascript:attach_file( 'javascript.php' )"]What time is it?[/url]
            


            <span id="dynamic_span" />
      </body>
</HTML>
javascript.php :
Codice PHP:
<?php
# set appropriate content type - to tell the browser we're returning Javascript
header'Content-Type: text/javascript' );         
# start the session
session_start();           
# determine the current time
$time  date'g:i a' );           
# determine how many times the user has called the function, then increment it
$js_count          = ( ++$_SESSION['js_count'] );           

            
# based on the count, set the appropriate display value
            
if ( $js_count == ) {
                        
$inner_html       "This is your first time asking. It is $time.";
            } else if ( 
$js_count <= ) {
                        
$inner_html       "You have asked me $js_count times now. It is $time.";
            } else {
                        
$inner_html       "You have already asked me $js_count times. Shut up!";
            } 
# END big-nasty-else-if-block
?>
// retrieve span object, and attach additional HTML to it
dynamic_span_obj          = document.getElementById( 'dynamic_span' );
dynamic_span_obj.innerHTML     += '<?php echo $inner_html?> 
';

Per dati l'idea poi lo adatti alle tue esigenze.