PHP session variable not parsing but ISSET says it is running & at 0

前端 未结 1 571
南笙
南笙 2021-01-23 16:00

Ok, so I have a counter which simply counts up a second at a time.This second counter I want it to be my session variable.Is this a bad idea? Also when I do a isset on my second

1条回答
  •  终归单人心
    2021-01-23 16:25

    Haven't seen your html but you might be missing something to start and run the timer function - this might be missing:

         
    

    Also I am not quite clear how you are submitting the page but I can't see anything that passes the value of the timer to the session variable. If you put a form on your page with a submit button then you could pick up the value of a hidden input with its value being set with javascript. You could submit the page automatically using submit(); in your javascript when the counter reaches a certain number if you want that:

    page1.html (could be called page1,php but there is no php in page 1 so that is not actually necessary)

     
     
     
      Page 1
    
          
     
           
                  
    Session Time Counter: 0

    You aren't referencing $_SESSION["counter"] on page 1 and you are initialising to 0 not 100 in your JavaScript.

    In your page 2 script page2.php you would have this - you could also submit this page to itself if only a part of the content is to be changed but the timer needs to continue or be logged at the point of submission.

    
    
    
    
    Page 2
    
       
    
        
              
    " />
    Session Time Counter:

    And in your page2.php JavaScript you would need to clearInterval() and restart it. http://www.w3schools.com/jsref/met_win_clearinterval.asp

        var counter=; //initiates score to submitted value
    

    You probably won't need to use a session variable as you are using the hidden input, so you could use:

        var counter=; //initiates score 
    

    You could also add 1 to it to approximately account for the delay submitting it

        var counter = ;
        var counter=; //initiates score 
    

    You could stick with using GET but I just prefer POST.

    This has a bit more about hidden inputs: Get and echo inputs from textarea repeatedly

    and a bit more about the timer script: http://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock

    0 讨论(0)
提交回复
热议问题