[PHP] How to store data that doesn't change?

2010-09-15 Thread Peter van der Does
Hi,

How do you people store data that doesn't change, an example of this
would be the version number of your software. You might want to use it
through out your program but how to you store it?

As far as I can see there are several options to use this data.
1. Global Variable
2. Store it in a registry class
3. Store it in a named constant.
4. Use a function that will return the data (kind of like a regsitry
class but it's not a class)

Personally I don't like option 1 but what about the other options. Is
any of them faster then the others. What other pros and cons are there.

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



Re: [PHP] Math Question....

2010-04-22 Thread Peter van der Does
On Thu, 22 Apr 2010 10:17:10 -0400
Dan Joseph dmjos...@gmail.com wrote:

 On Thu, Apr 22, 2010 at 10:12 AM, Stephen stephe...@rogers.com
 wrote:
 
  1,252,398 DIV 30 = 41,746 groups of 30.
 
  1,252,398 MOD 30 = 18 items in last group
 
 Well, the only problem with going that route, is the one group is not
 equally sized to the others.  18 is ok for a group in this instance,
 but if it was a remainder of only 1 or 2, there would be an issue.
 Which is where I come to looking for a the right method to break it
 equally.
 

My take on it:

$Items=1252398;
$MaxInGroup=30;
for ($x=$MaxInGroup; $x1;$x--) {
$remainder=$Items % $x;
// Change 17 to the max amount allowed in the last group
if ($remainder == 0 || $remainder = 17) { // 
$groups = (int) ($Items /$x)+1;
echo $groups.\n;
echo $remainder;
break;
}
}

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



Re: [PHP] Math Question....

2010-04-22 Thread Peter van der Does
On Thu, 22 Apr 2010 10:49:11 -0400
Peter van der Does pvanderd...@gmail.com wrote:


 
 My take on it:
 
 $Items=1252398;
 $MaxInGroup=30;
 for ($x=$MaxInGroup; $x1;$x--) {
   $remainder=$Items % $x;
   // Change 17 to the max amount allowed in the last group
   if ($remainder == 0 || $remainder = 17) { // 
   $groups = (int) ($Items /$x)+1;
   echo $groups.\n;
   echo $remainder;
   break;
   }
 }
 
Bugfixed LOL:
$Items=1252398;
$MaxInGroup=30;
for ($x=$MaxInGroup; $x1;$x--) {
$remainder=$Items % $x;
// Change 17 to the max amount allowed in a group
if ($remainder == 0 || $remainder = 17) {
$groups = (int) ($Items /$x);
if ($remainder  0 ) {
$groups++;
}
echo $groups.\n;
echo $remainder;
break;
}
}

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



Re: [PHP] Global Var Disappearing After Function

2010-03-22 Thread Peter van der Does
On Mon, 22 Mar 2010 16:58:33 -0400
APseudoUtopia apseudouto...@gmail.com wrote:

 Hey list,
 
 I have a very odd problem which has been driving me crazy for two
 days. I've been trying to debug my code and gave up. I finally coded a
 very simple representation of what the code does, and I get the same
 problem. However, I still don't understand what's causing it.
 
 The representational code:
 http://pastie.org/private/fz3lgvsjopz3dhid8cf9a
 
 As you can see, it's very simple. A variable is set, then a function
 is called which modifies the variable in the global scope. However,
 the modifications CANNOT BE SEEN after the function is called.
 
 The output from the script is here:
 http://pastie.org/private/29r5mrr1k7rtqmw7eyoja
 
 As you can see, the modifications in do_test() cannot be seen after
 the function is called.
 
 What is causing this? And how can I fix it?
 
 Thanks!
 

From PHP.net:

If a globalized variable is unset() inside of a function, only the
local variable is destroyed. The variable in the calling environment
will retain the same value as before unset() was called. [1]

[1] http://php.net/manual/en/function.unset.php


-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



[PHP] Using ArrayObject

2010-03-09 Thread Peter van der Does
What is the advantage of using ArrayObject to build a Registry class?

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



[PHP] Registry class question.

2010-02-26 Thread Peter van der Does
Hi,

I've build a registry class to store settings I need to use in several
other classes.

Currently I've set it up with a static array in the registry class and
using two methods to access the settings and values
storeSetting($key,$value) {
  $this-_settings[$key] = $value;
}

getSetting($key) {
  return $this-_settings[$key];
}

The question is what the pros and cons are compared to setting a new
property with the value, like:

storeSetting($key,$value) {
  $this-$key = $value;
}

and then instead of calling getSetting, you just use
$this-Registry-property

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



Re: [PHP] Spam opinions please

2009-10-20 Thread Peter van der Does
On Tue, 20 Oct 2009 14:31:53 -0400
Gary gwp...@ptd.net wrote:

 I have several sites that are getting hit with form spam.  I have the
 script set up to capture the IP address so I know from where they
 come.  I found a short script that is supposed to stop these IP
 addresses from accessing the form page, it redirects the spammer to
 another page (I was going to redirect to a page that has lots of
 pop-ups, scantily clad men and offers of joy beyond imagination), but
 someone suggested I redirect to the Federal Trade Commission or
 perhpas the FBI.
 
 Any thoughts on the script and its effectivness?
 
 ?php
 $deny = array(111.111.111, 222.222.222, 333.333.333);
 if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
header(location: http://www.google.com/;);
exit();
 } ?Gary 
 
 

There are several options to stop spammers, although none of them will
completely eliminate all spam. For a forum I prefer the .htaccess
method.

There is a website dedicated to keeping track of forum spammers,
http://stopforumspam.com and  depending on your forum you could add an
anti-spam mod that will query their database. On the site they have
mods for phpbb, vBulletin and SMF.

I wrote a Python script that uses a Python Library that's also posted
on their site. The Python program basically use an Apache log file for
the IP's checks them at Stop Forum Spam and adds spam IP in
the .htaccess file. I have it set up in cron to run daily.
For a little bit more detailed description and the program itself:
http://blog.avirtualhome.com/2009/10/08/stop-spammers-in-your-htaccess/


-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



Re: [PHP] Form Spam

2009-08-20 Thread Peter van der Does
On Thu, 20 Aug 2009 09:11:47 -0400
Gary gwp...@ptd.net wrote:

 I have a client with a form on his site and he is getting spammed.
 It appears not to be from bots but human generated.  While they are
 coming from India, they do not all have the same IP address, but they
 all have gmail addresses, New York  addresses are used in the input
 field and they all offer SEO services.  It is not overwhleming, but
 about 5 a month.
 
 What is the best way to stop this.
 
 Thanks
 
 Gary 
 

One of the things you could check is if they do direct posting.
What I mean by that if that sometimes a POST URL only is send. They
figured out the fields you have in your form and directly send a POST
with the appropriate fields.
You could check this in the webserver logs. Just look for the IP and
see if it only has a POST URL.

If this is the case you could implement a nonce on your form and check
it during the processing of the post.

A second idea is to check the IP of the visitor during the POST
process, with something like stopforumspam or project honey pot.

If you want more info let me know.


-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com


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



Re: [PHP] Anyone know whats the best way to learn PHP

2009-06-01 Thread Peter van der Does
On Mon, 1 Jun 2009 15:43:21 +0500
Muhammad Hassan Samee hassansa...@gmail.com wrote:

 Hi
 
 Anyone know whats the best way to learn PHP? Every time I open an php
 book or look the codes online, my mind goes oh man, So many stuffs
 to learn and gets frustrated before i even start but on the other
 hand, I don't know why some how the brain keep on nagging me to learn
 PHP. I guess what's the fun way to learn php? Any good books?

Do you already code?
If so, just download something you are interested in, maybe WordPress
if you blog, with some plugins as those are most likely easier to read,
and look at the programs and try figuring out why things are working
they way they work.
I can't really remember how I started but I believe it was with
Postnuke a long time ago. I looked at the code, try to help fix bugs.

The best way to learn any language, computer or natural, is not by
sitting down and reading books, it's by actually programming/speaking
the language.

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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



[PHP] PHP class question

2009-05-21 Thread Peter van der Does
I have the following situation.

I wrote some software and split it up into functionality:

class core {
  function go{
  }
}

class A extends core {
  // PHP4 constructor
  function A {
$this-go();
  }

}

class B extends core {
}

In core I define functions and variables that are to be used
through out my program and to address those functions/variables I just
use $this- .

Now I ran into a situation where class A needs to be extended with
another class. This is not my choice, it's part of a framework I have
to use.

Currently I solved this by doing this:

class A extends framework_class {
  $var core;

  // PHP4 constructor
  function A {
$this-core = new core();
$this-core-go();
  }
}

The question I have, is this a good solution, is it the only solution
or are there different ways to tackle this?
As you might see it needs to run in PHP4.

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

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



Re: [PHP] Re: PHP class question

2009-05-21 Thread Peter van der Does
On Thu, 21 May 2009 14:08:11 -0500
Shawn McKenzie nos...@mckenzies.net wrote:


 
 This doesn't make sense.  You say class A needs to be extended with
 another class, however what you show below is class A extending
 framework_class.
 

I worded it wrong, I apologize.
Class A needs to be an extension of the framework class.

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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



[PHP] Multiple return statements in a function.

2009-04-23 Thread Peter van der Does
I tend to put my return value in a variable and at the end of the
function I have 1 return statement.
I have seen others doing returns in the middle of the function.

Example how I do it:
function check($a) {
  $return='';
  if ( is_array( $a ) ) {
$return='Array';
  } else {
$return='Not Array';
  }
  return $return;
}

Example of the other method:
function check($a) {

  if ( is_array( $a ) ) {
return ('Array');
  } else {
return ('Not Array');
  }
}

What is your take? And is there any benefit to either method?


-- 
Peter van der Does

GPG key: E77E8E98
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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



Re: [PHP] What is wrong with this code

2009-04-03 Thread Peter van der Does
On Fri, 3 Apr 2009 15:08:45 -0400
Gary gwp...@ptd.net wrote:

 This is driving me nuts.  I am getting blank emails and the only
 information that is being passed to MySQL is the IP address.
 
 Can someone tell me what is wrong with this?
 

If this is in one file, as I assume it is, here's what is happening:
In browser type the URL.
Load page.
Show form.
Send email.
Echo.
Done

You should check if information is send and if it's not don't process
the $_POST cause the $_POST is empty.

Simplified:
form method=post action=?php echo $_SERVER['PHP_SELF']; ?
 div id=important style=visibility:hidden;
   pIf you can see this, it's an anti-spam measure.  Please don't
   fill in the address field./p
   label for=addressAddress/label
   input type=text name=address id=address //div

   label for=nameName:/label
   input name=name type=text /br /
   label for=emailEmail Address:/label
input name=email type=text /
br /
label for=nameComments:/label
textarea name=comments cols=50 rows=/textarea
input name=submit type=button value=submit //form

?php

if ( isset( $_POST['submit'] ) ) {
// Receiving variables


$ip= $_SERVER['REMOTE_ADDR'];
... all other stuff

echo 'Thank you $name for submitting your inquiry!br /';
echo 'You have supplied the following information:br /';
echo 'Name: $name br /';
echo 'Email Address: $email br /';
echo 'Comments: $comments';
}
?

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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



[PHP] ltrim behavior.

2009-03-11 Thread Peter van der Does
This might be old for some of you but I never encountered it until
today and I would like to know why this is happening.

Here's the situation:
php  $a='data[options][name]';
php  echo ltrim($a,'data[');
options][name]

