943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 38
  • PHP RSS
Aug 31st, 2010
0

calling Session?

Expand Post »
Hi, I've got a form with captcha working, but I'm trying to add a 'refresh captcha' link too it. Now I already have something changing dynamically with PHP so I was wondering if something like that would work for this. Here's the one I have working:

PHP Syntax (Toggle Plain Text)
  1. <a href="index.php?act=generate_quotes">Generate</a>

This obviously calls the function 'generate quotes. This works fine, but is there anyway to add a link to call something like this:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3.  
  4. $sha1 = SHA1(rand(2000,999000));
  5. $letters = mt_rand(5,8);
  6. $key = '';
  7. for($i = 0; $i < $letters; $i++){
  8. $pos = mt_rand(0, strlen($sha1)-1);
  9. $key .= substr($sha1, $pos, 1);
  10. }
  11.  
  12.  
  13. $_SESSION['captcha'] = $key;
  14.  
  15.  
  16. $w = 320;
  17. $h = 100;
  18.  
  19. $r = mt_rand(160, 255);
  20. $g = mt_rand(160, 255);
  21. $b = mt_rand(160, 255);
  22.  
  23. $captcha = imagecreate($w, $h);
  24. $background = imagecolorallocate($captcha, 255,255,255);
  25. $text = imagecolorallocate($captcha, $r-128, $g-128, $b-128);
  26. $dots = imagecolorallocate($captcha, 84,84,84);
  27. for($i = 0; $i < 1700; $i++) {
  28. imagefilledellipse($captcha, mt_rand(0,$w), mt_rand(0,$h), 1,
  29. 1, $dots);
  30.  
  31.  
  32. }
  33.  
  34.  
  35.  
  36. for($i = 1; $i <= $letters; $i++){
  37. $counter = mt_rand(0, 1);
  38. if ($counter == 0){
  39. $angle = mt_rand(0, 30);
  40. }
  41. if ($counter == 1){
  42. $angle = mt_rand(330, 360);
  43. }
  44.  
  45. imagettftext($captcha, 40, $angle, ($i * 18)-8, 70, $text, "iskpota.ttf", substr($key, ($i - 1), 1));
  46. }
  47.  
  48.  
  49. imageline($captcha, 0, mt_rand(5, $h-5), $w, mt_rand(5, $h-5), $text);
  50.  
  51.  
  52.  
  53. imagerectangle($captcha, 0, 0, $width - 1, $height - 1, $text);
  54. function Blur($im)
  55. {
  56.  
  57. $width = imagesx($im);
  58. $height = imagesy($im);
  59.  
  60. $temp_im = ImageCreateTrueColor($width,$height);
  61. $bg = ImageColorAllocate($temp_im,150,150,150);
  62.  
  63.  
  64. ImageColorTransparent($temp_im,$bg);
  65.  
  66.  
  67. ImageFill($temp_im,0,0,$bg);
  68.  
  69.  
  70. $distance = 1;
  71.  
  72.  
  73.  
  74. ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height-$distance, 70);
  75. ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width-$distance, $height, 70);
  76. ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, 70);
  77. ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, 70);
  78. // remove temp image
  79. ImageDestroy($temp_im);
  80.  
  81. return $im;
  82. }
  83. Blur($captcha);
  84.  
  85.  
  86.  
  87. header('Expires: Tue, 08 Oct 1991 00:00:00 GMT');
  88. header('Cache-Control: no-cache, must-revalidate');
  89.  
  90.  
  91. header("Content-Type: image/gif");
  92. imagegif($captcha);
  93. imagedestroy($captcha);
  94. ?>

The above code is my capture .PHP - I've tried adding a function too it and calling it the same way, but to no avail, could someone help me out with how to go about doing this? I've never really used sessions so I'm not sure how to call them in the same way...

thanks for any help.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
ello is offline Offline
66 posts
since Aug 2010
Aug 31st, 2010
0
Re: calling Session?
I don't think that you have provided enough info for anyone to help you. The structure of your modules and how they relate to each other isn't clear. You could certainly add a link to call the above module but it isn't clear if this will accomplish what you need to do. Maybe you should be including this module instead. You don't call a session, it is just a facility that you can use to pass info between modules and keep info through a transaction sequence. If you provide a more complete explanation, someone may be able to help you.
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Aug 31st, 2010
0
Re: calling Session?
Click to Expand / Collapse  Quote originally posted by chrishea ...
I don't think that you have provided enough info for anyone to help you. The structure of your modules and how they relate to each other isn't clear. You could certainly add a link to call the above module but it isn't clear if this will accomplish what you need to do. Maybe you should be including this module instead. You don't call a session, it is just a facility that you can use to pass info between modules and keep info through a transaction sequence. If you provide a more complete explanation, someone may be able to help you.
Aaha o.k, apologies. The basic answer I'm after is 'how can I add a 'refresh capture' link'

I'm sure you've all seen them, the ones where you can change just the capture dynamically if the user can't read it.

The first link was just ideally how I wanted to do it, they're not linked. It was just an example I had of changing something on the page dynamically. Granted, this wasn't very well explained.

I just wondered if there was a way for me to have a ahref link like in the first example, but it refresh the captcha. If that makes sense?

maybe something like:

PHP Syntax (Toggle Plain Text)
  1. <a href="captcha.php? // something to refresh the captcha //">Refresh</a>
Last edited by ello; Aug 31st, 2010 at 10:26 am.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
ello is offline Offline
66 posts
since Aug 2010
Aug 31st, 2010
0
Re: calling Session?
The simplest way is to just have a form with a refresh button where the action is the same module (assuming that it generates a random captcha each time). If the user has entered any data, then you need to pass them as hidden variables so they aren't lost (or as session variables). This will cause the screen to be refreshed from the server. If you want to get fancier, you can investigate JQuery / Javascript captchas that have this refresh built in.
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Aug 31st, 2010
0
Re: calling Session?
Click to Expand / Collapse  Quote originally posted by chrishea ...
The simplest way is to just have a form with a refresh button where the action is the same module (assuming that it generates a random captcha each time). If the user has entered any data, then you need to pass them as hidden variables so they aren't lost (or as session variables). This will cause the screen to be refreshed from the server. If you want to get fancier, you can investigate JQuery / Javascript captchas that have this refresh built in.
Aaah yes, great idea, didn't think of that, thanks alot for all your help
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
ello is offline Offline
66 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: no output from result set
Next Thread in PHP Forum Timeline: Help with error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC