Re: [PHP] How safe is a .htaccess file?

2010-08-17 Thread Peter Lind
On 17 August 2010 22:35, Robert Cummings rob...@interjinn.com wrote:


 On 10-08-17 04:23 PM, Peter Lind wrote:

 On 17 August 2010 22:17, teddt...@sperling.com  wrote:

 Hi gang:

 The subject line says it all.

 How secure is a .htaccess file to store passwords and other sensitive
 stuff?

 Can a .htaccess file be viewed remotely?

 No, Apache won't serve it.

 It's a configuration setting though, and not a hard-coded feature.

Set by default in your apache2.conf file which you're rather unlikely
to mess with as that is not how you're setting up sites.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] How safe is a .htaccess file?

2010-08-17 Thread Peter Lind
On 18 August 2010 01:41, tedd t...@sperling.com wrote:
 At 4:23 PM -0400 8/17/10, Robert Cummings wrote:

 On 10-08-17 04:17 PM, tedd wrote:

 Hi gang:

 The subject line says it all.

 How secure is a .htaccess file to store passwords and other sensitive
 stuff?

 Can a .htaccess file be viewed remotely?

 It depends on the server configuration. I think for the most part apache
 servers disable viewing these files by default. But, in any event, when
 these include access restriction, I always point it at a user/password file
 outside the web tree.

 Cheers,
 Rob.
 --

 Rob:

 When you're on a shared hosting account, they typically prohibit files being
 outside of the web root. Some do, some don't. For example, GoDaddy.com
 prohibits files outside of the web root while Parasane.net doesn't, at least
 my experience with my accounts.

 I'm simply trying to find the best method to hide sensitive information on
 a shared hosting environment. Thus far, it appears that .htaccess files are
 the safest bet, but I understand that nothing is certain -- every method has
 risks.

Try accessing a .htaccess file that you have created - if you get a
403 or anything to that effect, you're safe. You might also want to
try the same with .htpasswd and .htgroups (they'll likely be blocked
as well, but better safe than sorry). That way you'll actually know if
they're safe instead of just relying on our guesses about your
servers.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] tutorial failure

2010-08-18 Thread Peter Lind
On 18 August 2010 10:44, e-letter inp...@gmail.com wrote:
 Readers,

 Copy below of message sent 15 August to php install digest list, but
 to date not including in mail archive?

 The tutorial example:

 html
      head
              titlephp test
              /title
      /head
      body
              ?php
                      echo 'pHi, I am a PHP script/p';
              ?
              p
              this is a test
              /p
      /body
 /html

 is saved to the normal user temporary folder as 'test.php' and then
 copied to the folder '/var/www/html/' using the root user account. The
 web browser is directed to url 'http://localhost.test.php, to show:

 Hi, I am a PHP script

 '; ?

 this is a test

 What is the error please?

Looks like a problem with quotes, I'd say.

 Urpmi was used to install so the php version installed is not known.
 How to obtain this please

Check with php -i from the command line or a script containing
phpinfo(); requested through the browser.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] tutorial failure

