Jump to content

Calling function in table cell


Krash

Recommended Posts

 

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>.

:shrug:

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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.

 

 

Link to comment
Share on other sites

 

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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!  thu.gif

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.