Jump to content

scootstah

Staff Alumni
  • Posts

    3,858
  • Joined

  • Last visited

  • Days Won

    29

Posts posted by scootstah

  1. The answer is - it depends. A better approach is to identify these errors and code for them. But, from a practical standpoint, yes you can create a script that will restart if errors are encountered. But, you have to be careful about a possible error that may not be transient (i.e. an error that does not go away). If that happens you would be caught in an infinite loop which could have serious consequences on the rest of your application with regard to performance.

     

    For the sake of argument, you could create a while loop that contains the process you need run. Have the loop continue as long as the process does not complete and include a time-limit to prevent infinite loops.

     

    Just be sure you do extensive testing before actually implementing anything.

     

    Here is an example

    $complete = false;
    $timeLimit = time() + 120; //2 minutes
    while(!$complete && time()<$timeLimit)
    {
        //As you run each process that can generate an error,
        // suppress error messages but check for the errors
        $contents = @file_get_content('[url=http://somedomain.com/somedatafile.txt%27%29;]http://somedomain.com/somedatafile.txt');[/url]
        //If result was false restart at condition
        if(!$contents) { continue; }
    
        //If script completes w/o errors set $complete to true
        if(!$errors) { $complete = true; }
    }

     

    PHP has a default max_execution_time of 30 seconds, so this would terminate before that time limit is even reached.

  2. Not really.  What I am talking about is on your index.php page, you would have code such as:

    <?php
    define('CURRENT_PAGE', 'home');
    //...
    

     

    Then in your file where you need to test if your on the home page or not, use

    <?php
    if (defined('CURRENT_PAGE') && CURRENT_PAGE=='home'){
    // on home page
    }
    else {
      //not on home page
    }
    

     

    Nah, that seems too manual and too crude to me.

     

     

    Debbie

     

    Too manual? Well generally configuration options are...

     

    This is the best way to make sure your URL's are correct. Things may vary in server configurations and such, and if you need to dynamically create URL's for example then you have a way to control them.

  3. I added it, but I made a typo - so here it is:

     if ($userGuess<$randNum) {
                echo "<center>You guessed too low!</center>";
                $_SESSION['guesses']++;
            }
        if ($userGuess>$randNum) {
                echo "<center>You guessed too high!</center>";
                $_SESSION['guesses']++;
            }
        if ($userGuess==$randNum) {
                echo "<center>Congratulations You're right!!!</center>";
                             unset($_SESSION["randNum"], $_SESSION['guesses']);
        }

     

    Note the "$_SESSION['guesses']++" lines. Every time they make a wrong guess, the guesses is increment.

  4. Try this:

     

    game.php

    <?php
    session_start();
    
    $_SESSION['randNum'] = isset($_SESSION['randNum']) ? $_SESSION['randNum'] : rand(1, 100);
    $_SESSION['guesses'] = isset($_SESSION['guesses']) ? $_SESSION['guesses'] : 0;
    
    ?>
    
    <html>
    <body>
    <center><form action="game_check.php" method="POST">
    Guess a number 1-100:<input type="text" name="userGuess"/>
    <input type="submit" value="Guess"/>
    
    </form></center>
    <center><form action="game.php">
    <input type="submit" value="Restart"/>
    </form></center>
    </body>
    </html>

    game_check.php

    <?php
    session_start();
    
    $randNum = $_SESSION['randNum'];
    $userGuess=$_POST["userGuess"];
    
    if (isset($randNum)) {
        if ($userGuess<$randNum) {
                echo "<center>You guessed too low!</center>";
                $_SESSION['randNum']++;
            }
        if ($userGuess>$randNum) {
                echo "<center>You guessed too high!</center>";
                $_SESSION['randNum']++;
            }
        if ($userGuess==$randNum) {
                echo "<center>Congratulations You're right!!!</center>";
                             unset($_SESSION["randNum"], $_SESSION['guesses']);
        }
    }
    else {
        echo "Uh oh";
    }
    
    
    ?>

  5. About frameworks, what would happen if I started using one and it died ? (Discontinued...)

     

    That is pretty unlikely to happen if you use one of the more popular ones (IE: CodeIgniter, Kohana, Symfony, CakePHP, Zend, etc).

  6. I believe the GROUP BY function is what you are looking for.

     

    SELECT * FROM SELECT * FROM uitems WHERE username='$showusername' AND location='2' GROUP BY name

     

    Also, you shouldn't use mysql_fetch_array() unless you for some reason specifically require what it does. mysql_fetch_array() returns both an associative array and a numerical array, so your array holds the contents twice - and this is entirely unnecessary. You should either use mysql_fetch_row() (if you want a numerical array) or mysql_fetch_assoc() (if you want an associative array - which in your example, you do).

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.