Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
Like Tree2Likes
  • 1 Post By TheGAME1264
  • 1 Post By Webzarus

Thread: pausing and unpausing a script

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    24
    Member #
    36599
    Liked
    1 times

    Question pausing and unpausing a script

    Hello. I have perhaps an odd question.

    Is it possible in a single php script to run part of the script (say push some HTML to the browser) then pause the script, wait for the user to click something on the page, then un-pause the script, push some more HTML, then pause the script again, wait for the user to click something else on the page, then un-pause the script and continue executing.

    Right now, I can approximate this behavior by splitting the script across several different php files. This works fine except now I need to access some of the variables from the previous scripts. So with the code split across files, the problem boils down to gaining access to the previously set variables. I'm starting to read about using sessions but I am not sure sessions will work for me because the data that I need stored and available to the next page isn't calculated until after lots of HTML has already been sent to the browser.

    So that's why I started thinking about trying to pause / un-pause one script so I could work with global variables in the script.

    Hopefully my question is reasonably clear.

  2.  

  3. #2
    Junior Member
    Join Date
    Jun 2013
    Posts
    24
    Member #
    36599
    Liked
    1 times
    Here's another question.....

    Does anyone use the MySQL database to store the state of their variables from the first page and run a query on the second php page to get the variable data back and continue processing.

  4. #3
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    You could just use hidden form fields on the various PHP pages to pass the data.

    I'm not a PHP expert by any stretch of the imagination, but I don't think the scenario you've laid out is possible.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  5. #4
    Junior Member
    Join Date
    Jun 2013
    Posts
    24
    Member #
    36599
    Liked
    1 times
    The more I read about using sessions, the more it seems like sessions is what I should use.

  6. #5
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Sessions can be erased easily. Form input is a bit more difficult.

    Let's take a very simple example, and I haven't actually tested this example and my PHP isn't the greatest, so clean it up to suit your purposes. Add your sanitation and validation as well.

    Here's your first page.
    Code:
    <form action="page2.php" method="post">
    <input type="text" name="First_Name" value="" size="20" maxlength="255" />
    <input type="submit" value="Go to Page 2" />
    </form>
    Your second page would look something like this:
    Code:
    <form action="page3.php" method="post">
    <input type="hidden" name="First_Name" value="<?php echo $_POST['First_Name']; ?>" />
    <input type="text" name="Last_Name" value="" size="20" maxlength="255" />
    <input type="submit" value="Go to Page 3" />
    </form>
    The other option you have if this is a multi-part form, and I quite often do this depending on circumstance, is to create a database table and store the data in it as I go, with a unique identifier to retrieve and update the data as needed. But that depends on how many parts there are to the form and if the first part is important enough to use database space for.
    AlphaMare likes this.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  7. #6
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    A combo of AJAX... And PHP session variables is what you're looking for... But if really complex... I've used a DB to store things for a "logged in" user...

    Im seeing more and more online shopping carts that us a simpl cookie/session variable/ user login scenario to store and save cart contents for months... If you log out... The next time you visit... The cookie initiates an AJAX... Connection to pull the cart info... If you delete your cookies... The next time you login... A copy of the cookie is then re-set... And the data is pulled once again...

    what you're asking for is not impossible... But you really need to determine the importance of the data... And what to write to cookies... What to write to the DB... And how you can leverage session variables and the above to create the right balance.

  8. #7
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    How much information are you talking about? And is the person logged-in, or an anonymous visitor?



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:34 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com