'Random Question' Script

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by tillabong, Apr 9, 2010.

  1. tillabong

    tillabong New Member

    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    0
    hello. i was thinking of adding the random question script to my website's registration page as found in the search function of this forum.

    however i noticed something amiss. whenever i view the source code, the random question in the source code is different from the one displayed in the browser. i have tried it on my website and it has the same problem. is it something to do with the sequence the server loads php scripts? however for my script my answer is always wrong. here is a sample of my script. i've shorten my registration form. $registrationformpart is just the front part of the registration form i have snipped off.

    *edit*im using chrome browser. somehow IE doesnt have the inconsistency in the source code*edit*

    <body>
    <?php

    $randomnumber = rand(1,4);

    $question1 = <<< QUESTION1

    <tr>
    <td class="style1" colspan="2">What letter comes after B? (For Security Purposes)</td>
    </tr>

    <tr>
    <td class="style1" colspan="2"><input type="text" name="securityquestion" maxlength="5" size="35" style="border:#B0A860 solid thin"></td>
    </tr>

    <tr><th colspan=2 align="center"><input type="submit" name="register" value="Register"></th></tr> </table>
    </form>

    QUESTION1;

    $question2 = <<< QUESTION2

    <tr>
    <td class="style1" colspan="2">What letter comes after C? (For Security Purposes)</td>
    </tr>

    <tr>
    <td class="style1" colspan="2"><input type="text" name="securityquestion" maxlength="5" size="35" style="border:#B0A860 solid thin"></td>
    </tr>

    <tr><th colspan=2 align="center"><input type="submit" name="register" value="Register"></th></tr> </table>
    </form>

    QUESTION2;

    if ($randomnumber == 1 || $randomnumber == 2)
    {$registrationform = $registrationformpart.$question1;
    $securityanswer = 'c';}

    if ($randomnumber == 3 || $randomnumber == 4)
    {$registrationform = $registrationformpart.$question2;
    $securityanswer = 'd';}

    if (isset($_POST['register']))
    {$securityquestion = strtolower(mysql_real_escape_string($_POST['securityquestion']));

    if ($securityanswer!=$securityquestion)
    {$registration = '<span class="style4">Your answer to the security question was incorrect. </span>';
    $registration = $registration.$registrationform;}
    }
    else {$registration = $registrationform;}

    echo $registration; ?>
    </body>

    thank you for your time.
     
    Last edited: Apr 9, 2010
  2. misson

    misson Community Paragon Community Support

    Messages:
    2,572
    Likes Received:
    72
    Trophy Points:
    48
    Chrome re-requests the page when you view the page source. You can use the Web Inspector to examine the structure of the rendered page you're viewing. If you need any more help than that, you need to provide a link to a live page.
     
    Last edited: Apr 9, 2010
  3. descalzo

    descalzo Grim Squeaker Community Support

    Messages:
    9,375
    Likes Received:
    327
    Trophy Points:
    83
    Apparently Google changed the code since that article, because Chrome (4.1.249) does not do that on my test script.
     
    Last edited: Apr 9, 2010
  4. misson

    misson Community Paragon Community Support

    Messages:
    2,572
    Likes Received:
    72
    Trophy Points:
    48
    There are a couple of related issues (#523 and #10570), though they aren't resolved. When you view the source of a page that was retrieved with POST, you'll get the source for the page as retrieved with a GET. If there's a cached copy of the page retrieved with GET, Chrome will use that version and won't re-request the page.

    Tillabong, what version of Chrome are you using?
     
    Last edited: Apr 9, 2010
  5. tillabong

    tillabong New Member

    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    0
    thanks for the reply. im using version 4.1.249.1045. i managed to solve the problem with the random question script though. thank you so much for your time.
     
  6. as4s1n

    as4s1n New Member

    Messages:
    174
    Likes Received:
    4
    Trophy Points:
    0

Share This Page