+ Reply to Thread
Results 1 to 6 of 6

Thread: 'Random Question' Script

  1. #1
    tillabong is offline x10Hosting Member tillabong is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    60

    'Random Question' Script

    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 by tillabong; 04-09-2010 at 11:45 AM. Reason: add on

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: 'Random Question' Script

    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 by misson; 04-09-2010 at 06:14 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: 'Random Question' Script

    Quote Originally Posted by misson View Post
    Chrome re-requests the page when you view the page source.
    Apparently Google changed the code since that article, because Chrome (4.1.249) does not do that on my test script.
    Last edited by descalzo; 04-09-2010 at 05:16 PM.
    Nothing is always absolutely so.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: 'Random Question' Script

    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 by misson; 04-09-2010 at 07:35 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    tillabong is offline x10Hosting Member tillabong is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    60

    Re: 'Random Question' Script

    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. #6
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    Re: 'Random Question' Script

    Why not just use Captcha?
    There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.

+ Reply to Thread

Similar Threads

  1. "Random Question"
    By kevin1gamer in forum Free Hosting
    Replies: 3
    Last Post: 02-22-2010, 06:32 AM
  2. What's the random question for?
    By idontkno in forum Off Topic
    Replies: 12
    Last Post: 05-25-2009, 01:43 AM
  3. Random Chess Question
    By Shadow121 in forum Off Topic
    Replies: 9
    Last Post: 05-20-2007, 05:08 PM
  4. Just a question about my script
    By rubens in forum Free Hosting
    Replies: 11
    Last Post: 02-28-2006, 01:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers