Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it L'avatar di Nico
    Registrato dal
    Apr 2002
    Messaggi
    458

    [session] passaggio variabile al click

    problema: al click del mouse su un link devo passare una variabile alla pagina di destinazione, ma non via URL (uso le sessioni). Come faccio a impostare la variabile di sessione ($_SESSION['variabile']= "valore") solo al click?

  2. #2

    ..........

    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.


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3
    Utente di HTML.it L'avatar di coteaz
    Registrato dal
    Mar 2006
    Messaggi
    365
    io farei una cosa molto piu semplice

    quando clicchi ajax chiama un file php che setta una settione

    facile e rapido

  4. #4
    Utente di HTML.it L'avatar di Nico
    Registrato dal
    Apr 2002
    Messaggi
    458
    @whisher: grazie per la risposta, effettivamente avevo pensato a javascript anche se credevo si potesse fare più semplice!
    @coteaz: ajax non l'ho mai usato, come sarebbe la tua soluzione in termini di codice?

  5. #5

    ............

    io farei una cosa molto piu semplice
    quando clicchi ajax chiama un file php che setta una settione
    facile e rapido
    Se lo script usa solamente questo
    tipo di cosa perchè scomodare Ajax
    quando con due righe di codice
    hai risolto il problema.

    grazie per la risposta, effettivamente avevo pensato a javascript anche se credevo si potesse fare più semplice!



    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.