PHP Classes

file_prefix not working

Recommend this page to a friend!

      HN CAPTCHA  >  All threads  >  file_prefix not working  >  (Un) Subscribe thread alerts  
Subject:file_prefix not working
Summary:garbage collector will not set the file prefix.
Messages:1
Author:Shaun Freeman
Date:2009-04-30 08:36:02
 

  1. file_prefix not working   Reply   Report abuse  
Picture of Shaun Freeman Shaun Freeman - 2009-04-30 08:36:02
I have been using this class for years now and really love it but recently I come across an interesting bug in the HN_CAPTCHA class and would like to share my simple fix.

When using the captcha with the php5 class the garbage collector will not set the file prefix, it just simply ignores it.

This is because you had set the 'get_filename_url' and 'get_filename' methods and '$public_key' to private. php will not override the parent class methods when set in this fashion and you cannot use private variables from parent class in the child class.

So to fixed this I didn't want to set these to a public scope so I set these methods and variable to protected.

in hn_captcha.class.x1.php5

line 292:
protected function get_filename($public='')
{
if($public==='') $public = $this->public_key;

return $this->tempfolder.$this->prefix.$public.'.jpg';
}

line 301:
protected function get_filename_url($public='')
{
if($public==='') $public = $this->public_key;
return str_replace($_SERVER['DOCUMENT_ROOT'],'',$this->tempfolder).$this->prefix.$public.'.jpg';
}

in hn_captcha.class.php5:

line 388:
protected $public_key;

line 1031:
protected function get_filename($public='')
{
if($public==='') $public = $this->public_key;
return $this->tempfolder.$public.'.jpg';
}

line 1038:
protected function get_filename_url($public='')
{
if($public==='') $public = $this->public_key;
return str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->tempfolder).$public.'.jpg';
}

now with these set with the right scope the prefix will be added to the image names.

further reading http://uk3.php.net/manual/en/language.oop5.visibility.php

Hope this will help all who use your wonderfull script.