PHP? Javascript? Or both?

Discussion in 'PHP' started by ktsirig, Apr 28, 2006.

  1. #1
    Hi all!
    I have a php page which contains a form. The user enters data and then the data is processed to give some results. What I would like to have is a page inbetween, that says, for instance, "Your job is being processed" or something similar, and then, when the job is done, refresh itself to show the results. I have seen it in many websites, but I don't know what I need to get me started...
     
    ktsirig, Apr 28, 2006 IP
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could use a meta refresh tag... <meta http-equiv="refresh" content="5;url=http://thesite.com"> Drop that inbetween your <head> tags, and it's forward you after 5 seconds.
     
    exam, Apr 28, 2006 IP
  3. ontheweb

    ontheweb Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Exam's example is definitely the best way to do it. If you did it with Javascript you run the risk of your visitor being 'stuck' if they don't have Javascript turned on.. :)
     
    ontheweb, Apr 30, 2006 IP
  4. ktsirig

    ktsirig Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi guys, thank you for your time... I think that your idea is good, but what I need is somehow to check when the external program has ended and then redirect the user. In the way you suggested, I think that you just redirect in x seconds, but what if the program hasn't done the processing? It might take for example 1 minute or 2 or 20 seconds.. How will I know?
    PS: The external program writes the results to a temporary file that is being created and I read the results from it and print them to the user.
     
    ktsirig, May 1, 2006 IP
  5. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #5
    Ajax may be worth a try but it all comes down to you need something in place in case a user does not have javascript enabled
     
    Danny, May 1, 2006 IP
  6. arnek

    arnek Active Member

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    what you can also do is used the ob_start(i think) and ob_flush() methods, then when everything is finished, send through a piece of javascript that refreshes the page.

    
    
    echo "Loading";
    flush();
    ob_start();  // turn output buffering on, while output buffering is active, nothing is sent to browser
    // do your processing
    
    echo "<script language='javascript'>document.location='new_url';</script>
    // to output everything in the buffer, use ob_end_flush();
    
    ob_end_flush(); // sned the javascirpt to refresh the page
    
    PHP:
    (don't mind syntax, just for quick illustration)
     
    arnek, May 1, 2006 IP