Krash Posted March 31, 2011 Share Posted March 31, 2011 Trying to run this function so it displays the generated image in a table cell - <?php function imgsecuregen($size = 6){ $width = 11*$size; $height = 25; $string = ""; for($i = 1; $i <= $size; $i++){ $string .= rand (0,9).""; } // for $im = ImageCreate($width, $height); $bg = imagecolorallocate($im, 102, 102, 102); // background $black = imagecolorallocate($im, 0, 255, 0); // text $grey = imagecolorallocate($im, 102, 102, 102); // border imagerectangle($im,0, 0, $width-1, $height-1, $grey); imagestring($im, 5, $size, 5, $string, $black); imagepng($im); imagedestroy($im); } imgsecuregen(; // string length ?> Works if I load it directly, but not in a <td>. Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/ Share on other sites More sharing options...
Skewled Posted March 31, 2011 Share Posted March 31, 2011 Your showing us the code that's working, but your error is how your calling the function into your table. Just how are you doing that? I also sent you a PM about how your using this, because it would determine if you even need it to be a function or not. Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194771 Share on other sites More sharing options...
Krash Posted March 31, 2011 Author Share Posted March 31, 2011 I'm tinkering with a registration verification widget, which currently generates a random 8 digit numeric code that the user must enter. The code itself is not important, but generating a random image with this function (which I found on another board a while back) would serve the same purpose, and also be a red herring for the bots. Have no idea how to embed it in a table cell, other than echoing the function between <td> tags, which doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194778 Share on other sites More sharing options...
Skewled Posted March 31, 2011 Share Posted March 31, 2011 You could load it as an image <img src="name.php" and ditch the function side of it. Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194788 Share on other sites More sharing options...
Krash Posted March 31, 2011 Author Share Posted March 31, 2011 The function doesn't generate an image name, or an image file, as far as I can see. I can save it off the page as a bmp, but it's nowhere on the server. Not sure exactly how it works, but I can manipulate the code to duplicate exactly what I'm doing in the table cell with the random string. Just can't get it to display in the cell. Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194793 Share on other sites More sharing options...
PFMaBiSmAd Posted March 31, 2011 Share Posted March 31, 2011 You must use a HTML <img ..> tag to display an image on a web page (it's the browser the requests the image from wherever it is at and renders the image on the page.) See this recent thread for an example of someone doing this for their images stored in a database - http://www.phpfreaks.com/forums/index.php?topic=328757.0 You would put your GD code into the .php file that is put into the src="..." attribute. You would need to save the randomly generated number in a session variable so that it is available to the form processing code. Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194795 Share on other sites More sharing options...
Skewled Posted March 31, 2011 Share Posted March 31, 2011 You could session_start() Then add a session variable for your $string $_SESSION['passphrase'] = SHA1($string); before you clean up the image with imagedestroy add a header: header('Content-type: image/png"); imagepng($im); Then in your form add enctype="multipart/form-data" Then display the <img src="name.php"... Then you can use the $_SESSION variable to compare and check the verification image with the verification text. EDIT: I was working this up for you while PFMaBiSmAd posted but this is what he's also saying I believe Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194796 Share on other sites More sharing options...
Krash Posted March 31, 2011 Author Share Posted March 31, 2011 OK, got it working. Looks good, but the font's a little small and I can't make it larger (just smaller). Can you explain how the header works? Now I'll try to get the $string value out of it and into the form handler. So far, so good. Thx! Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194808 Share on other sites More sharing options...
Krash Posted March 31, 2011 Author Share Posted March 31, 2011 Everything looks/works exactly right. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194815 Share on other sites More sharing options...
Skewled Posted March 31, 2011 Share Posted March 31, 2011 Your welcome Quote Link to comment https://forums.phpfreaks.com/topic/232248-calling-function-in-table-cell/#findComment-1194831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.