SitePoint Sponsor

User Tag List

Page 6 of 9 FirstFirst ... 23456789 LastLast
Results 126 to 150 of 219

Thread: PHP Quiz

  1. #126
    SitePoint Zealot Blunderboy's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    eh?

    Why do I get the following error when I run this snippet:

    <?php
    ****$i = 'Z';
    ****echo ++$i;
    ?>


    Parse error: parse error, unexpected T_VARIABLE in C:\Inetpub\wwwroot\drip.php on line 2

  2. #127
    SitePoint Zealot Blunderboy's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where did all those stars come from?

  3. #128
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont think you can do this:
    PHP Code:
    echo ++$i
    Just do
    PHP Code:
    ++$i;
    echo 
    $i

  4. #129
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works for me

    Sean
    Harry Potter

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

  5. #130
    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 Blunderboy
    where did all those stars come from?
    (It used to be underscores)
    Here's the answer: http://www.sitepointforums.com/showt...threadid=91924
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  6. #131
    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 datune
    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.
    Once we identify the bogus array, what should we do with it?
    Alter it? Delete it?
    Which of two that match should be deleted?
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  7. #132
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    Once we identify the bogus array, what should we do with it?
    Alter it? Delete it?
    Which of two that match should be deleted?
    Alright, i understand my question might be too difficult (or not written well), so let me try to explain in an easier way.

    Let's use smilies for this example.

    Each smilie consists of three elements

    code, url, and descr.

    Now, as we all know, smilies may have different codes, but yet have the same url and descr.

    For example, ; ) and ; - ) are both the same smilies.

    Now you have an array as follows (note, im using wrong smilie codes, or otherwise the board would interpret them)
    PHP Code:
    $smilies = array();

    $smilies[1] = array('code' => '-smile-''url' => 'smile.gif''descr' => 'smile');
    $smilies[2] = array('code' => '*smile*''url' => 'smile.gif''descr' => 'smile');
    $smilies[3] = array('code' => '-grin-''url' => 'grin.gif''descr' => 'grin');
    $smilies[4] = array('code' => '*grin*''url' => 'grin.gif''descr' => 'grin'); 
    Now, let's say you wanted to print out the smilies, in the same way as vBulletin does, in a table. Now you don't really want to have two identical smilies displayed just because there are 2 or more different smilie codes existing.

    So, again, your job is to return a smilie array which only holds each smilie once, no matter the code. That's the only rule. it doesn't matter which array get#s removed etc...just make sure that FOR EXAMPLE this would be the outcome
    PHP Code:
    $smilies[1] = array('code' => '-smile-''url' => 'smile.gif''descr' => 'smile');
    $smilies[2] = array('code' => '-grin-''url' => 'grin.gif''descr' => 'grin'); 
    There, this should make things much more understandable images/smilies/wink.gif
    Last edited by datune; Apr 17, 2003 at 08:28.

  8. #133
    "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)
    PHP Code:
    echo ++$i
    is valid.
    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.

  9. #134
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gotcha!
    I have a feeling that there's room for improvment here. Any ideas?
    PHP Code:
    $smilies = array();
    $smilies[0] = array('code' => '-smile-''url' => 'smile.gif''descr' => 'smile');
    $smilies[1] = array('code' => '*smile*''url' => 'smile.gif''descr' => 'smile');
    $smilies[2] = array('code' => '-grin-''url' => 'grin.gif''descr' => 'grin');
    $smilies[3] = array('code' => '*grin*''url' => 'smile.gif''descr' => 'grin');
    $urls = array();
    $c count($smilies);
    for (
    $i=0$i<$c$i++ )
    {
       if (
    in_array($smilies[$i]['url'], $urls))
       {
          
    array_splice($smilies$i1);
       }
       else
       {
          
    $urls[] = $smilies[$i]['url'];
       }

    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  10. #135
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a good look at smilies[3] ['url']

    Correct it, and run your script again

    nice try though :P

  11. #136
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, not sure what you mean. This is the result I get from my attempt without any changes... the array came from cut and pasting your data. I did alter the array so that it began with 0 but that's it.
    [code]
    Array
    (
    [0] => Array
    (
    [code] => -smile-
    [url] => smile.gif
    [descr] => smile
    )

    [1] => Array
    (
    Code:
     => -grin-
                [url] => grin.gif
                [descr] => grin
            )
    
    )
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  12. #137
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Damn, im sorry. My mistake, i corrected it. Have a look and you will see. Sorry bout that...

  13. #138
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ha! I had a lot more trouble with that than I expected!

    The second time I went at it, I didn't change the array[1] numbers to create an array beginning with [0]. However, as soon as array_splice got its hands on the $smilies array, it rewrote the array to begin with [0]! Took me a little while to notice.

    Something else silly:
    PHP Code:
    $c count($array);
    for (
    $i=0$i<=$ci++) { //etc } 
    One big thing wrong with this: for doesn't work on a copy of the array like foreach. Therefore it is obivious to rather crucial factors, like the array getting shrunk by array_splice. Also there is no need to advance a number (i++) if an array element was removed. Therefore, I shifted that to the else part of the code.

    Anyway, I think everything is fixed up in this version. Instead of explicitly renumbering the array, I threw in shuffle, which both changed the array to begin at [0] and go to [3] and allowed me to check the script with many different orders. Anyway, hopefully this does the job. :)
    PHP Code:
    shuffle($smilies);
    for (
    $i=0$i<=count($smilies);)
    {
       if (
    in_array($smilies[$i]['url'], $urls))
       {
          
    array_splice($smilies$i1);
       }
       else
       {
          
    $urls[] = $smilies[$i]['url'];
          
    $i++;
       }

    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  14. #139
    SitePoint Evangelist cyngon's Avatar
    Join Date
    Aug 2001
    Location
    Livonia, MI, USA
    Posts
    513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The previous question seems to be solved so I am jumping in. I hope no one minds. Here is the question, as inspired by an article I read a while ago:

    I have a database table to store a user's name, password, and credit card number. Only the user who owns the credit card should be able to decrypt and view their CC number. This means that even someone with full access to the database should never be able to read any credit card numbers unless they know a user's password.

    Like in most PHP authentication schemes, passwords are stored in the database as md5 hashes so they cannot ever be decoded.

    You need to write two snippets of code:

    1. Given a user's name, actual (not md5()ed) password, and credit card number store it in the database using strong encryption.

    2. Given a user's name, actual (not md5()ed) password, retrive their credit card number from the databse and decrypt it.

    It must be absolutely impossible to decrypt a credit card number without that user's actual password. Also, since the md5() hashed passwords are stored in the database along with the credit card numbers, it must be impossible to decrypt a credit card number with just the md5() hash of the password and not the password itself.

    If the credit card number could be decrypted with just the md5() hash then anyone with full read access to the databse could decrypt the credit card numbers.

  15. #140
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    Ha! I had a lot more trouble with that than I expected!

    The second time I went at it, I didn't change the array[1] numbers to create an array beginning with [0]. However, as soon as array_splice got its hands on the $smilies array, it rewrote the array to begin with [0]! Took me a little while to notice.

    Something else silly:
    PHP Code:
    $c count($array);
    for (
    $i=0$i<=$ci++) { //etc } 
    One big thing wrong with this: for doesn't work on a copy of the array like foreach. Therefore it is obivious to rather crucial factors, like the array getting shrunk by array_splice. Also there is no need to advance a number (i++) if an array element was removed. Therefore, I shifted that to the else part of the code.

    Anyway, I think everything is fixed up in this version. Instead of explicitly renumbering the array, I threw in shuffle, which both changed the array to begin at [0] and go to [3] and allowed me to check the script with many different orders. Anyway, hopefully this does the job. [img]images/smilies/smile.gif[/img]
    PHP Code:
    shuffle($smilies);
    for (
    $i=0$i<=count($smilies)[img]images/smilies/wink.gif[/img]
    {
    if (
    in_array($smilies[$i]['url'], $urls))
    {
    array_splice($smilies$i1);
    }
    else
    {
    $urls[] = $smilies[$i]['url'];
    $i++;
    }

    Very nice. Only two things. You don't need shuffle, and this
    PHP Code:
    for ($i=0$i<=count($smilies))
     
    //should be
     
    for ($i=0$i<count($smilies)) 
    Cause PHP will otherwise spit out Notices saying that there is an undefined index.
    Otherwise, brilliant. Your turn to ask a question

  16. #141
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shuffle isn't nessesary, you are right.

    However, I declare a foul on the array that begins with [1]. What's up with that? Begin your array's with [0] and everything will work more predictably.

    Interesting about the <= vs. < , I should have checked that with a higher error level, I wasn't getting any warnings.

    Anyway, I hand my question over to cyngon. His question is two up from this post and I think I can produce an accurate answer tomorrow so the rest of you have about 8-10 hours!
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  17. #142
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like

    $username = 'username';
    $password = 'password';
    $key = $password.$username;
    $cc_number = '1234-5678-9012-3456';
    $cc_crypt = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $key, $cc_number, MCRYPT_MODE_ECB);
    $passwordhash = MD5($password);
    $quizit = mysql_query("INSERT INTO `cards` (user,pass,card) VALUES ('$username','$passwordhash','$cc_crypt')");

    ------------------------------

    $username = 'username';
    $password = 'password';
    $passwordhash = MD5($password);
    $quizit = mysql_query("SELECT card, user, pass FROM `cards` WHERE user='$username' AND pass='$passwordhash'");
    // assumes $row['card'] as returned variable for card
    $key = $password.$username;
    $cc_decrypt = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $key, $row['card'], MCRYPT_MODE_ECB);

    ------------------------------

    you could also maybe set and store an initialization vector and sling that into both the encrypt and decrypt calls as the last param.
    $init_vector = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),MCRYPT_RAND);

    furthering that basic exaample would be dependent upon the server you are on.
    teckis - that's news to me.

  18. #143
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What happens when they need to reset their password? Wouldn't they need to re-enter their CC details?
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  19. #144
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you'd just retrieve it, re-encrypt it with the new key and then re-insert it
    teckis - that's news to me.

  20. #145
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't retrieve it if they've forgotten their password - to decrypt it you need their password in cleartext, which is only available through user input.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  21. #146
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when have you ever let a user change their password without knowing the old one?

    doing that is like saying 'hey just ask nice and we'll give away the cc numbers'

    you'd have to create a rand password and maybe mail them that, get them to input that before changing to their new choice
    teckis - that's news to me.

  22. #147
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Based on secret-question or e-mail validation (or both); the whole point is that they would need to reset it since they forgot it.

    In any case, since at that point, nobody has the password in cleartext, your 'card' field is line noise.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  23. #148
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so - how do you script something so that no-one (user, cracker or even system-admin) can recreate the credit card number without knowing the cleartext password --- and allow resetting of that password for when people forget.

    all the ways I can see would require storing the encryption key as plaintext which defeats the security entirely.

    anyone?
    teckis - that's news to me.

  24. #149
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anode is correct, no one is going to be able to unencrypt the credit card number without the password. However, retrieval through alternate means is not applicable for this particular question.
    Quote Originally Posted by cyngon
    It must be absolutely impossible to decrypt a credit card number without that user's actual password.
    In cyngon's scenario, even the database admin must be ignorant of the actual credit card numbers. If any alternate method for retrieving the credit card number was available, that solution would not be acceptable this challenge.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  25. #150
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry guys, I was stuck in "practical mode" for some reason

    This does lead me to wonder what Authorize.net and the rest use.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure


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
  •