2010-08-18 Thread Peter Lind
On 18 August 2010 12:47, e-letter inp...@gmail.com wrote:
 On 18/08/2010, chris h chris...@gmail.com wrote:
 php is not processing the file.  There's a few reasons for this, but the
 first thing I would check is the permissions of the file.  From the
 directory try

 $ ls -oa

 The file permission was confirmed as root, since it was copied (as
 root) from a normal user account directorp 'temporary' to the
 directory '/var/www/html'

 This should tell you who owns the file and what it's permissions are.  You
 mentioned that you copied it as root, you could change it's ownership to
 www-data.

 This fails:

 [r...@localhost html]# chown www-data test.php
 chown: `www-data': invalid user

 So I repeated this with a normal user account and the change in
 permission occurs. However, the html file containing the php script
 remains unchanged.

 The instruction:

 ...
 ?php phpinfo() ?
 ...

 Does not show the version of php.


Your webserver might not be configured to process php files - which
server are you using?

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Bitwise NOT operator?

2010-08-20 Thread Peter Lind
On 20 August 2010 17:10, Andy McKenzie amckenz...@gmail.com wrote:
 Hey everyone,

  I'm really not sure what's going on here:  basically, the bitwise
 NOT operator seems to simply not work.  Here's an example of what I
 see.

 Script

 $ cat bintest2.php

 ?php

 $bin = 2;
 $notbin = ~$bin;

 echo Bin:  . decbin($bin) .   !bin:   . decbin($notbin) . \n;
 echo Bin: $bin  !bin:  $notbin\n;


 ?
 =


 Output

 $ php bintest2.php
 Bin: 10  !bin:  1101
 Bin: 2  !bin:  -3

 =


 Obviously that's not the expected response.  I expect to get something
 more like this:

 Bin: 10  !bin:  01
 Bin: 2  !bin:  1


 Can anyone shed some light on this for me?  The server is running an
 old version of OpenSUSE, and php --version returns:


You probably need to read up on computer architechture and CS theory -
the ~ operator works fine, your understanding does not. What you're
looking at is the following:

$bin = 2 = 0010 (64 bit number)
~$bin = ~2 = -3 = 1101 (the inverse of the above)

Computers generally do not operate on a couple of bits from a byte -
they tend to operate on a byte, a word, a doubleword, etc (before any
nitpickers interrupt: sure, they can, but most operations don't).
Hence, you're not doing a not operation on just 10, you're doing it
on 0010. And as you are operating on a
signed int, you'll get a negative number out of the ~ operation
(seeing as you flipped the most significant bit).

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Bitwise NOT operator?

2010-08-20 Thread Peter Lind
On 20 August 2010 17:41, Peter Lind peter.e.l...@gmail.com wrote:
 On 20 August 2010 17:10, Andy McKenzie amckenz...@gmail.com wrote:
 Hey everyone,

  I'm really not sure what's going on here:  basically, the bitwise
 NOT operator seems to simply not work.  Here's an example of what I
 see.

 Script

 $ cat bintest2.php

 ?php

 $bin = 2;
 $notbin = ~$bin;

 echo Bin:  . decbin($bin) .   !bin:   . decbin($notbin) . \n;
 echo Bin: $bin  !bin:  $notbin\n;


 ?
 =


 Output

 $ php bintest2.php
 Bin: 10  !bin:  1101
 Bin: 2  !bin:  -3

 =


 Obviously that's not the expected response.  I expect to get something
 more like this:

 Bin: 10  !bin:  01
 Bin: 2  !bin:  1


 Can anyone shed some light on this for me?  The server is running an
 old version of OpenSUSE, and php --version returns:


 You probably need to read up on computer architechture and CS theory -
 the ~ operator works fine, your understanding does not. What you're
 looking at is the following:

 $bin = 2 = 0010 (64 bit number)

32-bit number, as Colin pointed out.

Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: How safe is a .htaccess file?

2010-08-24 Thread Peter Lind
On 24 August 2010 15:43, Gary php-gene...@garydjones.name wrote:
 Jan G.B. wrote:

 The weakness of MD5 is mainly because MD5 collisions are possible.
 That means, that different strings can have the same MD5-hash...

 http://en.wikipedia.org/wiki/MD5#cite_note-1

It's worth noting that that essentially does not touch upon whether or
not MD5 can be considered safe or not as a means to store password
information. The researchers have discovered ways of crafting inputs
to easily find colliding hashes - they have not discovered any easy
means to craft an input that will collide with a given hash.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: How safe is a .htaccess file?

2010-08-24 Thread Peter Lind
On 24 August 2010 16:25, Jan G.B. ro0ot.w...@googlemail.com wrote:
 2010/8/24 Bob McConnell r...@cbord.com:
 From: Peter Lind

 On 24 August 2010 15:43, Gary php-gene...@garydjones.name wrote:
 Jan G.B. wrote:

 The weakness of MD5 is mainly because MD5 collisions are possible.
 That means, that different strings can have the same MD5-hash...

 http://en.wikipedia.org/wiki/MD5#cite_note-1

 It's worth noting that that essentially does not touch upon whether or
 not MD5 can be considered safe or not as a means to store password
 information. The researchers have discovered ways of crafting inputs
 to easily find colliding hashes - they have not discovered any easy
 means to craft an input that will collide with a given hash.

 That's a simple matter of brute force, which can be done once and saved
 for instant use later. However, putting a salt into your algorithm
 pretty much eliminates the chances of success using that attack.

 Bob McConnell

 Thanks..
 actually it's quite annoying when you post an answer which
 tries to explain a subject and people just post a link as
 response to one citation which somehow lacks relevance on the topic.


The link posted was all the relevance there is. MD5 is not weak in the
sense that it is easy to find collisions when all you have is a hash
(which is what you were implying). MD5 is only weak in the sense that
it's possibly to generate two input texts such that the MD5 hashes of
both will collide.
 The other weakness of MD5 (the more relevant one here) is that
calculating an MD5 hash is relatively fast today. Which means you can
generate rainbow tables of the most common inputs in relatively little
time. Of course, these rainbow tables are worthless against more
secure passwords and/or against salted passwords.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Bitwise NOT operator?

2010-08-25 Thread Peter Lind
Please stop arguing this pointless topic on the php mailing list.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Web application architecture (subdomain vs. sub directory)

2010-08-25 Thread Peter Lind
On 25 August 2010 20:54, Ashley Sheridan a...@ashleysheridan.co.uk wrote:
 On Wed, 2010-08-25 at 13:45 -0500, Tim Martens wrote:

 If you're new to PHP, I would recommend not using a framework for the
 experience you will gain with the language, as a framework will tend to
 hide away certain caveats and peculiarities of PHP which could lead to
 issues further down the line. Most people I know who are great PHP
 programmers have tended to start without frameworks at first.

 Having said that, if you're looking for a rapid deployment with a
 shorter learning curve, then a framework might be better in this
 situation.


You could also argue that using a framework is more likely to promote
good habits, as there's a bigger chance you'll be forced down good
paths.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Web application architecture (subdomain vs. sub directory)

2010-08-26 Thread Peter Lind
On 26 August 2010 08:08, Per Jessen p...@computer.org wrote:
 Tim Martens wrote:

 Thanks for all your answers. To clarify my question, I'm looking for
 advice regarding how best to set up users for a web app, e.g.,
 username.myapp.com vs myapp.com/username and the pros and cons of
 each.

 Using username.myapp.com means defining that name in your DNS and having
 a separate virtual host definition in your apache config.


While offtopic and nothing to do with PHP I think this should be
corrected: you can set a *.yourdomain rule which matches all
subdomains not explicitly set. So no, you do not need to define every
single name as a DNS record.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Questions about $_SERVER

2010-08-28 Thread Peter Lind
On 28 August 2010 23:45, tedd tedd.sperl...@gmail.com wrote:
 At 9:41 PM +0200 8/28/10, Per Jessen wrote:

 tedd wrote:
  

  So, how can I identify the exact location of the 'server_addr' and of
  the 'remote_addr' on shared hosting? Is that possible?

 $_SERVER['SERVER_NAME'] will tell you the name of the virtual host - I
 don't know if that is what you're after.

 --
 Per Jessen, Zürich (12.2°C)

 Certainly, $_SERVER['SERVER_NAME'] will tell you the name of the virtual
 host, but what about the virtual remote?

 You see, I can have a script on one server communicate with another script
 on a another server and the remote addresses reported on either will not
 translate back to their respective virtual hosts, but instead to their
 hosts.

 So, I'm trying to figure out a compliment to $_SERVER['SERVER_NAME'] such as
 something like $_SERVER['REMOTE_NAME'].

 Is there such a beast?


You're not making any sense. For the script on your local host to be
able to connect and communicate with the remote host, it would need to
know the name of the remote host. Hence, the local host already knows
the name and has no reason to ask the remote host for a name by which
to contact it.
 That's what I get from your description of the problem. You probably
want to clarify some things.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Put all class in one file or different files

2010-08-29 Thread Peter Lind
On 29 August 2010 08:14, Haulyn Jason saharab...@gmail.com wrote:
 On 08/29/2010 02:04 PM, Eric Cash wrote:

 I'm out and about right
 now, so I can't link you to the autoload documentation page

 Thanks Eric, I have read the autoload document, but not pay attention on it.
 I will search more about it now, thanks.


For maintainability: 1 class, 1 file
For performance: all critical/core class in same file (i.e. the ones
you WILL load no matter what), the rest loaded as needed

It's a tradeoff. If you don't know which to pick, go with 1 class, 1 file.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread Peter Lind
On 29 August 2010 08:08, Jim Lucas li...@cmsws.com wrote:

*snip*

 Their is not existing variable (if you would) that your server, when
 connecting to a remote server, would be sending.  So, to have the remote end
 be able to identify the initiating host identity, the initiating side would
 have to add some something to the headers or pass it along in the body of
 the request itself.


+1. Let the requestion script send through identification/authentification.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread Peter Lind
On 29 August 2010 18:04, Per Jessen p...@computer.org wrote:
 Jason Pruim wrote:

 My understanding of how shared hosting works would make this near
 impossible... Basically Apache grabs a header that is sent at the
 initial connection which includes the destination hostname and from
 there it translates it to the proper directory on the shared host.

 All the IP's though are based off of the parent site's server...

 Now with dedicated hosting where you have the entire machine you can
 do what you are looking at because the IP address will always
 translate back to your website.


The HTTP protocol does not provide a domain among the request header
fields - you need to implement idenfication/authentication in a
different manner (preferably in a way that does not rely upon IP
addresses, seeing as that doesn't provide any reliable sort of
identification).

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Secure Communication?

2010-08-29 Thread Peter Lind
On 29 August 2010 18:24, tedd t...@sperling.com wrote:
 Hi gangl:

 I realize that the problem stated herein has been solved by others, so I'm
 not claiming I've done anything new -- it's only new to me. It was a
 learning experience for *me* and my solution may help others.

 In any event, I've finished creating a method for establishing what I think
 is secure communication between two servers. I've written two scripts that
 run on different servers, which confirm communication between them via
 hard-wired urls and creating/writing/reading a url-confirmation file.

 The purpose of this exercise was to simply to keep database-access data
 (i.e., user_name, password, key to decryption) secret. However, the secret
 could be anything you want to keep secret -- secret being defined as no data
 residing on the server of concern while allowing that server access to the
 data when needed and under authorization.

 Here's what I've done -- I have two domains, namely webbytedd.com (the
 Master) and php1.net (the Slave) -- both domains reside on different
 servers. The domain names really don't matter, it's just that this method
 currently works between those two domains.

 Statement of Requirements:

 1. The Master requires access to it's database.

 2. The Slave keeps access to Master's database in it's own database.

 3. It's required that access remain secret in the event that the Master is
 hacked.

 *The term access above is defined as database-access data, such as
 user_name, password, and key to decryption.

 Description of Method:

 1. When the Master wants access to it's database, it first creates a
 url-confirmation file and writes a token to that file, which resides on the
 Master. I've used time() as the token, but the token could be any variable
 -- it really doesn't make much difference other than the value should be
 different each time.

 2. The Master then sends a cURL request to the Slave via a POST where the
 POST variable contains the token.

 3. The Slave when receiving the POST request from Master reads the token
 from the newly created url-confirmation file residing on the Master and then
 compares that token with the token provided by the POST -- if the tokens
 match, then the Slave returns the access to the Master. If not, the
 process fails.

 4. After receiving access the Master deletes the url-confirmation file and
 continues with it operation. If the Master does not receive access then it
 deletes the url-confirmation file and exits.

 This method sounds simple enough and does several things.

 1. There is no access stored on the Master.

 2. While the Slave has access for the Master stored in its database, the
 access to the Slave's database is kept in an out-of-root (not open to the
 web) file. Note, in this case, this was not possible on the Master because
 the host did not allow out-of-root files -- but that is only tangential to
 the problem addressed here.

 3. If a hacker did obtain access to the Slave database, then the hacker
 would discover the contents have been encrypted and only the Master has the
 decryption key kept in it's database.

 4. If a hacker did obtain access to the code residing on the Master, then
 the hacker could not access the Master's database because the access data
 is recorded on another server (i.e., Slave). Furthermore, the hacker could
 not get the code to run anywhere else because the Slave's look-up URL for
 the url-confirmation file is hardwired to the Master address.

 5. And lastly, all communication between both domains is done via https.

 Now, for the exception of both server's being hacked at the same time, what
 could go wrong?

A) I wouldn't want to reinvent the wheel but would use
SSL/certificates/something to that effect (it's a whole lot more
secure than your setup), and B) there's nothing in this setup that
secures you from someone hacking Master and just sucking out data from
that machine.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Questions about $_SERVER

2010-08-30 Thread Peter Lind
On 30 August 2010 21:32, Paul M Foster pa...@quillandmouse.com wrote:
 On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote:

 Jason Pruim wrote:

  My understanding of how shared hosting works would make this near
  impossible... Basically Apache grabs a header that is sent at the
  initial connection which includes the destination hostname and from
  there it translates it to the proper directory on the shared host.
 
  All the IP's though are based off of the parent site's server...
 
  Now with dedicated hosting where you have the entire machine you can
  do what you are looking at because the IP address will always
  translate back to your website.

 AFAICT, Tedd was not asking about the server, he's asking about the
 client.

 No, he's talking about the server. But the server he's using may offload
 the processing of a script to another machine. So

 $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME']

 both relate to the server which the client is originally communicating
 with. But he wants to know if he can get the same information about a
 different remote server which is processing a script for him. The
 problem is that we have:

 $_SERVER['REMOTE_ADDR']

 but no

 $_SERVER['REMOTE_NAME']

 So the question is, how would he get that last variable. It becomes
 complicated when using a shared hosting environment, because server
 names and IPs aren't a 1:1 mapping. An IP may represent numerous actual
 site names. This was part or all of the reason why the http protocol was
 revised from 1.0 to 1.1-- in order to accommodate all the domains, which
 because of the cramped IP space of IPv4, had to share IPs. So in the
 HTTP 1.1 protocol, there is additional information passed about the name
 of the domain.


In the scenario painted, it's explicitly stated that one server acts
as a client in trying to access a resource on another server. Could
you enlighten me as to where the domain name of a client is located in
the request header fields? Here's the RFC for HTTP 1.1
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Questions about $_SERVER

2010-08-30 Thread Peter Lind
On 30 August 2010 22:34, Paul M Foster pa...@quillandmouse.com wrote:
 On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote:

 On 30 August 2010 21:32, Paul M Foster pa...@quillandmouse.com wrote:
  On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote:
 
  Jason Pruim wrote:
 
   My understanding of how shared hosting works would make this near
   impossible... Basically Apache grabs a header that is sent at the
   initial connection which includes the destination hostname and from
   there it translates it to the proper directory on the shared host.
  
   All the IP's though are based off of the parent site's server...
  
   Now with dedicated hosting where you have the entire machine you can
   do what you are looking at because the IP address will always
   translate back to your website.
 
  AFAICT, Tedd was not asking about the server, he's asking about the
  client.
 
  No, he's talking about the server. But the server he's using may offload
  the processing of a script to another machine. So
 
  $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME']
 
  both relate to the server which the client is originally communicating
  with. But he wants to know if he can get the same information about a
  different remote server which is processing a script for him. The
  problem is that we have:
 
  $_SERVER['REMOTE_ADDR']
 
  but no
 
  $_SERVER['REMOTE_NAME']
 
  So the question is, how would he get that last variable. It becomes
  complicated when using a shared hosting environment, because server
  names and IPs aren't a 1:1 mapping. An IP may represent numerous actual
  site names. This was part or all of the reason why the http protocol was
  revised from 1.0 to 1.1-- in order to accommodate all the domains, which
  because of the cramped IP space of IPv4, had to share IPs. So in the
  HTTP 1.1 protocol, there is additional information passed about the name
  of the domain.
 

 In the scenario painted, it's explicitly stated that one server acts
 as a client in trying to access a resource on another server. Could
 you enlighten me as to where the domain name of a client is located in
 the request header fields? Here's the RFC for HTTP 1.1
 http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3

 From http://www8.org/w8-papers/5c-protocols/key/key.html:

 === EXCERPT ===

 Internet address conservation

 Companies and organizations use URLs to advertise themselves and their
 products and services. When a URL appears in a medium other than the Web
 itself, people seem to prefer ``pure hostname'' URLs; i.e., URLs without
 any path syntax following the hostname. These are often known as
 ``vanity URLs,'' but in spite of the implied disparagement, it's
 unlikely that non-purist users will abandon this practice, which has led
 to the continuing creation of huge numbers of hostnames.

 IP addresses are widely perceived as a scarce resource (pending the
 uncertain transition to IPv6 [DH95]). The Domain Name System (DNS)
 allows multiple host names to be bound to the same IP address.
 Unfortunately, because the original designers of HTTP did not anticipate
 the ``success disaster'' they were enabling, HTTP/1.0 requests do not
 pass the hostname part of the request URL. For example, if a user makes
 a request for the resource at URL http://example1.org/home.html, the
 browser sends a message with the Request-Line

    GET /home.html HTTP/1.0

 to the server at example1.org. This prevents the binding of another HTTP
 server hostname, such as exampleB.org to the same IP address, because
 the server receiving such a message cannot tell which server the message
 is meant for. Thus, the proliferation of vanity URLs causes a
 proliferation of IP address allocations.

 The Internet Engineering Steering Group (IESG), which manages the IETF
 process, insisted that HTTP/1.1 take steps to improve conservation of IP
 addresses. Since HTTP/1.1 had to interoperate with HTTP/1.0, it could
 not change the format of the Request-Line to include the server
 hostname. Instead, HTTP/1.1 requires requests to include a Host header,
 first proposed by John Franks [Fra94], that carries the hostname. This
 converts the example above to:

    GET /home.html HTTP/1.1
            Host: example1.org

 If the URL references a port other than the default (TCP port 80), this
 is also given in the Host header.

 Clearly, since HTTP/1.0 clients will not send Host headers, HTTP/1.1
 servers cannot simply reject all messages without them. However, the
 HTTP/1.1 specification requires that an HTTP/1.1 server must reject any
 HTTP/1.1 message that does not contain a Host header.

 The intent of the Host header mechanism, and in particular the
 requirement that enforces its presence in HTTP/1.1 requests, is to speed
 the transition away from assigning a new IP address for every vanity
 URL. However, as long as a substantial fraction of the users on the
 Internet use browsers that do not send Host, no Web site operator

Re: [PHP] require_once

2010-09-01 Thread Peter Lind
On 1 September 2010 08:00, David Mehler dave.meh...@gmail.com wrote:
 Hello,
 I've got probably a simple question on require_once. I've got a file
 that has require_once at the top of it pulling in another file of
 functions. Later on in this file I've got another require_once
 bringing in a second file. In this second file I have a function call
 to a function defined in the first files' top require_once functions
 file. I'm getting a call to undefined function.
 Should I change he require_once to require at the top of the first
 file to fix? I thought require_once meant it was in that file and
 anything pulled in later?
 Thanks.
 Dave.

The file is included properly, otherwise your script would halt.
You're likely looking at an issue of scope: the functions might be
included in a scope you don't expect them to be.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: require_once

2010-09-02 Thread Peter Lind
On 2 September 2010 12:55, Jangita jang...@jangita.com wrote:
 On 01/09/2010 10:56 p, freem...@centrum.cz wrote:

 I think the files included just when you call it to include. How do you
 mean
 it later?
 What's in that file? A class or direct code?

 David Mehler wrote:

 Hello,
 I've got probably a simple question on require_once. I've got a file
 that has require_once at the top of it pulling in another file of
 functions. Later on in this file I've got another require_once
 bringing in a second file. In this second file I have a function call
 to a function defined in the first files' top require_once functions
 file. I'm getting a call to undefined function.
 Should I change he require_once to require at the top of the first
 file to fix? I thought require_once meant it was in that file and
 anything pulled in later?
 Thanks.
 Dave.



 If i get you correctly

 file1.php has a require_once to file2.php
 then file 1.php has a require_once to file3.php
 but file3.php calls a function in file2.php

 answer would be to require_onec file2.php in file3.php

Which wouldn't do anything seeing as file2.php has already been
included by file1.php.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: require_once

2010-09-02 Thread Peter Lind
On 2 September 2010 13:20, Jangita jang...@jangita.com wrote:
 On 02/09/2010 12:59 p, Peter Lind wrote:

 Which wouldn't do anything seeing as file2.php has already been
 included by file1.php.

 Amazing! I didn't think that once you include a file; any other file
 included also includes any earlier included files (if that makes any sence)

 I've always thought includes are local; I.e in order to use a function from
 another file explicitly include that other file.

You're thinking about it from the wrong perspective. It's not a
question of a file including another file into it's own space, it's a
question of scope. If you're in the global scope, any file included
will get included into the global scope. If you're in a local scope
however, then other rules apply: variables in the file (that would
normally be in the global scope if you just executed the file) will be
in the local scope only, while classes and functions in the included
file will be imported into the global scope.

Also, require_once will require a file once only. Using it to require
the same file again from anywhere else will fail to include the file -
that's the whole point of _once.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



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

2010-09-15 Thread Peter Lind
On 15 September 2010 14:46, Peter van der Does pvanderd...@gmail.com wrote:
 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.


3. Constant, as long as you're dealing with scalars.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Session Vars loaded from MSSQL Query drop, those loaded from MYSQL Query stick

2010-09-16 Thread Peter Lind
On 16 September 2010 16:26, Cheryl Sullivan csull...@shh.org wrote:
 Absolutely -



 This is from the first page



 ?php

 $_SESSION['UserLastName'] = strtolower(trim($_POST['txtLastName']));

 $_SESSION['BadgeID'] = trim($_POST['txtBadgeID']);



 //access MS SQL Server database

 $q1 = select * from emps where emp_last =
 '.$_SESSION['UserLastName'].' and emp_badge =
 '.$_SESSION['BadgeID'].';

 $rs_emp_info = hitMSSQL($q1,_sql,database,table,password,1);

 $_SESSION['SSN'] = $rs_emp_info-fields(emp_ssn);

 $_SESSION['CostCenter'] = $rs_emp_info-fields(emp_costcenter);


You're sticking values from $_POST into an SQL query without
sanitizing them first. That spells out SQL INJECTION VULNERABILITY.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Session Vars loaded from MSSQL Query drop, those loaded from MYSQL Query stick

2010-09-16 Thread Peter Lind
On 16 September 2010 20:03, Cheryl Sullivan csull...@shh.org wrote:
 We are actually running the query through a function that removes single
 ticks, etc to avoid this, but I didn't think that was relevant to the
 question so I didn't include it.  Thanks, though!

You're the one with the problem you don't understand, which means you
don't get to make decisions as what is or is not relevant. Rather: you
have no idea what seems relevant to us trying to pinpoint the error.

That said, if - like Andrew points out - you see the values directly
after storing them, then the problem is not database related. What
exactly happens between the two pages and on the second page?

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] GD Watermark Question

2010-09-19 Thread Peter Lind
On 19 September 2010 16:05, tedd tedd.sperl...@gmail.com wrote:
 At 6:03 PM -0400 9/17/10, Gary wrote:

 Is there a way to insert a watermark on an image as it is being uploaded
 to
 the image file, then removed when it is called from a database to be
 viewed
 on a website?

 The rational behind this is I have a photographers site I am doing, and I
 am
 limiting the size of the images somewhat to reduce pilferage and I would
 like to be able to show the images a little larger, hence with a bit more
 clarity and detail.

 Thanks for your input.

 Gary

 Gary:

 Don't complicate this process more than necessary.

 Simply upload the image file normally and store it in the file system OR the
 database.

 When you want to show the image as a thumbnail, then show it. Here's the
 code:

 http://webbytedd.com/b/thumb/

 If you want to show it with a watermark, then show that. Again, here's the
 code:

 http://webbytedd.com/b/watermark/

 If you want to show the image as a thumbnail with a watermark, then combine
 the two routines. I'll leave that to you.


You're generating the thumbnail on every request. Just generate it
once and serve the thumbnail as a file (there's no reason why you
would need to invoke php to show a thumbnail of an image).
Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Auto-generating HTML

2010-09-20 Thread Peter Lind
On 20 September 2010 21:56, Andy McKenzie amckenz...@gmail.com wrote:
 On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto r...@niof.net wrote:
 On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote:

 On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote:

  Hey folks,
 
   I have the feeling this is a stupid question, but I can't even find
  anything about it.  Maybe I'm just not searching for the right things.
 
   Here's the problem.  I'm writing a lot of pages, and I hate going in
  and out of PHP.  At the same time, I want my HTML to be legible.  When
  you look at it, that's kind of a problem, though... for instance
  (assume this had some PHP in the middle, and there was actually a
  reason not to just put this in HTML in the first place):
 
  Simple PHP:
  ?php
 
  echo 'html';
  echo 'head';
  echo '  titlePage Title/title';
  echo '/head';
  echo 'body';
  echo 'pThis is the page body/p';
  echo '/body';
  echo '/html';
 
  ?
 
 
  Output page source:
  htmlhead  titlePage Title/title/headbodypThis is the
  page body/p/body/html
 
 
  Now, I can go through and add a newline to the end of each line (echo
  'html' . \n; and so on), but it adds a lot of typing.  Is there a
  way to make this happen automatically?  I thought about just building
  a simple function, but I run into problem with quotes -- either I
  can't use single quotes, or I can't use double quotes.  Historically,
  I've dealt with the issue by just having ugly output code, but I'd
  like to stop doing that.  How do other people deal with this?
 
  Thanks,
   Alex

 Alex

 Just add a \n at the end as

 echo 'html\n';

 That will not work. Single quotes means that the '\n' is not interpreted
 as a new line so you'll see a bunch of '\n' in the output.

 What I sometimes do is:

 $out = array();
 $out[] = 'html';
 $out[] = 'head';
 $out[] = '  titlePage Title/title';
 $out[] = '/head';
 $out[] = 'body';
 $out[] = 'pThis is the page body/p';
 $out[] = '/body';
 $out[] = '/html';
 echo join(\n,$out);


 Interesting.  I hadn't thought of that, but it could work.  It'd still
 be quite a bit of extra typing, but at least I find it more
 readable...


Ash already mentioned it: heredoc format. Much easier, less typing,
easier to read, keeps formatting, etc, etc etc.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Database Administration

2010-09-21 Thread Peter Lind
On 21 September 2010 11:48, Tom Barrett t...@miramedia.co.uk wrote:
 Hi

 I need to build a custom client management app, which will build and manage
 a database per client. This means that on top of the usual sql crud, it
 needs to be able to create databases, add/edit/delete database users, create
 tables.

 Is there a way for me to do this nicely as PHP solution? am I better off
 incorporating non PHP pieces into this (e.g. shell)? or should I leave the
 admin tasks (e.g. database creation) as a 'normal' administrative task
 (commandline/webmin/watever)?


Seeing as all the extra stuff you need is just plain sql commands, I
don't see the problem as such. You just need to make sure access to
the tool is done right (i.e. a user that can create/destroy databases
needs to be aware of this and you need to restrict the access to those
specific persons).

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Copying an Object

2010-09-23 Thread Peter Lind
On 23 September 2010 02:14, Daniel Kolbo kolb0...@umn.edu wrote:

*snip*

 On 9/22/2010 9:11 AM, chris h wrote:
 Say you have two classes: human and male.  Further, say male extends
 human.  Let's say you have a human object.  Then later you want to make
 that human object a male object.  This seems to be a pretty reasonable
 thing to request of our objects.

Perhaps if you're a C# programmer, but the PHP way of thinking is
radically different.
C#: This object is whatever it was currently cast to (if possible)
PHP: This object is this object, whatever it was created as

If you have a need to make an object switch class in PHP, then there's
a 99% chance you're working against, not with the language.

  This type of thing would especially be
 easy if objects of parent classes could be cast as an object of its
 extended class.

I'll hazard a guess and say you didn't start programming in PHP but in
something else.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Heredocs, print_r() and newline \n and fnmatch() - curious failures ...

2010-09-24 Thread Peter Lind
On 23 September 2010 21:47, YAD(YetAnotherDavid) ani...@mail.com wrote:
 This code is 95% cut and paste from the PHP manual examples -
 the Types/Strings/Heredocs section and the Filesystem/fnmatch pages.
 There are actually two questions here - I have combined the code into one
 test file ... the strings in the code contain the questions ..
 at the end I have inserted the output I get from the code - identical in
 Firefox and IE8 (so it's not browser related), and on my desktop as well as
 my laptop (so it's not a machine quirk). The setup is Xammplite Win32-1.7.1
 with PHP 5.2.9 and Apache 2.2.11 on both WinXP-SP3 installs.

 I tried Xammp Win32-1.7.3 with the same results. Then I tried installing
 Apache and PHP and MySQL individually, and got the same ...
 Aside from the issue here, I also was unable to get imagick and xdebug
 running on the same installation - it was one or the other. imagick's
 readfile() caused Apache to baulk on PHP5.3.3, so I returned to a fresh
 Xammplite setup. Same results.

 I have spent many hours with this - I would appreciate some insight ..

 Question 1 : how to get the newline functioning ? even print_r() output
 is not 'newlined' as it should be. Also note the \n is missing between the 
  in the output text of the second test!


Are you outputting to browser or to command line? Browsers have a
habit of ignoring whitespaces, reducing them to one whitespace
character regardless of their type or how many.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Copying an Object

2010-09-24 Thread Peter Lind
On 24 September 2010 14:22, Bob McConnell r...@cbord.com wrote:
 From: David Hutto

 On Fri, Sep 24, 2010 at 4:09 AM, Gary php-gene...@garydjones.name wrote:
 Daniel Kolbo wrote:

 Say you have two classes: human and male.  Further, say male extends
 human.  Let's say you have a human object.  Then later you want to make
 that human object a male object.  This seems to be a pretty reasonable
 thing to request of our objects.

 I don't think any human can change gender without major surgery, but I
 don't know if you just chose your example badly or whether you really
 think objects should be able to mutate into other types of object
 without some kind of special treatment.

 But it would work in something like makehuman, where you start with a neuter
 form and scale one way or the other for physical features. If I
 remember correctly,
 we're' all xx until you become xy(genetically speaking).

 This is one of the details that really bothers me about OOP. It makes it 
 impossible to implement some very reasonable scenarios. 80% of the time, when 
 a patron is added to a system, we don't know which gender they are. More than 
 50% of the time, we will never know, since the client doesn't keep track of 
 it. But the rest of them will be assigned sometime after they were added. 
 i.e. the gender assignment comes from a secondary source that is not 
 available at the time the patron is entered.


If you can't handle that, it's not the fault of OOP but your lack of
programming skills in OOP I'd say (and I mean no disrespect there, I'm
just pretty sure your scenario can be handled very easily in OOP).

And no, I have no urge to defend OOP in PHP, I just see this entire
thread as a complete non-starter: if the language doesn't let you do
something in a particular way, how about you stop, take a breather,
then ask if perhaps there's a better way in the language to do what
you want done? That would normally be a much more productive and
intelligent response than either a) pressing on in the face of failure
or b) complaining about your specific needs and how the language fails
to meet them.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Copying an Object

2010-09-25 Thread Peter Lind
On 25 September 2010 00:11, Daniel Kolbo dko...@gmail.com wrote:
 On 9/24/2010 8:35 AM, Peter Lind wrote:
 On 24 September 2010 14:22, Bob McConnell r...@cbord.com wrote:
 From: David Hutto

 On Fri, Sep 24, 2010 at 4:09 AM, Gary php-gene...@garydjones.name wrote:
 Daniel Kolbo wrote:

 Say you have two classes: human and male.  Further, say male extends
 human.  Let's say you have a human object.  Then later you want to make
 that human object a male object.  This seems to be a pretty reasonable
 thing to request of our objects.

 I don't think any human can change gender without major surgery, but I
 don't know if you just chose your example badly or whether you really
 think objects should be able to mutate into other types of object
 without some kind of special treatment.

 But it would work in something like makehuman, where you start with a 
 neuter
 form and scale one way or the other for physical features. If I
 remember correctly,
 we're' all xx until you become xy(genetically speaking).

 This is one of the details that really bothers me about OOP. It makes it 
 impossible to implement some very reasonable scenarios. 80% of the time, 
 when a patron is added to a system, we don't know which gender they are. 
 More than 50% of the time, we will never know, since the client doesn't 
 keep track of it. But the rest of them will be assigned sometime after they 
 were added. i.e. the gender assignment comes from a secondary source that 
 is not available at the time the patron is entered.


 If you can't handle that, it's not the fault of OOP but your lack of
 programming skills in OOP I'd say (and I mean no disrespect there, I'm
 just pretty sure your scenario can be handled very easily in OOP).

 And no, I have no urge to defend OOP in PHP, I just see this entire
 thread as a complete non-starter: if the language doesn't let you do
 something in a particular way, how about you stop, take a breather,
 then ask if perhaps there's a better way in the language to do what
 you want done? That would normally be a much more productive and
 intelligent response than either a) pressing on in the face of failure
 or b) complaining about your specific needs and how the language fails
 to meet them.

 Regards
 Peter


 I would consider the post to be a discussion among the community to
 discuss possible improvements for php, to help progress the language to
 handle the situations faced by the users of the language, and hey maybe
 learn something along the way.  I certainly wouldn't consider the post
 to be an avenue to belittle members of the community.  For some it's
 half empty, for others half full.
 `

I apologize for the wording of my post - I did not intend to belittle anyone.

Your posts seem to me, however, rather typical: I am coming up
against this problem, why doesn't the language let me solve it the way
I want it to? - something this last response also suggests (I would
consider the post to be a discussion among the community to discuss
possible improvements for php). Many people have already pointed out
that there's likely a much better solution to the problem at hand, yet
you still insist that the language should be improved (the latest idea
being a __cast() function) - and I cannot see you once commenting on
the composition strategy. Was the ... and hey maybe learn something
along the way. meant only for others?

Anyway, seeing as my glass is half-empty and I'm not adding anything
constructive to thread I'll refrain from posting more.

Regards
Peter
-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Heredocs, print_r() and newline \n and fnmatch() -curious failures ...

2010-09-27 Thread Peter Lind
On 24 September 2010 12:49, YAD(YetAnotherDavid) ani...@mail.com wrote:
 Peter Lind wrote:

 On 23 September 2010 21:47, YAD(YetAnotherDavid) ani...@mail.com wrote:

 This code is 95% cut and paste from the PHP manual examples -
 the Types/Strings/Heredocs section and the Filesystem/fnmatch pages.
 There are actually two questions here - I have combined the code into one

  ...

 Question 1 : how to get the newline functioning ? even print_r()
 output
 is not 'newlined' as it should be. Also note the \n is missing between
 the 
  in the output text of the second test!


 Are you outputting to browser or to command line? Browsers have a
 habit of ignoring whitespaces, reducing them to one whitespace
 character regardless of their type or how many.

 Regards
 Peter


 Thanks Peter, - output is to browser, I develop in Notepad++ and Firefox,
 and confirm in IE8. But this stuff used to work - I have been working with
 PHP for about two years (not pro) and am used to formatting my output for
 legibility - especially echoing or var_dumping variables when still testing
 the code. So the failure is recent and I just can't figure what changed.
 David

Browsers treat newlines as any other whitespace - so print_r and
var_dump will not, on their own, provide you with a linebreak in a
browser. If you've got xdebug installed, var_dump will provide a nicer
output (including line-breaks).
However, by far the easiest way to check if you're actually getting
linebreaks in your output is checking the source.

If you're suddenly experiencing a change in output, then some of your
environment variables have changed - hard to say which one without
knowing more about your system, but you must obviously have
changed/updated something for this to happen.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Friday's Post

2010-10-01 Thread Peter Lind
On 1 October 2010 17:11, Bob McConnell r...@cbord.com wrote:
 From: Gary

 tedd wrote:
 What do you people think of the .NET framework?

 It's a framework, like any other framework - can make your life
 easier,
 can make your life harder by forcing you to take the path determined
 as
 TOTP by its designers.

 That's The One True Path, not Top Of The Pops.

 The installer and the license limit its use to just a subset of a single
 platform. The attempts at producing clones on other platforms are
 clouded by license and patent restrictions, and will perpetually be at
 least one release behind the MS-Windows version.

 In reality, .Net is a poor clone of the Java runtime environment, while
 C# is a poor clone of the Java language. They were created after the
 courts told Microsoft the Sun license did not allow them to subvert the
 Java API to build applications that would only run on their OS.


C# has by now exceeded Java by quite a bit - and is, unlike Java, very
actively maintained and has fairly frequent releases with lots of new
functionality (4.0 was released this year and has functionality that
definitely makes me consider taking it on).

As for whether .Net is a better library than the JVM, I wouldn't be
able to judge that.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Friday's Post

2010-10-02 Thread Peter Lind
On 1 October 2010 20:21, Per Jessen p...@computer.org wrote:
 Peter Lind wrote:

 C# has by now exceeded Java by quite a bit -

 I've been away from the Java scene since 2002 (when I worked for BEA
 deploying J2EE on Linux/390), but assuming you're talking
 about deployed lines of code or some other real-life measurement, I
 find it hard to believe that C# should have exceeded Java.

Language functionality. I'd much rather use C# than Java as I can do
more in C# and easier than with Java. For instance, C# 4 has  support
for late binding to dynamic types. Does Java have an equivalent? Is
it planned?

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Friday's Post

2010-10-02 Thread Peter Lind
On 2 October 2010 11:05, Per Jessen p...@computer.org wrote:
 Peter Lind wrote:

 On 1 October 2010 20:21, Per Jessen p...@computer.org wrote:
 Peter Lind wrote:

 C# has by now exceeded Java by quite a bit -

 I've been away from the Java scene since 2002 (when I worked for
 BEA deploying J2EE on Linux/390), but assuming you're talking
 about deployed lines of code or some other real-life measurement, I
 find it hard to believe that C# should have exceeded Java.

 Language functionality. I'd much rather use C# than Java as I can do
 more in C# and easier than with Java. For instance, C# 4 has  support
 for late binding to dynamic types. Does Java have an equivalent? Is
 it planned?

 I don't know, but Java obviously supports late binding.


