Jump to content

ZHarvey

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ZHarvey's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. AbraCadaver, Yes the print_r() prints them via natural ordering algorithm correctly. But since natsort() doesn't change key/value pairs, if you just for-loop through the array, it will appear to be unsorted! Shawn, Thank you it *looks* like that was what I needed (array_values, didn't even know it existed). Personally, I think that's the first aspect of PHP that I dislike so far, and I've been coding in PHP for almost a year now. It is insane to me that an array sorting function doesn't actually reorder the elements in the array. I can't think of another language that operates like this. Thanks for the suggestions and input everyone!
  2. Let's say I have an array: $myArray[0] = "AtG2"; $myArray[1] = "AtG4"; $myArray[2] = "AtG1"; $myArray[3] = "AtG3"; $myArray[4] = "AtG5"; I want to sort it alphanumerically, so that the key/value pairs are as follows: [zero*] => "AtG1" [1] => "AtG2" [2] => "AtG3" [3] => "AtG4" [4] => "AtG5" * = I have to write [zero] because putting an actual zero number inside of [ and ] braces converts it to an HTML list bullet. It *appears* that natsort() is the proper function for this. The only problem I'm having is that natsort() doesn't manipulate key/value pairs. To confuse me even more, literally every example I can find on using natsort() uses it in conjunction with print_r() like so: natsort($someArray); print_r($someArray); Obviously, something is happening to $someArray when passed to natsort(), otherwise, print_r() wouldn't be able to order the indices in synch with the natural ordering algorithm. Well, I don't need my web app to use print_r()! I just need the darn key/value pairs reordered so that when I echo $myArray[3], I know I'm going to get "AtG4". What am I missing here? What is the point of calling it a "sort" if it doesn't manipulate the key/value pairs??? How can I get what I want?!?
  3. Thanks for the reply, Here is my code: <?php session_start(); // Make captcha $md5 = md5(microtime() * mktime()); $string = substr($md5,0,7); $captcha = imagecreatefrompng("./img/captcha.PNG"); $black = imagecolorallocate($captcha, 0, 0, 0); $line = imagecolorallocate($captcha,233,239,239); imageline($captcha,0,0,39,29,$line); imageline($captcha,40,0,64,29,$line); imagestring($captcha, 5, 20, 10, $string, $black); $_SESSION["CAPTCHA_CHALLENGE"] = md5($string); header("Content-type: image/png"); imagepng($captcha); $result = " "; if($_GET["action"] == "proc") { $response = $_POST["response"]; if($response != $_SESSION["CAPTCHA_CHALLENGE"]) $result = "The code you entered was incorrect."; else $result = "Correct!"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test</title> </head> <body> <div><?php echo $result; ?></div> <div id="test"> <h1>This is a test<h1> <form name="x" method="POST" action="Test.php?action=proc"> Type the code on the right: <input type="text" name="response" size="7" maxlength="7"/> <img src="./img/captcha.PNG"/> </form> </div> </body> </html> Now what is happening is that the page is loading with the captcha at the top-left, but all the HTML/form content is being ignored, probably because I'm telling the page to display image/png content. Any ideas? Thanks always, ZHarvey
  4. I am following a 4-year old tutorial on creating PHP captchas through the GD. When I include the PHP-generating code on a page that has nothing else (no HTML/text content), the captcha loads perfectly fine. But when I try to mix it in with any HTML at all, I get the error: "The image “http://testing.mysite.com/dts/cots/Test.php” cannot be displayed, because it contains errors.". Here is my code: // Author: Andrew Walsh // Original Post: http://www.codewalkers.com/c/a/Miscellaneous/Creating-a-CAPTCHA-with-PHP/ session_start(); $md5 = md5(microtime() * mktime()); $string = substr($md5,0,7); $captcha = imagecreatefrompng("./img/captcha.PNG"); $black = imagecolorallocate($captcha, 0, 0, 0); $line = imagecolorallocate($captcha,233,239,239); imageline($captcha,0,0,39,29,$line); imageline($captcha,40,0,64,29,$line); imagestring($captcha, 5, 20, 10, $string, $black); $_SESSION["CAPTCHA_CHALLENGE"] = md5($string); header("Content-type: image/png"); imagepng($captcha); The reason for the error is obvious: I am telling the system that I want to set the page's content type to image/png. If I am placing my CAPTCHA in an HTML form, then by definition there will already be text/html content sent back from the server by the time it gets to the header definition. According to the PHP manual, header must be the first call in a PHP page, otherwise it will throw an error. Is there a way to hack this or make this work so that I can place the code in an HTML form, mid-page? I guess I just don't know enough about the GD or PHP in general to come up with my own solution. Thanks, ZHarvey
×
×
  • 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.