Just as I expected.

Next one:
php  $a='options[options][name]';
php  echo ltrim($a,'options[');
][name]

UH, what?
Not exactly what I expected.

This works:
php  $a='options[options][name]';
php  echo ltrim(ltrim($a,'options'),'[');
options][name]

Can somebody explain the second behavior? Is this a known bug in PHP,
I'm running PHP 5.2.6 on Ubuntu.

-- 
Peter van der Does

GPG key: E77E8E98

WordPress Plugin Developer
http://blog.avirtualhome.com

GetDeb Package Builder/GetDeb Site Coder
http://www.getdeb.net - Software you want for Ubuntu

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



Re: [PHP] ltrim behavior.

2009-03-11 Thread Peter van der Does
On Wed, 11 Mar 2009 15:28:04 -0400
Paul M Foster pa...@quillandmouse.com wrote:

 On Wed, Mar 11, 2009 at 03:07:18PM -0400, Peter van der Does wrote:
 
  This might be old for some of you but I never encountered it until
  today and I would like to know why this is happening.
  
  Here's the situation:
  php  $a='data[options][name]';
  php  echo ltrim($a,'data[');
  options][name]
  
  Just as I expected.
  
  Next one:
  php  $a='options[options][name]';
  php  echo ltrim($a,'options[');
  ][name]
  
  UH, what?
  Not exactly what I expected.
  
  This works:
  php  $a='options[options][name]';
  php  echo ltrim(ltrim($a,'options'),'[');
  options][name]
  
  Can somebody explain the second behavior? Is this a known bug in
  PHP, I'm running PHP 5.2.6 on Ubuntu.
 
 Take a look at the documentation for ltrim():
 
 http://us2.php.net/manual/en/function.ltrim.php
 
 The string you're including as the second parameter to ltrim() is the
 *characters* you want to trim on, not the *character pattern*. If you
 think about it that way, it will make sense. Also one of the examples
 on the referenced documentation page does something similar to what
 you've cited. Work through that example, and you'll see.
 
 Paul
 
OK, the light bulb went on now. I did see it was characters, and not a
string, but for some reason it didn't get in my brain what the
consequence was.
Thanks and I apologize for the stupid question.


-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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