I was looking more for dynamic types, much more of interest to the
average PHP dev as that's one of the typical stumbling blocks when
switching languages. And no, far as I can tell Java doesn't offer
that.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] New to PHP and struggling with the basics

2010-10-04 Thread Peter Lind
On 4 October 2010 11:30, Col Day colind...@aol.com wrote:
 Hi all,

 Working with the PHP5 for Dummies book (yup real noob, feel free to ridicule
 (after telling me what I've done wrong)) and have installed Apache 2.2 and
 PHP 5.3.3 onto a laptop running Vista. (yes I know!!!).

 I've had Apache running fine with my basic web site created using Serif's
 Webplus10 but wanted to experiment with PHP as I want an uploadable area on
 my website for my friends and family to submit video/photos.

 I've checked the install of PHP using php -v and I get the output that

 PHP 5.3.3 (cli) (built: Jul 21 2010 20:10:20)

 but when I try and go to the test.php file (below) I get an http 403 webiste
 requires you to log in. Error message.

 html
 head
 titlePHP Test/title
 /head
 body
 pThis is an HTML line
 ?php
 echo pThis is a PHP line/p;
 phpinfo();
 ?
 /body
 /html

 This is the text of the test.php file which I have plonked down in
 /apache/htdocs

 What have I missed?

 the Dummies book is quoting PHP 5.0.0 as the latest release so not too far
 away really.


A) v5.0.0 is years old. B) your issue is with apache, not php - 403 is
a you have no permission to see this.

Check permissions for the file you're trying to test, as well as for
the folder. Also, seeing as you're naming the file test.php, make sure
you're browsing for that file and not just / or index.php.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] which one is faster

2010-10-06 Thread Peter Lind
On 6 October 2010 14:40, Bob McConnell r...@cbord.com wrote:
 From: Steve Staples

 On Tue, 2010-10-05 at 20:53 +0100, Ashley Sheridan wrote:
 On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:

  On Tue, 2010-10-05 at 20:35 +0100, Ashley Sheridan wrote:
   On Tue, 2010-10-05 at 15:28 -0400, chris h wrote:
  
Benchmark and find out! :)
   
What are you using this for? Unless you are doing something
 crazy it
probably doesn't matter, and you should pick whichever you feel
 looks nicer
/ is easier to code in / etc.
   
Chris H.
   
On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed
 saeed@gmail.com wrote:
   
 $a = 'hey';
 $b = 'done';

 $c = $a.$b;
 $c = $a$b;

 which one is faster for echo $c.

  
  
   As far as I'm aware, the first of the two will be faster, but
 only just.
   As Saeed mentioned, the difference will be negligible, and unless
 you
   plan to run a line like that in a loop or something hundreds of
   thousands of times, you probably won't notice any difference.
   Thanks,
   Ash
   http://www.ashleysheridan.co.uk
 
  to be proper, shouldn't it technically be
  $c = {$a}{$b};
 

 It doesn't have to use the braces. The braces only tell PHP exactly
 where to stop parsing the current variable name. The following
 examples
 wouldn't work without them:

 $var = 'hello ';
 $arr = array('msg 1'='hello','msg 2'='world');

 echo {$var}world;
 echo {$arr['msg 1']}{$arr['msg 2']};

 Without the braces, in the first example PHP would look for a
 variable
 called $varworld, and in the second it would be looking for a simple
 scaler called $arr, not the array value you wanted.

 Ash:

 I understand what the {} does, but just like in HTML, it is more
 proper
 to use lower case for the attributes/elements, and use  (double
 quotes)
 when wrapping the attributes... but is it not REQUIRED to write it
 in
 that manner... just like it is not required to wrap the variables in
 {}
 when inside the ...

 that's just me, I tend to try and do that every time...

 XHTML requires both lower case and double quotes. So if that may be in
 your future, you should be using both already.

 I don't know about HTML 5. Since that spec is still years away from
 completion and hasn't added anything we can make use of, we haven't even
 bothered to look at it.


Where exactly do you get the part about double quotes from? Can't seem
to locate it in the any of the relevant specs (xhtml or xml). Also,
never seen an xml or xhtml validator choke on single quotes.

As for html 5, it's in use today already. Big parts of it are unlikely
to change, so there's little reason not to start using it.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] which one is faster

2010-10-06 Thread Peter Lind
On 6 October 2010 15:31, Andy McKenzie amckenz...@gmail.com wrote:

*snip*

 Double quotes are the only example given:  in most documentation if
 there are two allowed forms, there are two examples, or at least a
 note in the text.  I haven't read enough of this particular document
 to know if they follow that form, but I've certainly seen it a lot of
 places.

 -Alex


Xhtml documents are xml documents and thus must follow the specs for
XML. Specifically, the following:
http://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Buffering output to allow headers late in code?

2010-10-14 Thread Peter Lind
Just out of curiosity: why were you told to switch off output buffering?

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] I need some thoughts on code duplication and separation

2010-10-21 Thread Peter Lind
On 21 October 2010 04:59, David McGlone da...@dmcentral.net wrote:
 On Thu, 2010-10-21 at 04:05 +0200, Rico Secada wrote:
 Hi.

 I am working on a small system where I am both trying to avoid code
 duplication and at the same time I am trying to keep the presentation
 logic separated from the application logic.

 I am using sessions and are avoiding headers already sent problem by
 keeping the HTML out of the application.

 For example, I would like to have a common header.php file, but it is
 difficult to create this since one file needs to have some specific
 Javascript located in the head /head tags, but the other files
 doesn't need this.

 Another file needs to have a specific onload call in the body tag,
 while yet another file also needs to have an onload call, but with
 different attributes.

 I have been looking around in other systems to see what kinds of
 solutions are being used - as inspiration.

 I have been thinking about the following solutions:

 1. Create only ONE header.php file that contains a lot of conditionals
 depending on what file is including it - the output of HTML/Javascript
 changes.

 I believe this would turn into a very ugly hack. Difficult to maintain.

 2. Create a HTML generating class with a set of methods that each
 contains an adequate amount of parameters. Each method maintains its
 own HTML tag. For example, docType($type) would generate the doctype
 specification.

 I believe this is a cleaner solution, but the problem with code
 duplication isn't avoided.

 Some of the presentation logic contains conditionals and the HTML
 changes when the conditional changes, hence the header content changes,
 but the doctype, html, and head doesn't necessarily change and
 they would get duplicated a couple of times in some files.

 3. Avoid the problem all together, use output buffering and completely
 forget about separation between application and presentation.

 I hope I make sense.

 Any thoughts on these kinds of problems?

 sounds like a job for smarty http://www.smarty.net/

 I've used smarty and it's nice.


How does Smarty solve this problem? Just curious.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Reminder On Mailing List Rules

2010-10-21 Thread Peter Lind
On 21 October 2010 16:25, Daniel Brown danbr...@php.net wrote:

* snip *

    The ultimate goal here isn't to start a flame war (or even any
 further discussion on the subject for that matter), but to point out
 that this is a RULE of the official community here, not a PREFERENCE.


If only the thread had ended there ...

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] include() and duplicate function definition

2010-11-03 Thread Peter Lind
You can check with function_exists to see if a function is already defined.
If not, create it.

Regards
Peter
On Nov 3, 2010 11:40 AM, David Nelson comme...@traduction.biz wrote:
 Hi Thijs, :-)

 On Wed, Nov 3, 2010 at 18:18, Thijs Lensselink d...@lenss.nl wrote:
 As far as I know it is not possible to overwrite functions in PHP (unless
 you use runkit, apd). Inside classes this is possible. But that's not the
 case here. Why do the functions have to be equally named?

 If the functions aren't named the same, my replacement function will
 never get called by the code that uses the WordPress theme code...

 Try to create a new function and call the original function from there if
 needed...

 Sadly, it wouldn't work for the above reason...

 But thanks for your answer. :-)

 David Nelson

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



Re: [PHP] include() and duplicate function definition

2010-11-03 Thread Peter Lind
That's not going to happen. My point was you could check in the original
file if the function is defined and if not then define it.
On Nov 3, 2010 11:55 AM, David Nelson comme...@traduction.biz wrote:
 Hi Peter, :-)

 On Wed, Nov 3, 2010 at 18:44, Peter Lind peter.e.l...@gmail.com wrote:
 You can check with function_exists to see if a function is already
defined.
 If not, create it.

 The function is definitely already defined, I just need to replace it
 without touching the file in which it's defined...

 David Nelson


Re: [PHP] Template engines

2010-11-08 Thread Peter Lind
On 8 November 2010 22:59, Michael Shadle mike...@gmail.com wrote:
 On Mon, Nov 8, 2010 at 1:41 PM, Hansen, Mike mike.han...@atmel.com wrote:
 I really like the idea of using a templating engine. Which one do you use? 
 Why? For those that don't use templating engines, why don't you use them?

 smarty is everyone's favorite usually but i find it a bit annoying.

 not to mention php itself is already a templating language... the only
 benefit is trying to separate content and presentation.

 however, for that to happen people create DSLs for templating that all
 have their own little syntaxes and glitches and annoyances.


PHPTal is an alternative to smarty: http://phptal.org/ - it's got a
nice syntax, I find.

However, whether one should bother with a templating system like
smarty or phptal very much depends upon how intricate your front-end
system needs to be and what it needs to do. For smaller projects.
smarty or phptal will get in the way and will likely get very
annoying. For bigger projects they can be of great use.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Template engines

2010-11-08 Thread Peter Lind
On 9 November 2010 06:20, Paul M Foster pa...@quillandmouse.com wrote:
 On Mon, Nov 08, 2010 at 02:41:12PM -0700, Hansen, Mike wrote:

 I really like the idea of using a templating engine. Which one do you
 use? Why? For those that don't use templating engines, why don't you
 use them?


 Here's why I don't use a templating engine.

 First, You're taking an embedded language and writing a templating
 engine in it. Seriously?

 Second, you're painting a single page, maybe 10-15K worth of
 information, and you're dragging 100K of code around just to paint a
 single page. Seriously?

 Third, you're creating a page on the fly, thrashing the server's CPU in
 order to generate a page which could be built statically, or at least
 with minimally embedded PHP. Seriously?


You assume that the OP will either make static pages (yet posts on the
PHP mailing list) or makes pages that aren't very dynamic in any
sense. Seriously?


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



[PHP] DOMDocument/DOMElement problem

2010-11-16 Thread Peter Lind
I'm currently trying to parse a document with DOMDocument, and I'm
having some serious problems. I created a script that runs fine on php
5.2.9, ripping out content using DOMNode::nodeValue. The same script
fails to get any content on php 5.3.3 - even though it correctly
navigates to the proper nodes to extract content.

Basically, the code used looks like this:

$dom = new DOMDocument();
$dom-loadHTML($data);
$dom-preserveWhiteSpace = false;
$xpath = new DOMXpath($dom);
$nodelist = $xpath-query($query);
$value = $nodelist-item(0)-nodeValue;

I've checked to make sure that item(0) is in fact a node - it's there
and even of the right type (a td - table cell), but nodeValue is
empty.

The script works on some documents but not others (on 5.3.3 - some
checking suggests a doctype of xhtml might be involved in the problem
but I tried ripping the doctype out and had no difference) - on 5.2.9
it works on all documents, returning the proper nodeValue.

Am I missing something basic?

TIA
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] DOMDocument/DOMElement problem

2010-11-17 Thread Peter Lind
On 16 November 2010 21:30, Adam Richardson simples...@gmail.com wrote:
 Hmmm...

 Nothing really stands out to me, but as my wife would attest, I'm often less
 than observant.

 I would probably try sifting through fixes/upgrades in the change logs for
 possible conflicts and/or changes in behavior.  Nothing jumped out at me
 after a quick glance.

 Sorry,

 Adam


Thanks for having a look. Far as I can tell, the main problem was
related to the encoding of the input data - and as such, the problem
was as likely to be in libxml as in php. I haven't seen any updates to
the DOM* extensions that would explain the change in behaviour and
really find it weird - but, at least I found a solution to the
problems :)

Quick note, in case anyone has similar problems: make sure that the
data you feed into DOMDocument is UTF8 encoded

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Procedural Autoloader?

2010-11-22 Thread Peter Lind
On 22 November 2010 22:40, Daniel P. Brown daniel.br...@parasane.net wrote:
 On Mon, Nov 22, 2010 at 16:31, Nathan Nobbe quickshif...@gmail.com wrote:

 Shrug, if you want to really be dirty about it, you could just put a 'class'
 atop each file of functions.
 ?php
 class IWishTheseFunctionsWereOOInstead {} // :P
 function firstProceeduralFunc() {
  // ..
 }
 ?

    That's not going to be economical or allow him to autoload,
 though, because the autoloader is called when the class is
 instantiated.

Not to mention that it has nothing to do with a procedural autoloader.
Autoloading takes place if you try to instantiate an object of a class
that PHP doesn't know about (yet). There is no such thing for
functions. Either refactor your code so you don't have this problem
(The Way To Go [tm]) or make an extension. End of discussion.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] is this thing on??

2010-11-23 Thread Peter Lind
On 23 November 2010 20:52, Steve Staples sstap...@mnsi.net wrote:
 tap tap tap... testing testing... 1, 2, 3

 Hello?    No activity since yesterday at like 6pm EST... am i not
 getting messages, or has there not been any activity?

 Just curious... carry on about your business... :P


http://news.php.net/php.general - please, next time, don't spam tons of people.

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Peter Lind
On Saturday, November 27, 2010, Richard West p...@cbnisp.com wrote:
 Hey Tommy,

 I get the same when seting it to a_downloads=a_downloads+1
 It still increments by 2
 I've never run into this before.
 RD


 On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote:

 -Original Message-
 From: Tamara Temple [mailto:tamouse.li...@gmail.com]
 Sent: Friday, November 26, 2010 7:54 PM
 To: Richard West
 Cc: PHP General Mailing List
 Subject: Re: [PHP] PHP Add +1 mysql updates by 2?


 On Nov 26, 2010, at 8:36 PM, Richard West wrote:

 Hey guys,
 I've never run into this before.
 I have a field in mysql for page views.
 So I pull out value and do +1 to new value - after UPDATE SET it has
 incremented by 2?

 $val = $row['a_downloads'] ;

 $new_val = $val+1;

 mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE
 a_id
 = '.$_GET['id'].' );

 Any ideas? What am I missing?
 RD

 a_downloads wouldn't happen to be an autoincrement value, would it?


 IIRC, the auto_increment should only increment on an INSERT statement and
 the field is omitted.  Besides, in MySQL, auto_increment must also be part
 of the primary key.  From Richard's query, I'd say that his primary key
 field is most likely a_id.  IMO, the best way to count something is to set
 the field to an int(eger) type.  Then just run 'UPDATE table_name SET
 count_field = count_field +1 WHERE criteria_column =  $criteria'.  This is
 more safe as you many have simultaneous users downloading.  This would
 ensure an accurate count, whereas your logic wouldn't.

 Regards,
 Tommy

 PS:  Richard, you should validate and sanitize all inputs.  Your query is
 prone to injection attack (deletion of rows or your entire DB deleted).  Use
 either mysql_escape_string or, better yet, mysqli to prepare the statement
 and bind the parameters.



Sounds like you're hitting the page twice. Check for missing image,
css files, favicons, js files etc.

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Peter Lind
And what difference will that make if the document is requested twice with
every browser load?
On Nov 27, 2010 6:39 AM, Richard West p...@cbnisp.com wrote:
 I took that into consideration so I added the update at the very end of
document...
 Still the same,
 RD




 On Nov 27, 2010, at 12:31 AM, Peter Lind wrote:

 On Saturday, November 27, 2010, Richard West p...@cbnisp.com wrote:
 Hey Tommy,

 I get the same when seting it to a_downloads=a_downloads+1
 It still increments by 2
 I've never run into this before.
 RD


 On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote:

 -Original Message-
 From: Tamara Temple [mailto:tamouse.li...@gmail.com]
 Sent: Friday, November 26, 2010 7:54 PM
 To: Richard West
 Cc: PHP General Mailing List
 Subject: Re: [PHP] PHP Add +1 mysql updates by 2?


 On Nov 26, 2010, at 8:36 PM, Richard West wrote:

 Hey guys,
 I've never run into this before.
 I have a field in mysql for page views.
 So I pull out value and do +1 to new value - after UPDATE SET it has
 incremented by 2?

 $val = $row['a_downloads'] ;

 $new_val = $val+1;

 mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE
 a_id
 = '.$_GET['id'].' );

 Any ideas? What am I missing?
 RD

 a_downloads wouldn't happen to be an autoincrement value, would it?


 IIRC, the auto_increment should only increment on an INSERT statement
and
 the field is omitted. Besides, in MySQL, auto_increment must also be
part
 of the primary key. From Richard's query, I'd say that his primary key
 field is most likely a_id. IMO, the best way to count something is to
set
 the field to an int(eger) type. Then just run 'UPDATE table_name SET
 count_field = count_field +1 WHERE criteria_column = $criteria'. This
is
 more safe as you many have simultaneous users downloading. This would
 ensure an accurate count, whereas your logic wouldn't.

 Regards,
 Tommy

 PS: Richard, you should validate and sanitize all inputs. Your query is
 prone to injection attack (deletion of rows or your entire DB deleted).
Use
 either mysql_escape_string or, better yet, mysqli to prepare the
statement
 and bind the parameters.



 Sounds like you're hitting the page twice. Check for missing image,
 css files, favicons, js files etc.

 --
 hype
 WWW: plphp.dk / plind.dk
 LinkedIn: plind
 BeWelcome/Couchsurfing: Fake51
 Twitter: kafe15
 /hype



Re: [PHP] php mail() and sendmail/smtp

2010-12-02 Thread Peter Lind
2010/12/2 Michael Crowl octo...@serv.net:

* snip *

 Also, we
 have Redmine running on the same server, and it sends admin emails out just
 fine - however, I don't think it calls sendmail directly like our PHP
 install, but connects directly to the local SMTP server.

Sounds like a solution to me: connect to port 25 on the mail server
instead of going through sendmail. Plenty of good mail libraries out
there (swiftmailer, phpmailer come to mind).

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-11 Thread Peter Lind
On Friday, 10 December 2010, Tommy Pham tommy...@gmail.com wrote:

* snup *

 The way I see it is this:

 1) Thorough understanding of the problem: needs of the client/company,
 programming language in use, etc.
 2) Thorough understanding of the objective of the application: answer the
 needs, capable of possible future growth/expandability, etc.
 3) Well thought out application design to resolve the above 2:  framework,
 mixed, or no framework.

 Thus, IMHO, caching is needed when one fails to fully meet the above 3 such
 as when the user clicks on any link in the browser, it should take no more
 than 3 seconds for the browser's status to be 'Done', provided that the user
 isn't on some 56k modem connection ;).

Always use a cache. Not using a cache means you've misunderstood some
fundamental points.

Regards
Peter


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
 I understand cache well, both the benefits (save DB trip) and shortfalls 
 (outdated by DB, management, etc.).  Most of the apps that I've seen so far 
 used cache to solve a problem that shouldn't happen in the 1st place.  For 
 example, during recent my quest looking PHP MVC framework and sample apps, I 
 saw OpenCart, an e-commerce app based on custom MVC framework.  Installed it 
 for a test run.  It looks good and seems to perform well with the included 
 sample data.  Then I filled up some more sample data: over 3000 categories, 
 over 2000 manufacturers, over 300,000 products.  No other changes made such 
 specials, features, etc.  Although the app supports i18n, the sample data is 
 just one language for a decent DB size of about 100MB.  The app took over 30 
 seconds to respond for any link.  Then I disable the cache and began 
 debugging.  I made 1 minor addition to the DB and 1 minor change in the code 
 base - parts on 1 line - I shorten the response time by about 10 seconds.  
 What I just did proved my 2nd and 3rd point :)

 Regards,
 Tommy


An app that takes 30 secs to respond using cache is doing it wrong.
You shaving 10 secs off the request without cache is fine but you
should have brought it much further down with a cache. Waiting 20 secs
for the response is still useless.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
On Sunday, 12 December 2010, Tommy Pham tommy...@gmail.com wrote:
 -Original Message-
 From: Peter Lind [mailto:peter.e.l...@gmail.com]
 Sent: Sunday, December 12, 2010 1:18 AM
 To: Tommy Pham
 Cc: php-general List
 Subject: Re: [PHP] ORM doctrine

  I understand cache well, both the benefits (save DB trip) and
  shortfalls (outdated by DB, management, etc.).  Most of the apps that
  I've seen so far used cache to solve a problem that shouldn't happen
  in the 1st place.  For example, during recent my quest looking PHP MVC
  framework and sample apps, I saw OpenCart, an e-commerce app based
 on
  custom MVC framework.  Installed it for a test run.  It looks good and
  seems to perform well with the included sample data.  Then I filled up
  some more sample data: over 3000 categories, over 2000 manufacturers,
  over 300,000 products.  No other changes made such specials, features,
  etc.  Although the app supports i18n, the sample data is just one
  language for a decent DB size of about 100MB.  The app took over 30
  seconds to respond for any link.  Then I disable the cache and began
  debugging.  I made 1 minor addition to the DB and 1 minor change in
  the code base - parts on 1 line - I shorten the response time by about
  10 seconds.  What I just did proved my 2nd and 3rd point :)
 
  Regards,
  Tommy
 

 An app that takes 30 secs to respond using cache is doing it wrong.
 You shaving 10 secs off the request without cache is fine but you should
 have brought it much further down with a cache. Waiting 20 secs for the
 response is still useless.

 Regards
 Peter

 --
 hype
 WWW: plphp.dk / plind.dk
 LinkedIn: plind
 BeWelcome/Couchsurfing: Fake51
 Twitter: kafe15
 /hype

 My goal wasn't to optimize any app.  I just want to learn 'implement abstract 
 MVC concept into concrete, ...' as I mentioned in Adam's thread about 
 choosing framework or not.  If I was to optimize it, I wouldn't have any 
 problems lowering the response time down to under 3 seconds w/o cache.

 Regards,
 Tommy


Your posts seem to indicate that caches are only useful when other
parts of the app have been done wrong. My point was that this is a
fairly fundamental misunderstanding of caches - regardless of what you
are or aren't capable of optimizing.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
On Sunday, 12 December 2010, Tommy Pham tommy...@gmail.com wrote:
 -Original Message-
 From: Lester Caine [mailto:les...@lsces.co.uk]
 Sent: Sunday, December 12, 2010 2:10 AM
 To: php-general List
 Subject: Re: [PHP] ORM doctrine

 Peter Lind wrote:
  Your posts seem to indicate that caches are only useful when other
  parts of the app have been done wrong. My point was that this is a
  fairly fundamental misunderstanding of caches - regardless of what you
  are or aren't capable of optimizing.

 CHACHES are only useful when there are static views of the information
 available. Only static elements can be cached with any real chance of
 performance improvement, so part of what Tommy is saying is correct.
 Although the way he has worded that is perhaps a little misleading?

Possibly. However, thinking that a cache is something you apply at the
end of development means you may well bar yourself from better uses of
one. Ie. thinking that a cache is icing on the cake prohibits you
from mixing it into the cake (to further abuse a metaphor) which
could give you a better recipe.
 I may have misunderstood the topic, but a cache to me is more than
just storing views. It's also the db cache, memcache, apc, etc. You
have to think about how you use these - some of them can't just be
slapped on to your app after development.


 Data caching SHOULD always be the
 domain of the database, so duplicating that in PHP is pintless.

So you're saying one should never use memcache for storing data from the db?

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
On Sunday, 12 December 2010, Tommy Pham tommy...@gmail.com wrote:
 -Original Message-
 From: Lester Caine [mailto:les...@lsces.co.uk]
 Sent: Sunday, December 12, 2010 2:10 AM
 To: php-general List
 Subject: Re: [PHP] ORM doctrine

 Peter Lind wrote:
  Your posts seem to indicate that caches are only useful when other
  parts of the app have been done wrong. My point was that this is a
  fairly fundamental misunderstanding of caches - regardless of what you
  are or aren't capable of optimizing.

 CHACHES are only useful when there are static views of the information
 available. Only static elements can be cached with any real chance of
 performance improvement, so part of what Tommy is saying is correct.
 Although the way he has worded that is perhaps a little misleading?

Possibly. However, thinking that a cache is something you apply at the
end of development means you may well bar yourself from better uses of
one. Ie. thinking that a cache is icing on the cake prohibits you
from mixing it into the cake (to further abuse a metaphor) which
could give you a better recipe.
 I may have misunderstood the topic, but a cache to me is more than
just storing views. It's also the db cache, memcache, apc, etc. You
have to think about how you use these - some of them can't just be
slapped on to your app after development.


 Data caching SHOULD always be the
 domain of the database, so duplicating that in PHP is pintless.

So you're saying one should never use memcache for storing data from the db?

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
On Sunday, 12 December 2010, Lester Caine les...@lsces.co.uk wrote:
 Peter Lind wrote:

 I may have misunderstood the topic, but a cache to me is more than
 just storing views. It's also the db cache, memcache, apc, etc. You
 have to think about how you use these - some of them can't just be
 slapped on to your app after development.


  Data caching SHOULD always be the
  domain of the database, so duplicating that in PHP is pintless.



 So you're saying one should never use memcache for storing data from the db?


 That is probably one of the areas where care should be taken in WHAT you are 
 caching. CURRENTLY too much caching goes on

I have not seen this problem but I have often seen sites not caching
things they should, so I'd say you're wrong. I don't think its
relevant one way or the other though.

 memcache may well be a candidate to use for a cached list of choices for a 
 form, but on a distributed database ( such as Firebird ) then how do you KNOW 
 if the list has been updated?

This is relevant to very few developers. Much more relevant is the
overhead used in contacting the single mysql/postgresql/etc database
that your provider put on another machine.

 Only the database actually knows that, and a good database will provide ALL 
 of the data caching that you need ... or at least it should if the DATABASE 
 is designed correctly.

See above.

 The reason for 'caching' needs to be understood before it is applied in order 
 to avoid the black holes that random caching is causing nowadays already. How 
 often do you hear wipe the xxx browser cache? And I know if I am changing 
 theme elements in bitweaver or phpgedview then I HAVE to wipe the cache to 
 ensure that smarty rebuilds the relevant pages.

Which underlines my point: caching is not icing on the cake but should
be thought of sooner in the process, contrary to Tommys point.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] How to define a data range for graphing?

2010-12-17 Thread Peter Lind
On Friday, 17 December 2010, Simon J Welsh si...@welsh.co.nz wrote:
 On 18/12/2010, at 8:45 AM, Brian Dunning wrote:

 Hey all -

 I'm trying to provide reporting to users of our widget. Some may get 0 to 5 
 hits a day; others may get up to 10,000 hits a day. I need to define the 
 range of the graph (using one of Google's). If their max day is 7, I'd like 
 the graph to go from 0 to 10. If their max day is 5678, I'd probably like it 
 to go from 0 to 6000. I'm guessing the way to do this is with a ceiling 
 function?

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


 Personally, I'd use something like:

 if($hits  10) {
         $top = 10;
 } else {
         $top = ($hits[0] + 1) * pow(10, strlen($hits) - 1);
 }

 Basically, add one to the first digit and make the rest of the digits 0. 
 Depending on how you want to handle the cases ending in 0s, you may want an 
 extra check in there.

 General disclaimer about code typed directly into mail client.

 Happy Saturday :)

Personally I'd add a percentage on top, say 5 or 10 percent.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Peter Lind
On 28 December 2010 21:18, Dotan Cohen dotanco...@gmail.com wrote:
 On Tue, Dec 28, 2010 at 21:57, Nathan Rixham nrix...@gmail.com wrote:
 Don't trim or limit the range of input characters, but far more importantly
 /don't send passwords in clear text/, indeed don't generate passwords at
 all, let users enter there desired password, then they won't be copy and
 pasting them ;)

 ps: if unavoidable, then give some advice on login failure like passwords
 are case sensitive, check you don't have caps lock on and that you haven't
 included any additional spaces.


 I'm toying with the idea of having the passwords hashed twice: they're
 already in the database hashed, and javascript hashes them on the
 client before sending them over, but I'm thinking about sending an
 additional salt to the client to hash the hashed passwords with salt,
 and that's what is sent back. This way, each login is done with a
 different hash of the password so an attacker cannot simply capture
 and reuse the hashed password.

Sounds like https would be MUCH simpler and likely as safe or safer. I
wouldn't waste my time on trying to come up with very clever schemes
when tried and true technologies are out there.

 But before all that goes on, I have to decide what to do about leading
 and trailing spaces.

As has been noted a couple of times: trim usernames. Never trim passwords.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Peter Lind
On 28 December 2010 22:06, Daniel Brown danbr...@php.net wrote:
 On Tue, Dec 28, 2010 at 16:05, Dotan Cohen dotanco...@gmail.com wrote:

 Did you know that when you type 'brown1' we see it as **? Your
 system does that automatically.

    That's how I see it, too.  It took me fourteen years to realize
 that my password wasn't just six asterisks (though, in my hand-made,
 high-security login scripts, the same will work, in case I forget my
 password).


Bla bla bla not Friday yet bla bla bla cut down on the noise on the list bla bla


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] memory usage/release GC

2010-12-31 Thread Peter Lind
On Dec 31, 2010 6:20 AM, Tommy Pham tommy...@gmail.com wrote:

 Hi folks,

 With the recent thread about password  security, I wrote a small quick
 script to generate a random or all possible passwords based on certain
 parameters for a brute force use.  On a very long running execution for a
 complex password in length with full use of the keys (94 characters),
 including upper case, the script seems to consumes more memory (shown in
 Windows task manager) as time progress.  Below are snippets from the
script
 file that does the workload:

 while (!$this-isMax())
 {
for ($b = 0; $b = $this-pwdLength; $b++)
{
if ($this-counter[$b]  $this-max)
{
$this-pwd[$b] =
 $this-charList[$this-counter[$b]];
$this-counter[$b]++;
break;
}
else
{
$this-counter[$b] = 1;
$this-pwd[$b] = $this-charList[0];
}
}
 }

 private function isMax()
 {
for ($a = $this-pwdLength-1; $a=0; $a--)
{
if ($this-counter[$a]  $this-max) return false;
}
return true;
 }

 Could someone please tell me why the above code consumes additional memory
 as time progress for the execution of the while loop?  Researching PHP GC
on
 google didn't shed light on problem.  Generating all possible combinations
 for 20 length with 94 possibilities each, the script easily consumes more
 than 1GB RAM in few minutes.  BTW, gc_enabled() reports on.

 Thanks,
 Tommy



Are you storing or throwing away the passwords? Also, lots of code is
missing from that post, no idea if you've got a memory leak in the rest of
the code

Regards
Peter


Re: [PHP] Global or include?

2011-01-06 Thread Peter Lind
On Jan 6, 2011 4:24 PM, Sándor Tamás sandorta...@hostware.hu wrote:

  In that case you should use include_once in every script. But if you are
absolutely sure that all scripts will be processed, you can include it only
in one of them, because PHP - in short terms - does a file include, so it
will look like as the included file is part of the script.
 The global keyword does not do what you think, it only propagates
variables between functions without passing them as parameters. In general,
you ought to avoid using global, because it can make your script less
readable, and / or can lead to logical errors.

 Because I am OOP fan, I'd rather create a static class, using public
static fields, so you can reach those variable as like
ConstClass::MyConstant. In that way, you have the advantage of simply create
new constants, and it doesn't matter how many times you include this file,
there will be only one instance.

If you include the file several times, you still have the problem of
redeclaring the class, so you'd have to wrap the definition in a
conditional, which sucks, or use the *_once functions and incur the
overhead. Much better to be in control of the includes.

Apart from that, it's generally better to use require* instead of include*.
If the file is needed, don't continue without it, as the consequences will
be unknown.

 SanTa

 2011.01.05. 23:40 keltezéssel, Paul Halliday írta:

 Say you have 10 or so scripts and a single config file. If you have
 main.php, functions1.php, functions2.php, functions3.php..

 Does is hurt to do an include of the config file in each separate
 script, even if you only need a few things from it,  or should you
 just specify what you want with a 'global' within each
 script/function?

 Thanks!




Re: [PHP] Re: Re: Re: PHP extension for equivalen of getent?

2011-01-08 Thread Peter Lind
On Jan 8, 2011 9:53 AM, David Robley robl...@aapt.net.au wrote:

 Michelle Konzack wrote:

  Hello David Robley,
 
  Am 2011-01-08 16:25:38, hacktest Du folgendes herunter:
  You might find http://xchm.sourceforge.net/ useful :-)
 
  [ 'apt-cache policy xchm' ]-
  xchm:
Installiert: 2:1.14-4
Kandidat: 2:1.14-4
Versions-Tabelle:
   *** 2:1.14-4 0
  900 ftp://ftp2.de.debian.org lenny/main Packages
  100 /var/lib/dpkg/status
  
 
  and it crash all the time...  :-(
 
  Thanks, Greetings and nice Day/Evening
  Michelle Konzack
 

 It's not Friday, so I won't go Off Topic and suggest you try compiling
from
 source :-)



While you're busy being not off topic, perhaps it might be an idea to also
not point to a proper place for questions about debian tools to read chm
files? I'm sure there are plenty of resources like irc channels or such.

Regards
Peter


Re: [PHP] Re: First PHP job

2011-01-11 Thread Peter Lind
On Jan 11, 2011 4:32 PM, Gary php-gene...@garydjones.name wrote:

 Steve Staples wrote:
  or the ($needle, $haystack) vs ($haystack, $needle)... i still get it
  screwed up...

 Given that, for example, array_search and strstr take those arguments in
 different orders, that's not really surprising.


Something tells me that's what he meant ...


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



[PHP] projectpier

2011-01-12 Thread Peter Lind
Heads up: jeg har flyttet projectpier over paa fastaval.dk domaenet -
det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
(og dermed ikke logge ind det forkerte sted).

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] projectpier

2011-01-12 Thread Peter Lind
2011/1/12 Ashley Sheridan a...@ashleysheridan.co.uk

  On Wed, 2011-01-12 at 23:14 +0100, Peter Lind wrote:

 jeg har flyttet projectpier over paa fastaval.dk domaenet -
 det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
 fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
 (og dermed ikke logge ind det forkerte sted)


 I think perhaps your change in domains was not meant to be posted to the
 list? :p


There's a massive ooops! if ever I did see one. Sorry about the (unintended)
noise and thanks for letting me know.


Re: [PHP] Re: email list 101

2011-01-16 Thread Peter Lind
On 16 January 2011 16:35, Michelle Konzack
linux4miche...@tamay-dogan.net wrote:
 Hello Kirk Bailey,

 Am 2011-01-16 10:09:03, hacktest Du folgendes herunter:
 So, in php, I want a program to handle sending out a mail list. All
 this is going to do is be a filter to exclude non subscribers, and
 send a copy to every person in the subscriber file. This is pretty
 simple in python, but this is not my mother tounge we speak here, so
 let's talk in php instead.

 If the submission does not come from a member, the script simply
 aborts. So the script should read the subscriber file, and if the
 source From: does not appear there, DIE. If it is there, walk the
 array and send a copy there, then end.

 Now how to do this in php? Is there an off the shelf solution?

 Maybe using RTFW http://www.php.net/

Considering that you've used the PHP list for some very inane
questions yourself, perhaps you should keep the tone lighter and avoid
flaming people? Just a thought.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Class and interface location

2011-01-19 Thread Peter Lind
How often would this profiling have to happen? Seems to me that if
it's a once per build or once per someone pressing the button,
then go for the more expensive analysis checking through the files.
Just build up a tree that shows which classes implement what or
inherit from where, save that along with file modification times, and
if you have to redo the analysis (on a running system, for instance)
then just check files that have changed since last check. It'll likely
be expensive once, but probably not very much (after all, you only
care about class, you don't need to parse docblocks or anything like
it).

regards
Peter
-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] email address syntax checker

2011-01-19 Thread Peter Lind
On 20 January 2011 05:14, Donovan Brooke li...@euca.us wrote:
 Hi Guys,

 I'm waddling my way through database interaction and thought someone on the
 list may already have a simple email checker that they'd like to share...

 you know, looking for the @ char and dots etc..

 I did a quick search of the archives and found a couple elaborate things..
 but
 I'm looking for something simple. This job will have trusted users and
 the checker is more to help them catch mistakes when registering.

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo Bad user! Bad user!;
}

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] No SMTP server? Can't get mail()

2011-01-20 Thread Peter Lind
Probably not the solution you were looking for, but I've always found mail()
very unstable and I tend to use a mail library instead. Like phpmailer or
swiftmailer. Easier to configure and figure out problems with.

Regards
Peter


Re: [PHP] Bilingual strtotime()

2011-02-06 Thread Peter Lind
On Feb 6, 2011 11:16 AM, Per Jessen p...@computer.org wrote:

 Alexis wrote:

  I was wondering if there was a way to use the strtotime() function
  when the months are in one or the other of the above two languages?

 Ah, I misread this earlier - strtotime(), not strftime().  You're
 talking about transforming from text to a locale()-neutral format.  I
 don't think strtotime() is locale-sensitive - according to the manual:

 The function [strtotime] expects to be given a string containing an
 English date format




Strtotime can read a number of formats, but does (from experience) have
problems with some. It won't work with textual dates in anything but
English, far as I know.

Regards
Peter


Re: [PHP] Re: First PHP site - thanks - euca_phpmysql function library

2011-02-09 Thread Peter Lind
On 9 February 2011 14:57, Bob McConnell r...@cbord.com wrote:
 From: Al

 On 2/8/2011 4:58 PM, Donovan Brooke wrote:
 Hello,

 Just wanted to say thanks to those that helped me get through my
 first PHP
 project (over the last month).

 As is with much of the work we server-side language people do, the
 back-end
 (non-public) side of this site is perhaps the more interesting.


 Suggestion: Design for XHTML 1.1.  It really doesn't require any
 significant
 additional effort and you'll already be current when it becomes the
 W3C
 standard. I like it because it forces me to create better, cleaner
 html code.

 You should also use the HTML Validator plug-in for Firefox to make sure
 you are producing valid XHTML. That makes it so much easier to find
 those invisible problems. I can't count how many times it has pointed
 right at a logic flaw in my code.

 Bob McConnell

Or go with the more likely candidate for a future html standard: html
5. Has the added benefit of easing you in to the new tags that will be
used as standard in a few years but won't be in xhtml.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: First PHP site - thanks - euca_phpmysql function library

2011-02-09 Thread Peter Lind
On 9 February 2011 17:22, Bob McConnell r...@cbord.com wrote:
 From: Peter Lind

 On 9 February 2011 14:57, Bob McConnell r...@cbord.com wrote:
 From: Al

 On 2/8/2011 4:58 PM, Donovan Brooke wrote:
 Hello,

 Just wanted to say thanks to those that helped me get through my
 first PHP
 project (over the last month).

 As is with much of the work we server-side language people do, the
 back-end
 (non-public) side of this site is perhaps the more interesting.


 Suggestion: Design for XHTML 1.1.  It really doesn't require any
 significant
 additional effort and you'll already be current when it becomes the
 W3C
 standard. I like it because it forces me to create better, cleaner
 html code.

 You should also use the HTML Validator plug-in for Firefox to make sure
 you are producing valid XHTML. That makes it so much easier to find
 those invisible problems. I can't count how many times it has pointed
 right at a logic flaw in my code.

 Or go with the more likely candidate for a future html standard: html
 5. Has the added benefit of easing you in to the new tags that will be
 used as standard in a few years but won't be in xhtml.

 I don't believe HTML 5 will ever be completed. Microsoft is working hard 
 behind the scenes to block it unless it only allows their codec's behind the 
 video and canvas tags. (Their efforts are very reminiscent of their sabotage 
 of ISO with the OOXML specification.) From a recent announcement(*), it 
 appears that even the committee has given up ever having a usable consensus, 
 but will accept whatever the browser developers want to implement even if 
 they are incompatible with other browsers. That's not a standard.


Html 5 has a fair chance of not being completed (that's going by what
Ian Hickson has stated as well as reading blogs and such on the matter
- see http://en.wikipedia.org/wiki/HTML5 for a pointer or two). That's
besides the point, though: html 5 *is* where the web is headed, as
opposed to xhtml. In part this is happening by browsers implementing
features piece by piece as they become stable - hence, you can already
use some html 5 features and be rather certain they'll work as
expected later on. MS may hate things not working how they like it,
but big and stupid as they are they have in fact figured out that the
web will happily move on without them - so they'll get round to
implementing html 5 features as well, at some point, even if it
doesn't use their proprietary code.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Displaying Results

2011-02-15 Thread Peter Lind
On 15 February 2011 20:28, Ethan Rosenberg eth...@earthlink.net wrote:
 Dear List -

  I have a form.  In one field, the customer types the name of a product.
  The first seven(7) results of the MySQL query that the entry generates
 should be displayed as a clickable drop down list.

 How do I do it?

Ask google you should
Plenty of advice you'll find
we won't do your homework

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:00, Dan Schaefer d...@performanceadmin.com wrote:
 In my code, I set the optional parameter to NULL and check for triple equals
 === or !== to see if the variable has been passed with a value. IMO,
 this is the safest way.

 function MyFunction($x, $y, $z=NULL) {
 if ($z !== NULL) {
 // Do Something
 }
 }

In case you're actually trying to test if a variable was passed or not
that doesn't work (as it doesn't detect NULL passed in). Use
func_get_args() as that gives you any and all arguments passed to the
function, excluding defaults.

That said, if you're making use of optional parameters and need to
check if anything was passed in, you're almost certainly doing things
wrong.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:45, Andre Polykanine an...@oire.org wrote:
 Hello Peter,

 So is
 func_get_args()
     the unique way?


Not really sure what you mean by the unique way. Most things proposed
so far in the thread would be fine for most purposes, I'd say. If you
really need finegrained control, I'd suggest func_get_args.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:45, Adam Richardson simples...@gmail.com wrote:
 On Wed, Feb 16, 2011 at 3:21 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On 16 February 2011 21:00, Dan Schaefer d...@performanceadmin.com wrote:
  In my code, I set the optional parameter to NULL and check for triple
 equals
  === or !== to see if the variable has been passed with a value. IMO,
  this is the safest way.
 
  function MyFunction($x, $y, $z=NULL) {
  if ($z !== NULL) {
  // Do Something
  }
  }

 In case you're actually trying to test if a variable was passed or not
 that doesn't work (as it doesn't detect NULL passed in). Use
 func_get_args() as that gives you any and all arguments passed to the
 function, excluding defaults.


 I'm not sure what you're saying here, Peter? Are you saying that the code
 wouldn't detect if $z was set to NULL by the calling code or by the default?
 I believe the point would be that no matter the case, the check would still
 perform the same task.

 Maybe I misunderstood (sorry.)

The point is the poster seemed to suggest the safest way to use
optional parameters was to use null as the default value and use ===
null to check against the optional parameter - as a way to check if
anything was passed in or not. I just pointed out that that would fail
to check for a null passed in and that func_get_args() would be a
better match. You're obviously right that the check inside the
function would work the same whether null was passed in or the value
was defaulted to null.



 That said, if you're making use of optional parameters and need to
 check if anything was passed in, you're almost certainly doing things
 wrong.


 I sometimes use this approach. PHP doesn't to my knowledge allow you to use
 function calls within defaults. There are times that I want the default to
 be the result of a function, and to accomplish this, I'll often set the
 default to null, then check for the null and carry out the function within.

 Is there a better solution?

As noted in the post, func_get_args will show any and all (at least on
my 5.3.3 install and 5.2.6 install) values passed in to the function -
hence it will also show if no parameter was passed in (and is thus
safer than relying on the default value).
That noted, I don't think checking if a value was passed in is good
design - I think the function should be ignorant of what is passed to
it. But that's just me :)

Regards
Peter


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 22:04, Paul M Foster pa...@quillandmouse.com wrote:
 On Wed, Feb 16, 2011 at 09:21:20PM +0100, Peter Lind wrote:

 On 16 February 2011 21:00, Dan Schaefer d...@performanceadmin.com wrote:
  In my code, I set the optional parameter to NULL and check for triple
 equals
  === or !== to see if the variable has been passed with a value. IMO,
  this is the safest way.
 
  function MyFunction($x, $y, $z=NULL) {
  if ($z !== NULL) {
  // Do Something
  }
  }

 In case you're actually trying to test if a variable was passed or not
 that doesn't work (as it doesn't detect NULL passed in). Use
 func_get_args() as that gives you any and all arguments passed to the
 function, excluding defaults.

 This must be my week to make enemies.

 I beg to differ. If the user passes in NULL for $z or passes in nothing
 for that variable, it does in fact show up as NULL. The following test
 code works as indicated:

Did anyone say it wouldn't?


 The responses in the first and third cases are NULL. You might be able
 to argue that in the first case, where the user passed in NULL, it's
 not the same as if the user passed in nothing. But I would assume that the
 author considers NULL a signal value, such that if the user passed such
 a value in, it would be equivalent to not passing a value for the third
 parameter.

The point I was trying to make was specifically that someone might try
to distinguish whether a value was passed in for an optional parameter
or not (like the case Adam outlined). Relying on the value of the
optional parameter will not do, in that case (well it might, depending
upon how stringent you really need to be).


 That said, if you're making use of optional parameters and need to
 check if anything was passed in, you're almost certainly doing things
 wrong.

 Again, assuming you're talking about examples like the one above, I have
 to disagree. Presumably, passing in an optional parameter changes the
 action inside the function. Thus, you would *need* to test for its
 presence. Otherwise, you would be stuck with assuming it's there,
 attempting to use it on that assumption, and dealing with whatever
 errors it causes when-- surprise!-- it's not there.

You should be wary of assumptions, they're not really working out for you.
- a) you're not addressing Adam's use case
- b) I wouldn't need to test for any presence if I wrote the function
as I would personally prefer, i.e. not trying to test if any value was
passed to the function or not. That's the whole point of optional
values: even if nothing is passed in, there's a default value. That's
why trying to check if something was passed for the optional parameter
is counter-productive: the idea of the default value is that you
shouldn't have to check.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Regex pattern for preg_match_all

2011-02-18 Thread Peter Lind
On 18 February 2011 22:36, Tommy Pham tommy...@gmail.com wrote:
 Hi folks,

 This is not directly relating to PHP but it's Friday so I'm gonna give
 it a shot :).  Would someone please help me figure out why my regex
 pattern doesn't work.  Below is the code and sample data:

 $html = HTML
 li class=small  tab a class=y-mast-link images
 href=http://images.search.yahoo.com/images;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Images/span/a/li
 li class=small  tab a class=y-mast-link video
 href=http://video.search.yahoo.com/video;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Video/span/a/li
 li class=small  tab a class=y-mast-link local
 href=http://local.yahoo.com/results;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Local/span/a/li
 li class=small  tab a class=y-mast-link shopping
 href=http://shopping.yahoo.com/search;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Shopping/span/a/li
 li class=small lasttab more-tab a class=y-mast-link more
 href=http://tools.search.yahoo.com/about/forsearchers.html; span
 class=tab-cover y-mast-bg-hideMore/spanspan
 class=y-fp-pg-controls arrow/span/a/li
 HTML;

 $pattern = 
 '%a\s[^href]*href\s*=\s*[\'|]?([^\'||#]+)[\'|]?\s*[^]*(.*)?/a%im';
 preg_match_all($pattern, $html, $matches);

 The only matches I got is:

 Match 1 of 1:   a class=y-mast-link local
 href=http://local.yahoo.com/results;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Local/span/a

 Group 1:        http://local.yahoo.com/results

 Group 2:        span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Local/span

 The pattern I made was to work in cases where the page is
 non-compliant to any of standard W3.


Not entirely sure what your input data is, as I'm guessing one or more
mail programs may have added line breaks. When I run the code I get no
matches at all - so I'm guessing you might have different input on
your end. More specifically, I'm also guessing you have line breaks on
your end, but not equally distributed - which would explain the one
hit.
 Apart from that, there are a couple of things I'd rework in your regex:

%a\s+.*?(?!href)\s+href\s*=\s*([^\s\']+|\'[^\']+\'|\[^\]+\)[^]*(.*?)/a%ims

* added modifier to whitespace at first
* allowing for any character not followed by href (non-greedy)
* match the href
* use proper alternation
* capture anything inside the a tag, non-greedy
* match with a closing /a tag

Results:
array(3) {
  [0]=
  array(5) {
[0]=
string(205) a class=y-mast-link images
href=http://images.search.yahoo.com/images;
data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Images/span/a
[1]=
string(201) a class=y-mast-link video
href=http://video.search.yahoo.com/video;
data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Video/span/a
[2]=
string(196) a class=y-mast-link local
href=http://local.yahoo.com/results;
data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Local/span/a
[3]=
string(204) a class=y-mast-link shopping
href=http://shopping.yahoo.com/search;
data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Shopping/span/a
[4]=
string(188) a class=y-mast-link more
href=http://tools.search.yahoo.com/about/forsearchers.html; span
class=tab-cover y-mast-bg-hideMore/spanspan
class=y-fp-pg-controls arrow/span/a
  }
  [1]=
  array(5) {
[0]=
string(39) http://images.search.yahoo.com/images;
[1]=
string(37) http://video.search.yahoo.com/video;
[2]=
string(32) http://local.yahoo.com/results;
[3]=
string(34) http://shopping.yahoo.com/search;
[4]=
string(55) http://tools.search.yahoo.com/about/forsearchers.html;
  }
  [2]=
  array(5) {
[0]=
string(96) span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Images/span
[1]=
string(95) span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Video/span
[2]=
string(95) span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Local/span
[3]=
string(98) span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Shopping/span
[4]=
string(94) span
class=tab-cover y-mast-bg-hideMore/spanspan
class=y-fp-pg-controls arrow/span
  }


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



[PHP] Infosys FYI

2011-02-26 Thread Peter Lind
Det gik op for mig at i tilmeldingsstresset fik jeg taget 2010
databasen ned. Den er nu tilgængelig igen.

Man bruger:
- http://archive.fastaval.dk/2010/infosys/ for at set 2010 udgaven
- http://infosys.fastaval.dk/ for at se 2011 udgaven

Derudover er 2009 udgaven stadig tilgængelig på
http://archive.fastaval.dk/2009/infosys/

De samme adgangskoder skulle virke til både 2010 og 2011.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: RE: [PHP] Check for open file

2011-03-03 Thread Peter Lind
On Mar 4, 2011 4:53 AM, Ashley M. Kirchner ash...@pcraft.com wrote:

  -Original Message-
  From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
  Sent: Thursday, March 03, 2011 2:03 PM
  To: sstap...@mnsi.net
  Cc: php-general@lists.php.net
  Subject: RE: [PHP] Check for open file
 
 
  As far as I was aware, if you're in the middle of writing to a file and
another
  script was attempting to write to it, the OS would prevent that as you
had an
  open lock on it.
 
  --
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 

And as it turned out, that was not the case.  I started copying a
200MiB file from my desktop machine onto the Samba share.  While that was
copying, I got onto the server and tried to copy the file to /tmp and it
happily did that for me without any indication that it was still being
written to (which is was by the way.)  So, that's not a good way of dealing
with this.

I think I'm going to have to go with a time delay function here ...


If on Linux, you can check for open file with lsof, I think the command is
called.

Regards
Peter

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



Re: [PHP] Deleting elements from the middle of an array

2011-03-14 Thread Peter Lind
On 14 March 2011 22:10, Paul M Foster pa...@quillandmouse.com wrote:
 On Mon, Mar 14, 2011 at 09:34:33PM +0100, Peter Lind wrote:

 On 14 March 2011 21:31, Paul M Foster pa...@quillandmouse.com wrote:
  Here's what I need to do: I have an indexed array, from which I need to
  delete elements in the middle. Once completed, the indexes should be
  numerically in sequence, as they were when I first encountered the
  array. That is:
 
  Before:
  $arr = array(0 = 5, 1 = 6, 2 = 7, 3 = 8, 4 = 9, 5 = 10);
 
  After:
  $arr = array(0 = 5, 1 = 6, 2 = 9, 3 = 10);
 
 
  I've tried:
 
  1) Using for() with unset(). Elements are deleted, but the indexes are
  no longer sequential.
 
  2) Using for() with array_splice(). Understandably, deletes certain
  elements but not others.
 
  3) Using foreach() with referenced array elements. Neither unset() nor
  array_splice() appear to have any effect on the array at all.
 
  4) while() loop using current() and the like. But these array functions
  return values, not references, so the array isn't actually modified.
 
  5) array_walk() with unset() array_splice(). No effect on the array.
 
  Anyone know how to do this, or know of a reference on how to?
 

 Remove the elements, then use sort().

 I've given a simplified example. The actual target array is
 multi-dimensional. Sort() won't work in a case like that, as far as I
 know. Moreover, I don't want the array sorted based on the element
 values.

Ahh, I see - you wanted me to guess at the actual circumstances of the
case instead of provide an answer to the example you posted. My bad.


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Deleting elements from the middle of an array

2011-03-15 Thread Peter Lind
On Mar 15, 2011 4:10 AM, Paul M Foster pa...@quillandmouse.com wrote:

 On Mon, Mar 14, 2011 at 10:14:53PM +0100, Peter Lind wrote:

  On 14 March 2011 22:10, Paul M Foster pa...@quillandmouse.com wrote:

 [snip]

   Remove the elements, then use sort().
  
   I've given a simplified example. The actual target array is
   multi-dimensional. Sort() won't work in a case like that, as far as I
   know. Moreover, I don't want the array sorted based on the element
   values.
 
  Ahh, I see - you wanted me to guess at the actual circumstances of the
  case instead of provide an answer to the example you posted. My bad.

 Is the sarcasm really necessary?


Without it, would you learn to post the actual details instead of something
irrelevant? If yes, then my apologies.

Regards


Re: [PHP] Deleting elements from the middle of an array

2011-03-15 Thread Peter Lind
On Mar 15, 2011 5:05 PM, Paul M Foster pa...@quillandmouse.com wrote:

 On Tue, Mar 15, 2011 at 07:08:28AM +0100, Peter Lind wrote:

 On Mar 15, 2011 4:10 AM, Paul M Foster [1]pa...@quillandmouse.com
 wrote:
 
  On Mon, Mar 14, 2011 at 10:14:53PM +0100, Peter Lind wrote:
 
   On 14 March 2011 22:10, Paul M Foster [2]pa...@quillandmouse.com

 wrote:
 
  [snip]
 
Remove the elements, then use sort().
   
I've given a simplified example. The actual target array is
multi-dimensional. Sort() won't work in a case like that, as
far as
 I
know. Moreover, I don't want the array sorted based on the
element
values.
  
   Ahh, I see - you wanted me to guess at the actual circumstances
of the
   case instead of provide an answer to the example you posted. My
bad.
 
  Is the sarcasm really necessary?
 
 
 Without it, would you learn to post the actual details instead of
 something irrelevant? If yes, then my apologies.

 Your sarcasm taught me more about you than about how to properly post to
 a mailing list.

 Help wrapped in a barbed package I can do without. Please feel free to
 ignore any requests for help from me in the future. Likewise, I will
 return the favor by ignoring any help you may give.


Duly noted - I shall regard any subsequent emails from you as having the
same degree of relevance as the information in your first email.


Re: [PHP] session variable problem

2011-03-25 Thread Peter Lind
More info (including some code) would be needed to get to the bottom
of this, I'd say. Hard to diagnose what's happening otherwise.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] is there a static constructor?

2011-03-30 Thread Peter Lind
On 31 March 2011 06:56, D. Dante Lorenso da...@lorenso.com wrote:
 All,

 I want to build a config file class that gets called statically.  Is there
 such a thing as a static constructor?  Example:

 class Daz_Config {
  public static function load() {
    ...
  }
  public static function get($key) {
    self :: load();
    ...
  }
 }

 Daz_Config :: get('myvalue');

 I want to call the load function when the class is used for the first time.
  If no code ever calls Daz_Config :: get(...) then I never want to invoke
 load() but if it does get called, I only want to call load() once before the
 class is used further.

 Anyone know how to do this with calling load() at the top of all the other
 functions and writing a load() function that exits early if already loaded?


The concept doesn't really make sense - a class that never gets
instantiated never gets constructed, hence no static constructor (nor
a static destructor). You'll have to call your constructor function
at the top of the static methods you'll be using - just check inside
the constructor if it's been called before or not.

Regards
Peter


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] XML... Useful or another layer of complexity?

2011-04-03 Thread Peter Lind
Like every other technology, XML needs to have a use before it becomes
a useful tool. Just using XML because it's available quickly leads to
headaches, as it isn't the best tool for all scenarios (config files
written in XML for instance). That said, XML is awesome for a lot of
things ... however, without having a better grasp of XML you're
unlikely to know whether it'll fit your needs.

If for no other reason, learning XML and related technologies is worth
it simply because the rest of the world uses it. So get to know it,
then you'll be able to actually judge if your project can benefit from
it.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



[PHP] Re: Config files: what is best? (was: Re: [PHP] XML... Useful or another layer of complexity?)

2011-04-03 Thread Peter Lind
On 3 April 2011 21:41, Andre Polykanine an...@oire.org wrote:
 Hello Peter,

 Just because you mentioned config files.
 What  would  you suggest me as better format for them? Database is not
 available  yet  since  I  need to make a config file before creating a
 database.

For config files I would suggest plain text config files - in the style of

key = value

php has built-in functions for reading those, so parsing them is very
fast and easy. See
http://dk2.php.net/manual/en/function.parse-ini-file.php

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Config files: what is best? (was: Re: [PHP] XML... Useful or another layer of complexity?)

2011-04-03 Thread Peter Lind
On 3 April 2011 22:35, Andre Polykanine an...@oire.org wrote:
 Hello Peter,

 Thanks a lot! And is there a way to set (write) custom values in files
 other than php.ini? Sorry, didn't find such a function.


I haven't come across any, but then again, I haven't had the need so
never looked much ... It would be rather easy to generate though

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Wiki formatting class or something similar

2011-04-30 Thread Peter Lind
On 30 April 2011 15:13, Stuart Dallas stu...@3ft9.com wrote:
 On Friday, 29 April 2011 at 22:04, Andre Polykanine wrote:
 Hi everyone,
 I allow my users to put some Html into their blogs. I filter it using
 a great tool called HtmLawed and written by Dr. Santosh Patnaik (if
 you're reading this, many thanks to you!).
 However, I would like to give them a possibility to mark-up their text
 in a more convenient way for beginners (such as Wiki or something
 similar).
 I searched through http://phpclasses.org/ but didn't find anything.
 Could you suggest me something?
 And one more question: maybe some of you already have a handy solution
 to process smilies? Say, a user writes :) and this is replaced by an
 image in my directory.
 Thanks in advance!

 Markdown is a pretty good option for a wiki: 
 http://michelf.com/projects/php-markdown/

 Textile is another option (and supports tables which markdown does not): 
 http://textile.thresholdstate.com/


MarkItUp is a favourite plugin editor of mine - will allow you to work
with a lot of different syntaxes and users don't need to know them.

http://markitup.jaysalvat.com/home/

If you're considering sanitizing html instead of using a markup
language to convert into html, I'd read
http://blog.astrumfutura.com/2010/08/html-sanitisation-the-devils-in-the-details-and-the-vulnerabilities/
before settling on any tool to do the job. Far as I can tell, HtmLawed
isn't actually capable of sanitizing properly, according to the author
- unless it's since been updated to fix the problems mentioned in the
blog.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Wiki formatting class or something similar

2011-04-30 Thread Peter Lind
On 30 April 2011 21:26, Andre Polykanine an...@oire.org wrote:
 Hello Peter,

 And what would you recommend as an Html sanitizing tool?


I go by htmlpurifier when I need to sanitize html. I generally try to
avoid the issue though, by having users use other markup languages (I
like markdown but dislike textile). That's much faster and just as
secure - downside is that your users might not be as used to it.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] How to DUMP $_POST parameters to a log file? Very useful and missing in the php.net

2011-05-08 Thread Peter Lind
On May 8, 2011 1:57 PM, Eli Orr (Office) eli@logodial.com wrote:


 Dear PHP Gurus,

 I need dump a $_POST parameters as part of debug process with a client.
 Any know service to make this ?

 I know $_POST is an Array but I look for a service function  that can save
the parsed array into a file.
 let say :

 $stt = save_POST_into_file ($_POST, $fp);


file_put_contents($filename, print_r($array, true));

Regards


Re: [PHP] Odd array_push issue

2011-05-11 Thread Peter Lind
On 11 May 2011 22:23, Richard S. Crawford rich...@underpope.com wrote:
 I'm encountering what appears to be a bug in array_push when I try using
 that function to add objects to an array. For example...

 A = Object 1
 B = Object 2

 If I execute the following code:

 array_push(objectarray, A);
 array_push(objectarray, B);

 ...I expect the contents of $objectarray to be:

 [0] = A
 [1] = B

 Instead, the last object pushed onto the array is repeated throughout the
 array. In other words, instead of the above, I get this:

 [0] = B
 [1] = B

 Can anyone enlighten me as to why this is happening? I've looked through bug
 reports but haven't found anything, which leads me to think that perhaps my
 own code is at fault.


If you could post some more of your code, it would be easier to check
if your code is at fault or not.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Odd array_push issue

2011-05-11 Thread Peter Lind
On 11 May 2011 22:39, Richard S. Crawford rich...@underpope.com wrote:
 On Wed, May 11, 2011 at 1:30 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On 11 May 2011 22:23, Richard S. Crawford rich...@underpope.com wrote:
  I'm encountering what appears to be a bug in array_push when I try using
  that function to add objects to an array. For example...
 
  A = Object 1
  B = Object 2
 
  If I execute the following code:
 
  array_push(objectarray, A);
  array_push(objectarray, B);
 
  ...I expect the contents of $objectarray to be:
 
  [0] = A
  [1] = B
 
  Instead, the last object pushed onto the array is repeated throughout
  the
  array. In other words, instead of the above, I get this:
 
  [0] = B
  [1] = B
 
  Can anyone enlighten me as to why this is happening? I've looked through
  bug
  reports but haven't found anything, which leads me to think that perhaps
  my
  own code is at fault.
 

 If you could post some more of your code, it would be easier to check
 if your code is at fault or not.

 Regards
 Peter

 Here's some more sample code, then:

 
 function retrieve_records ($where) {
      (Returns an array of objects which represent rows from a database
 query)
 }

 $records = retrieve_records($condition);

 $recordlist  = array();

 foreach ($records as $record) {

  array_push ($recordlist, $record)

 }
 

 I know this code isn't very useful, but these are the conditions which cause
 the issue I've mentioned.

class a {
public function __construct() {
$this-rand = mt_rand();
}
}

function retrieve_records () {
return array(
new a,
new a,
new a,
new a,
new a,
);
}

$records = retrieve_records();

$recordlist  = array();

foreach ($records as $record) {
 array_push ($recordlist, $record);
}

die(var_dump($recordlist));

gives me:

array(5) {
  [0]=
  object(a)#1 (1) {
[rand]=
int(515141845)
  }
  [1]=
  object(a)#2 (1) {
[rand]=
int(804365869)
  }
  [2]=
  object(a)#3 (1) {
[rand]=
int(32698894)
  }
  [3]=
  object(a)#4 (1) {
[rand]=
int(1375725959)
  }
  [4]=
  object(a)#5 (1) {
[rand]=
int(100662005)
  }
}


I'd say there's a problem in your code. Check where you might be using
references, chances are you're using one somewhere and not unsetting
it afterwards.

Regards
Peter
-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Error recovery - fatal errors

2011-05-14 Thread Peter Lind
On 14 May 2011 12:33, Tim Streater t...@clothears.org.uk wrote:
 I would like, in my app, to recover from as many run-time errors as possible, 
 so that I can tidy up. And unsolicited output generated by the standard error 
 system is really unhelpful as it becomes part of the ajax reply to the 
 browser.

 So I've added my own error handler, but it seems that I can't catch fatal 
 errors. The error in question comes from doing something like:

Fatal errors are fatal - if you could recover from them, they wouldn't be fatal.

 $res = $dbh-query ($sql);

 with $sql being an SQL statement, and $dbh being a database handle. I 
 recently had a case where $dbh was NULL, which triggers a fatal error from 
 SQLite. In principle such a bug should show up quickly, but this one had lain 
 untriggered for about a year. It seems to me somewhat arbitrary for this to 
 be designated a fatal error. Is there a way I can catch these? Most SQLite 
 error situations I'm solving with try/catch but no luck with this one so far.

You've got something wrong: either $dbh is not null or the error is
not from sqlite. I'm guessing the former. To avoid situations like
that, do proper error checking (i.e. actually check that your database
connection was opened succesfully).

 Error handling in library packages seems somewhat arbitrary - e.g. opendir 
 may give an E_WARNING, but closedir, readdir don't.


You can avoid all problems with error output by turning off error
displays in php.ini (set display_errors = off) - use error logging
instead. That's the recommended setting for production servers.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: Re: [PHP] Error recovery - fatal errors

2011-05-16 Thread Peter Lind
On 16 May 2011 22:14, Tim Streater t...@clothears.org.uk wrote:
 On 14 May 2011 at 15:05, Peter Lind peter.e.l...@gmail.com wrote:

 On 14 May 2011 12:33, Tim Streater t...@clothears.org.uk wrote:
 I would like, in my app, to recover from as many run-time errors as 
 possible,
 so that I can tidy up. And unsolicited output generated by the standard 
 error
 system is really unhelpful as it becomes part of the ajax reply to the
 browser.

 So I've added my own error handler, but it seems that I can't catch fatal
 errors. The error in question comes from doing something like:

 Fatal errors are fatal - if you could recover from them, they wouldn't be
 fatal.

 Except that this error is arbitrarily designated as fatal when it need not 
 be. A few days ago I discovered register_shutdown_function as mentioned by 
 someone today, and use that to pass E_ERRORs on to my error handler (as 
 declared by set_error_handler). That way I can log the error properly and 
 notify the user in a consistent manner. I've tested this by introducing some 
 errors (e.g. unitialised variables or setting $dbh to null) and these are all 
 nicely picked up.

You were trying to call a method on a non-object - how do you expect
PHP to handle that if not with a fatal error?
Anyway, good to hear you solved the issue - I misunderstood what you
wanted to do (shut down in a proper fashion, not actually recover from
the error) so I didn't think to mention this.

* snip *

 You can avoid all problems with error output by turning off error
 displays in php.ini (set display_errors = off) - use error logging
 instead. That's the recommended setting for production servers.

 This is not a browser/webserver situation in the classic manner. In this 
 case, the browser, PHP code, and the instance of apache used are all running 
 on the user's machine. The user just thinks they are running a local 
 application.

You can call it production server or not, if you are having problems
with error messages from php then you should turn off error display -
which shouldn't get in the way of you showing your own error messages
but will solve the problem mentioned.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] An Invitation to Neuroscientists and Physicists: Singapore Citizen Mr. Teo En Ming (Zhang Enming) Reports First Hand Account of Mind Intrusion and Mind Reading

2011-05-17 Thread Peter Lind
On May 17, 2011 5:05 PM, tedd tedd.sperl...@gmail.com wrote:

 At 1:19 PM +0100 5/17/11, Richard Quadling wrote:

 On 17 May 2011 12:45, Singapore Citizen Mr. Teo En Ming (Zhang Enming)
 -snip-

   Please remember what Singapore Citizen Mr. Teo En Ming (Zhang Enming)
have

  said. Mark my words. You will know the truth in future. It is no longer
a
  conspiracy theory. I can affirm that it (mind intrusion and mind
reading) is

   indeed happening to me.

 Is it Friday?

 Richard Quadling



 Wow! You read my mind.

 Cheers,

 tedd

If only it was ... then I'd be off work tomorrow, and the op and all the
replies would have been welcome noise instead of just noise. *sigh*

 --
 ---
 http://sperling.com/

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



Re: [PHP] Consistent Class Renaming (Simple Refactoring)

2011-05-17 Thread Peter Lind
On May 17, 2011 4:32 PM, Daniel Brown danbr...@php.net wrote:

 On Mon, May 16, 2011 at 18:46, Richard Quadling rquadl...@gmail.com
wrote:
 
  2.7.2? I'm guessing 5.7.2.

Then you're guessing wrong, sir.  There was no 2.7.2, and it's
 highly unlikely there would ever be a 5.7.2 either.

Closest I can guess is Apache httpd 2.2.7, or perhaps some other
 all-in-one installer (for example, there is a XAMPP 1.7.2).

Php 5.2.7 seems a more likely culprit

 --
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/

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



Re: [PHP] A Review Request

2011-05-18 Thread Peter Lind
On 18 May 2011 22:34, tedd t...@sperling.com wrote:
 At 3:31 PM -0400 5/18/11, Joshua Kehn wrote:

 On May 18, 2011, at 3:22 PM, tedd wrote:

 I am considering providing PHP code to the general public via my website

 This is my first attempt:


 http://sperling.com/php/authorization/http://sperling.com/php/authorization/

 What do you people think?


Good initiative. One thing though:
Please do not EVER suggest that people copy/paste your code. Do NOT
provide a nice option for copying it or suggest that it will work if
you just copy this and add a suffix. Plenty of people will mess
things up somehow, you'll discover a bug somewhere, etc. etc.
Copypasted code is one of the worst things the web has done. So please
don't add to it :)

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



<    11   12   13   14   15   16   17   18   19   >