[PHP] Form Validating Class (OOP misunderstandings...)

2003-01-21 Thread Nicholas Wieland
Hello everybody,
I'm working on a class but having a lot of problems... probably my 
understanding of PhP-OOP is not so good ...
Here's the class: I found it on the web and I've tried to personalize 
it to fit my needs...



class FormV
{
	var $errorList;
	 
	function FormV()
	{
		$this->reset_errorList();
	}
	 
	function getValue( $field )
	{
		$value = $HTTP_POST_VARS[ $field ];
		return $value;
	}
	 
	function isEmpty( $field, $msg )
	{
		$value = $this->getValue( $field );
		 
		if( trim( $value ) == "" )
		{
			$this->errorList[] = array( "field" => $field, 
"value" => $value, "msg" => $msg );
			return true;
		} 	 
		else
			return false;
	 
	}
	 
	function isString( $field, $msg )
	{
		$value = $this->getValue( $field );
		 
		if( is_string( $value ) )
			return true;
		 
		else
		{
			$this->errorList[] = array( "field" => $field, 
"value" => $value, "msg" => $msg );
			return false;
		}
	}
		 
	function isEmail( $field, $msg )
	{
		$value = $this->getValue( $field );
		$pattern = 
"/^([a-zA-Z0-9])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
		 
		if( preg_match( $pattern, $value ) )
			return true;
			 
		else
		{
			$this->errorList[] = array( "field" => $field, 
"value" => $value, "msg" => $msg );
			return false;
		}
	}
	 
	function isError()
	{
		if( sizeof( $this->errorList ) > 0 )
			return true;
			 
		else
			return false;
	}
	 
	function get_errorList()
	{
		return $this->errorList;
	}
	 
	function reset_errorList()
	{
		$this->errorList = array();
	}
	 
	function stringConvert( $field )
	{
		$value = $this->getValue( $field );
		 
		$value = html_special_chars( $value );
		 
		$value = stripslashes( $value );
		 
		$value = strtolower( $value );
		 
		return $value;
	}
	 
};

?>

Ok.
I think that the getter is *totally* wrong but I'm not able to debug 
it, because it's private (I think...). Also the stringConvert() method 
sucks, maybe I'll split it in some others accessor methods, for a 
better design.
Now I'm totally lost, I don't have a clue how to continue, I've tried 
for hours and hours to make it work, but didn't succeed :(
Any suggestion on improving and other enhancment for a good form 
validating class is really really appreciated.

TIA,
	Nicholas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Form Validating Class (OOP misunderstandings...)

2003-01-21 Thread Nicholas Wieland
On 2003.01.21 15:42 Joseph W. Goff wrote:

For the most part I found two errors
The first was a scope problem.  $HTTP_*_VARS hashes are not accessible
inside functions unless you source them in.  i.e. global
The other was an extra line in an if statement that did not contain
braces.
I did a little formating while I checked the code.  Try this to see if
it
works as you expected it to.



snip, it's perfect >


Yes, it works. I misunderstood the visibility of $HTTP_POST_VARS.
Thank you Joseph ! I really appreciate your help :)

I've read the paper from OWASP and now I'm a little paranoid about form 
validating and user input... does someone have other suggestions about 
improving the class ?

TIA,
	Nicholas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Form Validating Class (OOP misunderstandings...)

2003-01-21 Thread Nicholas Wieland
On 2003.01.21 15:21 Rich Gray wrote:

PHP does not yet support private methods ... your problem with
getValue() is
most probably because register_globals is off in your php.ini try
substituting $_POST[] for $HTTP_POST_VARS[] and it may start to
work...


Sorry... I forgot to mention that I use PhP 4.2.2 on my GNU/Linux Box 
but I have PhP 4.0.6 on the production machine, AFAIK $_POST is a 
'feature' of PhP 4.1.x ...
Thanks for your help, I'll try to be more accurate next time...

	Nicholas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function problem

2003-02-14 Thread Nicholas Wieland
On 2003.02.15 00:11 Peter Gumbrell wrote:
[...]

$option_block .= "
[...]

Are you sure it's a scope problem ?
You haven't instantiated any $option_block variable when the loop 
starts, so you're concatenating a string to a bunch of uninitialized 
memory :)
I can't run your script at the moment, so it's just a supposition...

Hope it helps,
	Nicholas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] permissions to work with fopen

2003-02-15 Thread Nicholas Wieland
On 2003.02.15 20:11 qt wrote:

I am planning to make a log file with fopen command.

I am succesfully read and write the file with fopen. But as I see
fopen is requiring a file with read and write permission for public.


Not for public, for your webserver user, www-data or another similar 
name.

I was using same method with perl in cgi-bin directory; but I was
giving read and write permission for only owner.

If I give write and read permission for only owner; fopen command can
not read the file.

Do you have any idea, how can I make log file with protecting from
public?


Give pemissions to your web server user.

Cheers
	Nicholas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php