SitePoint Sponsor

User Tag List

Page 5 of 9 FirstFirst 123456789 LastLast
Results 101 to 125 of 219

Thread: PHP Quiz

  1. #101
    SitePoint Addict sojomy's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by seanf
    Don't forget we haven't had a question from sojomy yet
    I'm so sorry, I totally forgot. I was kind of taking a break from the computer (I know, blasphemous, isn't it?) because the Dallas Cup is going on. I should be back to my regular daily addiction after next weekend.

    Anyway, I really can't think of a "trivial" question, so how bout something like this :

    Say i'm using a multi-purpose form. Meaning, if it were a user sign-up script, the same file would not only show the form, but would also submit to itself, and accept the data and process it (as well as redisplaying the form in the case of errors). Now, without using a header or other redirect to another page (like a "thank you", or "success" page), how could you use this same script (one file only) to keep the form from being processed if the user hits refresh?

    Now I know that there is probably more than one way to do this, but I could only think of one, so let's here what others say about it. BTW, the way I use (or am about to use) keeps any form from being reprocessed (ie, duplicate data being entered into a database) when the user presses the refresh button (like all users do).

  2. #102
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sojomy
    I'm so sorry, I totally forgot. I was kind of taking a break from the computer (I know, blasphemous, isn't it?) because the Dallas Cup is going on. I should be back to my regular daily addiction after next weekend.

    Anyway, I really can't think of a "trivial" question, so how bout something like this :

    Say i'm using a multi-purpose form. Meaning, if it were a user sign-up script, the same file would not only show the form, but would also submit to itself, and accept the data and process it (as well as redisplaying the form in the case of errors). Now, without using a header or other redirect to another page (like a "thank you", or "success" page), how could you use this same script (one file only) to keep the form from being processed if the user hits refresh?

    Now I know that there is probably more than one way to do this, but I could only think of one, so let's here what others say about it. BTW, the way I use (or am about to use) keeps any form from being reprocessed (ie, duplicate data being entered into a database) when the user presses the refresh button (like all users do).

    Well, i guess using a session variable which you set to the appropriate status would do the trick. For example, you could set it to "notPosted", whenever an error occurs, and you only set it to posted once you've inserted the input into your DB. Once placed into the database you could set another session variable which holds the time when the entriy was inserted. How to move on from here should be fairly obvious

  3. #103
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wouldn't it be best to set session variables equal to the value of the form fields and test against the posted values - thus allowing people to change one input slightly (eg if their email addr doessn't validate through a typo) and submit again without being blocked/ having to open a new browser session?

    one mo and I'll try some code.
    teckis - that's news to me.

  4. #104
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pootergeist
    wouldn't it be best to set session variables equal to the value of the form fields and test against the posted values - thus allowing people to change one input slightly (eg if their email addr doessn't validate through a typo) and submit again without being blocked/ having to open a new browser session?

    one mo and I'll try some code.
    You misunderstood.....people can edit there post when errors occur as much as they want, because the session variable will only be set to POSTED when the form has actually been posted, otherwise it will be set to notPosted, which means they can edit the form etc....

  5. #105
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so my guess is that datune got it, right?
    Aaron Brazell
    Technosailor



  6. #106
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sketch
    Ok, so my guess is that datune got it, right?
    I would say so.
    datune, give us a question!
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  7. #107
    SitePoint Addict sojomy's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sketch
    Ok, so my guess is that datune got it, right?
    Yes, that's what I use.

    I just use one session variable called $_SESSION['FormProcessed']. When the page first loads, I check to see if $_POST['Action'] is set, and if it is, is it set to "AddUser" or "SendMessage" or whatever I set the hidden action field to in the form. If the $_POST['Action'] isn't set, or isn't set to whatever I tell it to look for, I set $_SESSION['FormProcessed'] to 0 (Zero). I then display the form for the user to fill out, with the HIDDEN field named Action that has the value of whatever I want, like "AddUser" or "SendMessage"

    If the $_POST['Action'] Variable is set to what I am looking for, then I know that the form was submitted. The first thing I do is check to see if $_SESSION['FormProcessed'] is 1 or 0. If it is a 1, then I know that the form has been processed, so I skip the form processing, if it is 0, then I continue with the form processing. First in the processing is to check all of the submitted data. If it fails any of the error checks, I redisplay the form with the user data, along with the appropriate error message. If it passes all of the error checks, I process the data (send the message, add a user to the database, or do whatever), and then I set the $_SESSION['FormProcessed'] variable to 1 (One), so that I won't do the form processing again, even if the user presses refresh. If there were no errors, then I continue, otherwise, I display an error message and halt. Then, if I get this far, whether I did processing this time or not, I show the "Form has been processed" message.

    This might be a little hard to understand the flow without code, so here's a small demo...
    PHP Code:
    // Form to add a new user, only a username
    <? session_start(); ?>
    <HTML><BODY>
    <?
    if (!isset($_POST['Action']) $_POST['Action'] = '';
    if (!isset(
    $_SESSION['FormProcessed']) $_SESSION['FormProcessed'] = 0;
    $_POST['UserName'] = (isset($_POST['UserName']) ? $_POST['UserName'] : '';
    $_POST['Password'] = (isset($_POST['Password']) ? $_POST['UserName'] : '';
    $FormErrors '';
    if (
    $_POST['Action'] == 'AddUser') {
      do {
        if (
    $_SESSION['FormProcessed'] == 0) {
          if (
    $_POST['UserName']==''$FormErrors .= 'Please provide a username<BR>';
          if (
    $_POST['Password']==''$FormErrors .= 'Please provide a Password<BR>';
          if (
    $FormErrors != '') break;
          
    // insert data into the database here
          // if it fails, show an error and halt
          
    $_SESSION['FormProcessed'] = 1;
        }
        echo 
    'New user was added successfully';
      } while(
    0);
    }
    if (
    $FormErrors != '') echo $FormErrors '<P>';
    ?>
    <FORM ACTION="<? echo $_SERVER['PHP_SELF']; ?>" METHOD="POST">
    <INPUT TYPE=HIDDEN NAME="Action" VALUE="AddUser">
    Username :
    <INPUT TYPE=TEXT NAME="UserName" VALUE="<? echo htmlspecialchars(MyStripSlashes($_POST['UserName'])); ?>">
    <BR>Password :
    <INPUT TYPE=TEXT NAME="Password" VALUE="<? echo htmlspecialchars(MyStripSlashes($_POST['Password'])); ?>">
    <BR><INPUT TYPE=SUBMIT VALUE="Add User">
    </FORM>
    </HTML></BODY>

  8. #108
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will try to come up with a question until tommorow...i can't just think of something right now.....

    I hope this is ok for everyone

  9. #109
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, i got something (a lot quicker as expected, found these questions on the net...), you have to answer all three questions to ask the next one (if that's ok for everybody, if not just use one question [img]images/smilies/wink.gif[/img] )

    1.) What's the name of the very first known PHP Virus ?
    1. PHP.Virus
    2. dEsTR0Y
    3. PHP.Serious
    4. PHP.Pirus
    2.) What do you need to use the function virtual() ?
    1. PHP2
    2. MySQL Database
    3. Perl
    4. Apache Server
    3.) What name did PHP have BEFORE PHP3 ?
    1. PHP2
    2. PHP
    3. PHP/FI 2.0
    4. FI
    Now as with any quiz, you should not go look it up on the internet, either you know the answers or you don't.

    Have fun [img]images/smilies/wink.gif[/img]

  10. #110
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's so hard to come up with good questions....
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  11. #111
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. 2
    2. Perl
    3. Fi
    Aaron Brazell
    Technosailor



  12. #112
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got 'em all wrong
    Aaron Brazell
    Technosailor



  13. #113
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    4, 4, 3?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  14. #114
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    1) 1
    2) 4
    3) 1
    Mike
    It's not who I am underneath, but what I do that defines me.

  15. #115
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    seanf, you're right. Guess it's your turn

    Ps: it is indeed not easy to come up with good questions...

  16. #116
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll let Aaron post his question, I've done a few

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  17. #117
    SitePoint Evangelist cyngon's Avatar
    Join Date
    Aug 2001
    Location
    Livonia, MI, USA
    Posts
    513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got a question idea. I'll post it when someone gives me the ok (or if I manage to get one of these answered correctly before anyone else does).

  18. #118
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah cool....

    What are the 2 kinds of RegX formats used by PHP?
    Aaron Brazell
    Technosailor



  19. #119
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perl Compatible Regular Expressions (PCRE) and POSIX extended - I know what they are, but I hate using them!

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  20. #120
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by seanf
    Perl Compatible Regular Expressions (PCRE) and POSIX extended - I know what they are, but I hate using them!

    Sean
    Yeah regex aren't for wusses.


    *Runs*

  21. #121
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not fast enough Joel!




    Your question cyngon?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  22. #122
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, told you it wasn't hard.
    Aaron Brazell
    Technosailor



  23. #123
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since no questions are being posted, im gonna post one. (i hope nobody minds).

    This is (i think at least), a rather tough question.

    Lets say you have a multidimensional array, like so
    PHP Code:

    $array
    [1] = array ('one' => 1'two' => 2'three' => 3);
    $array[2] = array ('one' => 4'two' => 5'three' => 9);
    $array[3] = array ('one' => 16'two' => 23'three' => 37);
    $array[4] = array ('one' => 13'two' => 25'three' => 33);
    $array[5] = array ('one' => 13'two' => 24'three' => 32);
    $array[6] = array ('one' => 11'two' => 34'three' => 98);
    $array[7] = array ('one' => 19'two' => 32'three' => 23);
    $array[8] = array ('one' => 16'two' => 22'three' => 31); 
    Now, your job is to make $array only contain unique arrays, in such a way that neither the key one or two may be the same.
    So for example, array[4] and array [5] are not valid, because one is 13 on both arrays.


    How do you do it ?

    Have fun thinking images/smilies/wink.gif
    Last edited by datune; Apr 16, 2003 at 19:40.

  24. #124
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    forgive my ignorance, but doesn't it already contain unique arrays? I must be missing the question.
    Aaron Brazell
    Technosailor



  25. #125
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Updated it, sorry, my mistake for not making myself all too clear...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •