Re: [PHP] preg_replace

2013-11-01 Thread Adam Szewczyk
Hi,

On Fri, Nov 01, 2013 at 11:06:29AM -0400, leam hall wrote:
 Despite my best efforts to ignore preg_replace...
Why? :)

 PHP Warning:  preg_replace(): Delimiter must not be alphanumeric or
 backslash
 
 Thoughts?
You are just using it wrong.
http://us2.php.net/manual/en/regexp.reference.delimiters.php

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



Re: [PHP] COM - Assigning to method.

2013-07-15 Thread Adam Nicholls
Hi Andrew

Thanks for this.

But I'm still getting errors. I think I need to explain a bit more.

Unfortunately there isn't a PHP API for this application I'm trying to
interact with, my goal really is to be able to expose the COM
functionality over a web-service such as SOAP so I can use it in a
CMS. The application I'm trying to integrate with is Blackbuad's
Raiser's Edge - API documentation here:
https://www.blackbaud.com/files/support/guides/re7ent/api.pdf

I think part of the problem is that the field names are also
represented by an integer. So to get data out I would do:

$oBank-Fields(22);   // which maps to BANK_fld_BRANCH_NAME.

When I do:

$oBank-22 = 'blah blah';

I get an error because a property can't be numeric, it has to start as
alpha character. If I use:

$oBank-BANK_fld_BRANCH_NAME = 'blah blah blah';

I get the following error:

Fatal error: Uncaught exception 'com_exception' with message 'Unable
to lookup `BANK_fld_BRANCH_NAME': Unknown name.

I've also tried using your Value property returned by Fields():

$oBank-Fields(22)-Value = 'Blah Blah blah blah';

Which I then get:
PHP Warning:  Creating default object from empty value in [C:\Users]
Fatal error: Call to undefined method variant::Save()

Soo seems nearly impossible to implement a safe way to write to the COM API.


At the moment, I'm still in the scoping/prototype stage of my project,
so I'm beginning to think that using this COM API for this project is
a no-go, which is unfortunate. I'm also guessing even if we did
implement this API, exposing it as a Web Service is going to be tricky
for performance sake (given that I've read that COM doesn't
multithread very well??)

Many Thanks
Adam.

On 14 July 2013 22:16, Andrew Ballard aball...@gmail.com wrote:
 On Sun, Jul 14, 2013 at 3:18 PM, Adam Nicholls inkysp...@gmail.com wrote:

 Richard - I've tried that I get an error about it not being defined as
 property of the object.

 Andrew - do you mean try using the method Richard has shown?

 Cheers
 Adam.

 On 13 July 2013 17:11, Richard Quadling rquadl...@gmail.com wrote:
 
 
 
  On 13 July 2013 01:24, Andrew Ballard aball...@gmail.com wrote:
 
  On Jul 12, 2013 4:53 AM, Adam Nicholls inkysp...@gmail.com wrote:
  
   Hi Guys/Gals,
  
   I'm doing some integration work with a COM API and according to their
   documentation to save data in the API, you have to assign to the
   method.
  
   This is their example in Visual Basic:
  
  
 
  -
   Set oBank = New CBank
   oBank.Init Application.SessionContext
   With oBank
   .Fields(BANK_fld_ACCOUNT_NAME) = Test account
   .Fields(BANK_fld_ACCOUNT_NO) = 12345
   .Fields(BANK_fld_BANK) = Bank of the Nation
   .Fields(BANK_fld_BRANCH_NAME) = State Street Branch
   End With
   oBank.Save
  
 
  -
  
   Obviously in PHP is isn't possible to assign to a method in this way
   (thats what parameters are for!) So I'm at a bit of a loose end. I'm
   wondering if anyone else has come across this? Or am I missing
   something obvious in PHP's implementation of the COM that allows me to
   work around this?
  
   My PHP Code is looks like this:
  
 
  -
   $API = new COM('API7.API');
   $API-Init($SerialNo, $Login, '', 1, '', 1);
   $API-SignOutOnTerminate = True;
  
   $Record = new COM(Data.Record);
   $Record-Init($API-SessionContext);
  
   $Record-Fields('BANK_fld_ACCOUNT_NAME') = 'Test Account';//doesn't work
  
 
  -
  
   I've also tried (below) but the API says wrong number of parameters
   $Record-Fields('BANK_fld_ACCOUNT_NAME', 'Test Account');
  
   I've also tried something crazy like this (below) but that overwrites
   the $Record object.
   $_R = $Record-Fields('BANK_fld_ACCOUNT_NAME');
   $_R = 'Test Account';
  
  
   Any ideas? Is it possible?
  
  
   Many Thanks
   Adam Nicholls
  
 
  That example isn't assigning values to method return value. Fields is a
  collection of ADO Field objects. The default property of a Field object is
  its Value property, so the shorthand is simply assigning the values of the
  variables to the value of each field in a record within a Recordset.
 
  Andrew
 
 
  So ..
 
  $oBank-BANK_fld_ACCOUNT_NAME = Test account;
 
  sort of thing.
 
  --
  Richard Quadling
  Twitter : @RQuadling



 --
 Adam Nicholls

 Richard has the general idea correct, but as I recall it is a little
 more involved because it's COM. I've never done that much with COM in
 PHP because it was always such a pain. The example you posted probably
 used to require com_set() in PHP 4, although it looks like that has
 been deprecated in favor of a more typical OO syntax in PHP 5. Is
 there any

Re: [PHP] COM - Assigning to method.

2013-07-14 Thread Adam Nicholls
Richard - I've tried that I get an error about it not being defined as
property of the object.

Andrew - do you mean try using the method Richard has shown?

Cheers
Adam.

On 13 July 2013 17:11, Richard Quadling rquadl...@gmail.com wrote:



 On 13 July 2013 01:24, Andrew Ballard aball...@gmail.com wrote:

 On Jul 12, 2013 4:53 AM, Adam Nicholls inkysp...@gmail.com wrote:
 
  Hi Guys/Gals,
 
  I'm doing some integration work with a COM API and according to their
  documentation to save data in the API, you have to assign to the
  method.
 
  This is their example in Visual Basic:
 
 

 -
  Set oBank = New CBank
  oBank.Init Application.SessionContext
  With oBank
  .Fields(BANK_fld_ACCOUNT_NAME) = Test account
  .Fields(BANK_fld_ACCOUNT_NO) = 12345
  .Fields(BANK_fld_BANK) = Bank of the Nation
  .Fields(BANK_fld_BRANCH_NAME) = State Street Branch
  End With
  oBank.Save
 

 -
 
  Obviously in PHP is isn't possible to assign to a method in this way
  (thats what parameters are for!) So I'm at a bit of a loose end. I'm
  wondering if anyone else has come across this? Or am I missing
  something obvious in PHP's implementation of the COM that allows me to
  work around this?
 
  My PHP Code is looks like this:
 

 -
  $API = new COM('API7.API');
  $API-Init($SerialNo, $Login, '', 1, '', 1);
  $API-SignOutOnTerminate = True;
 
  $Record = new COM(Data.Record);
  $Record-Init($API-SessionContext);
 
  $Record-Fields('BANK_fld_ACCOUNT_NAME') = 'Test Account';//doesn't work
 

 -
 
  I've also tried (below) but the API says wrong number of parameters
  $Record-Fields('BANK_fld_ACCOUNT_NAME', 'Test Account');
 
  I've also tried something crazy like this (below) but that overwrites
  the $Record object.
  $_R = $Record-Fields('BANK_fld_ACCOUNT_NAME');
  $_R = 'Test Account';
 
 
  Any ideas? Is it possible?
 
 
  Many Thanks
  Adam Nicholls
 

 That example isn't assigning values to method return value. Fields is a
 collection of ADO Field objects. The default property of a Field object is
 its Value property, so the shorthand is simply assigning the values of the
 variables to the value of each field in a record within a Recordset.

 Andrew


 So ..

 $oBank-BANK_fld_ACCOUNT_NAME = Test account;

 sort of thing.

 --
 Richard Quadling
 Twitter : @RQuadling



-- 
Adam Nicholls

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



[PHP] COM - Assigning to method.

2013-07-12 Thread Adam Nicholls
Hi Guys/Gals,

I'm doing some integration work with a COM API and according to their
documentation to save data in the API, you have to assign to the
method.

This is their example in Visual Basic:

-
Set oBank = New CBank
oBank.Init Application.SessionContext
With oBank
.Fields(BANK_fld_ACCOUNT_NAME) = Test account
.Fields(BANK_fld_ACCOUNT_NO) = 12345
.Fields(BANK_fld_BANK) = Bank of the Nation
.Fields(BANK_fld_BRANCH_NAME) = State Street Branch
End With
oBank.Save
-

Obviously in PHP is isn't possible to assign to a method in this way
(thats what parameters are for!) So I'm at a bit of a loose end. I'm
wondering if anyone else has come across this? Or am I missing
something obvious in PHP's implementation of the COM that allows me to
work around this?

My PHP Code is looks like this:
-
$API = new COM('API7.API');
$API-Init($SerialNo, $Login, '', 1, '', 1);
$API-SignOutOnTerminate = True;

$Record = new COM(Data.Record);
$Record-Init($API-SessionContext);

$Record-Fields('BANK_fld_ACCOUNT_NAME') = 'Test Account';//doesn't work
-

I've also tried (below) but the API says wrong number of parameters
$Record-Fields('BANK_fld_ACCOUNT_NAME', 'Test Account');

I've also tried something crazy like this (below) but that overwrites
the $Record object.
$_R = $Record-Fields('BANK_fld_ACCOUNT_NAME');
$_R = 'Test Account';


Any ideas? Is it possible?


Many Thanks
Adam Nicholls

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



Re: [PHP] How to enable cURL php extension on Debian Wheezy?

2013-06-01 Thread Adam Szewczyk
On Sat, Jun 01, 2013 at 09:41:33PM +0200, Csanyi Pal wrote:
 Hi,
 
 I just upgraded Squeeze to Wheezy, and have difficulties with cURL PHP
 extension: I can't enable it.
 
 I have installed following packages related to this issue:
 curl, libcurl3, libcurl3-gnutls, php5-curl.
 
 I have in
 /etc/php5/mods-available/curl.ini
 ; configuration for php CURL module
 ; priority=20
 extension=curl.so
 
 I know that cURL extension is not enabled because I want to install
 Moodle and it complains about cURL extension.
 
 How can I solve this problem?

Hi,

what error message do you get?

Also, have you restarted apache after installing the extension?

Regards,
A.

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



Re: [PHP] How to enable cURL php extension on Debian Wheezy?

2013-06-01 Thread Adam Szewczyk
On Sat, Jun 01, 2013 at 09:41:33PM +0200, Csanyi Pal wrote:
 Hi,
 
 I just upgraded Squeeze to Wheezy, and have difficulties with cURL PHP
 extension: I can't enable it.
 
 I have installed following packages related to this issue:
 curl, libcurl3, libcurl3-gnutls, php5-curl.
 
 I have in
 /etc/php5/mods-available/curl.ini
 ; configuration for php CURL module
 ; priority=20
 extension=curl.so
 
 I know that cURL extension is not enabled because I want to install
 Moodle and it complains about cURL extension.
 
 How can I solve this problem?

Hi,

what error message do you get?

Also, have you restarted apache after installing the extension?

Regards,
A.

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



Re: [PHP] php links doest work when im using mod rewrite

2013-06-01 Thread Adam Szewczyk
This is more of an apache question.

You can try below url.

http://lmgtfy.com/?q=mod_rewrite+exclude+css

On 1 June 2013 21:39, Farzan Dalaee farzan.dal...@gmail.com wrote:

 i starting to use mod rewrite but all my images or js links doest work
 my current query string is:
 index.php?r=blogpage=2
 i want to change it with this:
 /blog/2
 this is my .htaccess file
 RewriteEngine On
 RewriteRule ^([^/]*)/([^/]*)$ /framework/?r=$1page=$2 [L]

 but none of my js or css cant find

 i need a way with php to make urls
 thanks




-- 
A.


Re: [PHP] Load testing an app

2013-04-23 Thread Adam Richardson
On Mon, Apr 22, 2013 at 10:41 PM, Andrew Ballard aball...@gmail.com wrote:

 The other developer in our office spent some time profiling the site with
 xdebug and found that an exec() call to netsh used on a couple pages seems
 to take 2-4 seconds to complete. Unfortunately, those exec() calls are the
 one function that we cannot test in our development environment. We are
 considering some optimizations, but since load on the production server is
 at a seasonal low we want to duplicate the problem so we can measure the
 impact of any changes we make. We spent most of today hammering the site
 with JMeter today in an attempt to reproduce the issue. While we were
 easily able to slow the site to a crawl (some samples taking over 2 minutes
 to complete), the server returned to normal as soon as the test concluded
 and it never became totally unresponsive like it did this past fall.


If you can't test the exec calls, directly, I'd refactor the functionality
that calls exec() so you could pass in replacement functionality that
creates that artificially creates the pause in your development environment:

function callnetsh($args, $func) {
$func($args);
}
// in dev environment, pass in $func that doesn't call exec but just sleeps
for the expected duration
callnetsh(['some', 'args'], function($args){
sleep(4);
});

We're both new to JMeter. I know a single test server may not be able to
 create enough simultaneous requests to accurately simulate real traffic,
 but I'm fairly confident that our tests involved far more (roughly-)
 simultaneous connections than we were experiencing live. (The first test
 used 20 threads; we gradually increased the threads for each test to 500
 threads before we quit for the day.) The site is on a private subnet, so
 distributed and/or cloud-based testing are probably not options.


2 quick notes:

If you have a linux box available, I like the simplicity of siege, but
jmeter is nice, too:
http://www.joedog.org/siege-home/

If the exec() calls were not being executed (e.g., they were bypassed) and
weren't being accounted for in terms of processing time, then these tests
would likely fail to recreate the load issues with similar numbers.

The site is running PHP 5.3 on IIS/Windows Server 2003. The netsh calls are
 to a DHCP server on a separate Windows server, and the database is SQL
 Server 2008 (previously 2000).


PHP 5.4 offers performance improvements. I don't suspect the migration from
SQL Server 2003 to 2008 caused any of these issues.


 So, any ideas we can try?


We'd probably have to know more about what the netsh calls were doing.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Compiler for the PHP code

2013-03-19 Thread Adam Nicholls
Checkout HipHop by the Facebook guys, it turns PHP into C code and compiles 
down to binary. 

...although I don't think it's for the faint hearted.

Have you tried other optimisation techniques first - eg Caching, and 
Profiling?? If this is a production environment you might wanna think about 
increasing resources or introducing a load balancer (in the case of PHP based 
websites)

Cheers
Ads.


Sent from my BlackBerry® wireless device

-Original Message-
From: Camille Hodoul camille.hod...@gmail.com
Date: Tue, 19 Mar 2013 09:52:14 
To: Kevin Petersonqh.res...@gmail.com
Cc: php-general@lists.php.net
Subject: Re: [PHP] Compiler for the PHP code
Googling compile php code gave me this :
http://stackoverflow.com/questions/1408417/can-you-compile-php-code
It looks like you have some options but I haven't tried any yet, so I can't
help you with the installation


2013/3/19 Kevin Peterson qh.res...@gmail.com

 My webcode written in PHP and it is running in the interpreted way. My
 problem is it is not giving the desired performance so want to try the
 compiler if any.
 Please suggest if we have any compiler option available for the PHP code
 and more important is this new option.




-- 
Camille Hodoul
http://camille-hodoul.com/



Re: [PHP] webDAV/CalDAV client class experience ?

2013-03-01 Thread Adam Tauno Williams
On Sun, 2013-02-17 at 21:26 -0600, tamouse mailing lists wrote:
 On Sat, Feb 16, 2013 at 2:30 PM, B. Aerts ba_ae...@yahoo.com wrote:
  - the biggest mistake: apparently I commented the fwrite() call to the
  stream, which explains why he went in time-out ... (in this case, please DO
  shoot the pianist)
 Nah, just don't leave a tip. :)
  - Adding the HTTP header Accept: */* made sure all read actions ( e.g.
  GET, PROPFIND, REPORT) worked perfectly

Interesting, suprising, but it makes sense.  An Accept header is
required; although most things actually ignore it.

 This is interesting. The Accept header has to do with what media types
 the browser will accept in return. I didn't think it had anything to
 do with what operations the server/application accepts. Must go read
 further
  Only problem remaining was that PUT still isn't possible - at least not with
  one of the providers. Since I used a verbatim copy of a PUT action from the
  RFC, I strongly suspect the problem to be with the provider.
 
 You've no doubt considered this already, but it might be intentional
 on the provider's part. I'm not up on all the webDAV/calDAV providers;
 I imagine some of them might add in additional layers of auth
 (including the NOWAI layer)  just to consider themselves more secure.

I have WebDAV/CardDAV/CalDAV experience - what actually happens when you
do a PUT operation?  Do you get any response at all?  Is your
content-type header correct?  Is your payload actually correct?



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



Re: [PHP] webDAV/CalDAV client class experience ?

2013-03-01 Thread Adam Tauno Williams
On Mon, 2013-02-18 at 12:19 +0100, B. Aerts wrote:
  - Adding the HTTP header Accept: */* made sure all read actions ( e.g.
  GET, PROPFIND, REPORT) worked perfectly
 
  This is interesting. The Accept header has to do with what media types
  the browser will accept in return. I didn't think it had anything to
  do with what operations the server/application accepts. Must go read
  further
 
 I'll have to revoke this statement, as I can't reproduce it anymore.
 I noticed the DaviCal didn't use it, bu the CURL call did - and yielded 
 more ( = meaningfull) results.
 But, as I said, can't reproduce it.
 
 The thing I could reproduce was that, if the request was sent to the 
 default port, AND this port was included in the Host header, both GET 
 and PUT yielded HTTP 404.
 
 
  Only problem remaining was that PUT still isn't possible - at least not 
  with
  one of the providers. Since I used a verbatim copy of a PUT action from the
  RFC, I strongly suspect the problem to be with the provider.
 
  You've no doubt considered this already, but it might be intentional
  on the provider's part. I'm not up on all the webDAV/calDAV providers;
  I imagine some of them might add in additional layers of auth
  (including the NOWAI layer)  just to consider themselves more secure.
 
 Yes I did, but the following arguments should negate that consideration:
 - when running OPTIONS, PUT is included in the allowed HTTP methods
 - the HTTP return code from the PUT command is 301, where a security 
 issue would have yielded a code in the 400 range

Ok, and the 301 response contains a Location: header?  A 301 as a
response to PUT just means the server relocated/renamed the resource. 

 - the other provider does respond as expected (though I agree, that is 
 the weakest argument: expectations != specifications )

Nobody, nowhere, matches the spec.

 - the provider does allow sync'ing Sunbird, iCal, ... over CalDAV, and 
 that works, even entering a new event (which is a PUT action). The 
 Charles debugging proxy too shows that it's only Basic authentication 
 that's going up - and succeeding

If your response is 301 why do you believe it is failing?

 $body = XML
 ?xml version=1.0 encoding=utf-8 ?
 C:calendar-query xmlns:D=DAV: xmlns:C=urn:ietf:params:xml:ns:caldav
   D:prop
 C:calendar-data/
 D:getetag/
   /D:prop
   C:filter
 C:comp-filter name=VCALENDAR
   C:comp-filter name=VEVENT
 C:time-range start=20130201T01Z end=20130228T01Z/
   /C:comp-filter
 /C:comp-filter
   /C:filter
 /C:calendar-query

Does PHP provide some kind of XML building library?  String building XML
is *always* dicey and it is *VERY* easy to introduce encoding problems.
Something at least with an codepage codec would be good.  [although it
*should* work, I manipulate WebDAV servers via curl CLI all the time].

In Python a combination of ElementFlow and the codecs module is
perfection.  I assume there is a PHP equivalent.

-- 
Adam Tauno Williams awill...@whitemice.org


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



[PHP] Close enough to Friday...

2013-02-28 Thread Adam Richardson
Just wanted to toss this out as something I quick developed in case it
could help others:
https://github.com/AdamJonR/PreHP

Essentially, I just wanted a quick pre-processor that would work with
PHP so I could limit some of the processing done at runtime. As
opposed to C macros, I wanted to design it so that files could/should
be developed to be valid html/php without the preprocessor. The
preprocessor merely speeds the performance. The example for templating
could be redone to use includes and then replace those with the
inlined content, I just prefer to work with skeleton HTML so I can
validate the XHTML as I go within the static file rather than having
to check the content on a test server.

The preprocessor is dumb (for now, I'm not parsing the PHP to ensure
the comments are not contained within strings, etc.), but this
shouldn't pose an issue for most situations.

Anyways, I just whipped this up so I could ditch Dreamweaver Templates
(which I used so the templating happened prior to runtime, too), as
I'm trying to save some money and I don't want to upgrade to the next
version :)

Happy Friday!

Adam

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



Re: [PHP] Close enough to Friday...

2013-02-28 Thread Adam Richardson
On Thu, Feb 28, 2013 at 10:19 PM, tamouse mailing lists
tamouse.li...@gmail.com wrote:

 Congratulations on ditching the Dreamweaver Templates!

 Now, as to preprocessing: how does this benchmark out? Have you
 noticed a significant different in processing time, memory usage, disk
 usage, etc?

Well, it depends...

For example, if you use code similar to the inlined function example,
there is a difference. In that example, the inlined code runs almost
twice as fast.

?php
$a = 1;
$b = 2;
$start = microtime();

for ($i = 0; $i  1; $i++) {
$result = ($a  $b  $a % 2 !== 0) ? $a : (($b % 2 !== 0) ? $b : (($a
% 2 !== 0) ? $a : null));
}

$runtime = microtime() - $start;
echo $runtime;

?

?php

function maxodd($a, $b)
{
return ($a  $b  $a % 2 !== 0) ? $a : (($b % 2 !== 0) ? $b : (($a %
2 !== 0) ? $a : null));
}

$a = 1;
$b = 2;
$start = microtime();

for ($i = 0; $i  1; $i++) {
$result = maxodd($a, $b);
}

$runtime = microtime() - $start;
echo $runtime;

?

That said, there's tremendous variance across the possible range of
function types (e.g., number of args, complexity of function, etc.),
so there's no guarantee you'll always see a worthwhile (which is also
subjective) improvement. I'm going to use inlining for functions that
output html-escaped output (the function wraps htmlspecialchars to
allow whitelisting), as they're frequent and simple, the very type of
function that is easily inlined and provides some speed benefit.

In terms of the templating, in my tests using siege comparing
Dreamweaver Templates vs PHP includes, I've typically seen significant
benefits when the template requires multiple includes, with the effect
dropping off as the number of includes approaches 0. These results
should be the same. Again, there seems to be a broad range of
considerations (in terms of using APC, using absolute paths helped the
include performance:
http://www.php.net/manual/en/apc.configuration.php#ini.apc.stat)

There are usually bigger ways to enhance performance (data
persistence, etc.), but in the same way that I try to teach my little
girls to turn off the faucet in between spitting into the sink even
though monitoring showers can do much more to save water, when I see
simple ways I can consistently save cycles, I try to implement them :)

Adam

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



Re: [PHP] Arrays

2013-02-25 Thread Adam Richardson
On Mon, Feb 25, 2013 at 8:40 PM, Karl DeSaulniers k...@designdrumm.com wrote:
 Hi Guys/Gals,
 If I have an multidimensional array and it has items that have the same name
 in it, how do I get the values of each similar item?

 EG:

 specialservices = array(
 specialservice = array(
 serviceid = 1,
 servicename= signature required,
 price = $4.95
 ),
 secialservice = array(
 serviceid = 15,
 servicename = return receipt,
 price = $2.30
 )
 )

 How do I get the prices for each? What would be the best way to do this?
 Can I utilize the serviceid to do this somehow?
 It is always going to be different per specialservice.

Something appears to be amiss, as your array couldn't contain multiple
items with the specialservice key (I'm assuming the second key
'secialservice' is just a typo), as any subsequent assignments would
overwrite the previous value.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] if (empty versus if (isset

2013-02-19 Thread Adam Richardson
On Tue, Feb 19, 2013 at 9:29 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:

 What is the difference between?

 if (empty... http://www.php.net/manual/en/function.empty.php Determine 
 whether a variable is empty
 and
 if (isset... http://php.net/manual/en/function.isset.php Determine if a 
 variable is set and is not *|NULL|*


I like the explanation on the empty page:

No warning is generated if the variable does not exist. That means
empty() is essentially the concise equivalent to !isset($var) || $var
== false.


 I have an input type=radio value=something.

 If it is not checked, it is NOT empty, because it has a value, right?
 But it is NOT set, right?

Some of the form elements (e.g., checkboxes, radio's) are a little tricky:
http://stackoverflow.com/questions/476426/submit-an-html-form-with-empty-checkboxes

When unchecked, no GET or POST variable is present to represent their value.

 Is this empty, because it's value is ?

 input type=text value=

 Just trying to understand ... :)

A text field would be present in the GET or POST super globals, and if
empty (the user did not add input), the empty function would return
true because an empty string is one of the values that evaluates to
false:
-  (an empty string)
- 0 (0 as an integer)
- 0.0 (0 as a float)
- 0 (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- $var; (a variable declared, but without a value)

Adam

--
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] Affordable low-fee e-commerce - DIY?

2013-02-18 Thread Adam Richardson
On Mon, Feb 18, 2013 at 1:26 PM, George Langley george.lang...@shaw.cawrote:

 Hi all. Am wanting to build a site where people can donate $1.00 but is
 not for charity or other non-profit per se. So if I use PayPal, with their
 2.9% + .30 per transaction fee, that equals .33 cents for each dollar -
 that's a full third of the amount the people would be giving. Credit cards
 appear to be similar, with some percantage and about .22 cents per
 transactions.
 Am wondering what other options I'm missing, that won't take such a chunk
 out of the low price? Is it easy enough to code to some other API for free
 (or at least cheaper)?
 Thanks.


Not really a PHP question, but just FYI, Paypal and other providers provide
micropayments options:
https://www.paypalobjects.com/IntegrationCenter/ic_micropayments.html

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] fopen and load balancing

2013-02-11 Thread Adam Tong
I think this is what happened. As the application was trying to open
our url domain the request was sent to the load balancer, and as it
does not accept internal requests, the connection was timed out.

The only way we could avoid that is to not use fopen our url, is that right?


On Mon, Feb 11, 2013 at 4:26 AM, ma...@behnke.biz ma...@behnke.biz wrote:


 Adam Tong adam.to...@gmail.com hat am 10. Februar 2013 um 23:41 geschrieben:
 Hi,

 We had an issue with the code of a junior php developer that used
 fopen to load images using the url of the companies website that is
 load balanced.

 We could not the detect the problem in dev and test because the dev
 and test servers are not load balanced.

 I know that he could load the images using just the filesystem, but I
 am curious to know why it failed and if the load balancer is really
 the source of the problem or it is a limitation on the function
 itself.

 Do you have any error messages for us?
 If the load balancer accessable from the internal servers? Normally it is not.



 Thank you

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


 --
 Marco Behnke
 Dipl. Informatiker (FH), SAE Audio Engineer Diploma
 Zend Certified Engineer PHP 5.3

 Tel.: 0174 / 9722336
 e-Mail: ma...@behnke.biz

 Softwaretechnik Behnke
 Heinrich-Heine-Str. 7D
 21218 Seevetal

 http://www.behnke.biz

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


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



[PHP] fopen and load balancing

2013-02-10 Thread Adam Tong
Hi,

We had an issue with the code of a junior php developer that used
fopen to load images using the url of the companies website that is
load balanced.

We could not the detect the problem in dev and test because the dev
and test servers are not load balanced.

I know that he could load the images using just the filesystem, but I
am curious to know why it failed and if the load balancer is really
the source of the problem or it is a limitation on the function
itself.

Thank you

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



Re: [PHP] fopen and load balancing

2013-02-10 Thread Adam Richardson
On Sun, Feb 10, 2013 at 5:41 PM, Adam Tong adam.to...@gmail.com wrote:

 Hi,

 We had an issue with the code of a junior php developer that used
 fopen to load images using the url of the companies website that is
 load balanced.

 We could not the detect the problem in dev and test because the dev
 and test servers are not load balanced.

 I know that he could load the images using just the filesystem, but I
 am curious to know why it failed and if the load balancer is really
 the source of the problem or it is a limitation on the function
 itself.

 Thank you

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


I'm not sure it sounds like an issue with the load balancer, as a load
balancer shouldn't have any qualm with passing through the image data
associated with an http request (which is what the fopen wrapper
essentially performs behind the scenes.) It's possible that the prod
servers (those making the call to fopen) aren't configured to allow the
http wrapper. It could just be as simple as allow_url_fopen being set to
false, in contrast to the configuration of the dev server(s).

http://php.net/manual/en/function.fopen.php
http://php.net/manual/en/wrappers.php
http://www.php.net/manual/en/wrappers.http.php

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] newbie with imap_mail_move

2013-02-09 Thread Adam Richardson
On Sat, Feb 9, 2013 at 7:29 PM, dealTek deal...@gmail.com wrote:


 Warning: reset() [function.reset]: Passed variable is not an array or
 object in /home/bbeast/public_html/emtest/em-move.php on line 91



 if ($mbox_name != $newmbox_name) {
   reset($msg_no);
   $messageset = implode (,,$msg_no);
   imap_mail_move($mbox,$messageset,$newmbox_name);
   imap_expunge($mbox);
 }


Where is the variable $msg_no coming from?

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Integer

2013-02-01 Thread Adam Richardson
On Fri, Feb 1, 2013 at 11:40 PM, Ron Piggott ron.pigg...@actsministries.org
 wrote:

 How can I get the 25 by itself?
 - I want to drop the “2.” and remove all the zero’s

 Would it be best to turn this into a STRING?


I would recommend turning it into a string, splitting the string at the
decimal, then scanning the second string for the first non-zero and storing
the subsequent characters. Working with floats at that precision level
would likely lead to tragic results:

10.0 times .1 is hardly ever 1.0
http://www.eg.bucknell.edu/~xmeng/Course/CS2330/Handout/StyleKP.html

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] seg fault with pecl ps extension

2012-11-28 Thread Adam Richardson
On Wed, Nov 28, 2012 at 10:50 PM, Ray r...@stilltech.net wrote:

 Hello,
 I'm not positive if this is the right list, or if other info is required.
 If this is the wrong list, please recomend a better one. If other info is
 desired, just ask.

 I am having some problems with the PECL PS (postscript) extension. For some
 commands, everything works properly, but when the code tries to deal with
 fonts, it seg faults and core dumps. In my code, the problem appears to be
 caused by the ps_setfont command.
 I have some code that uses it that used to work, but no longer does. I have
 confirmed the same behaviour with the example code that ships with the
 extension, glyphlist.php for a specific example. I have un-installed and
 reinstalled the php5-ps (64 bit) package through the package manager to no
 effect.


Hi Ray,

Does this issue coincide with an upgrade to PHP 5.4, and if so, which
version of PHP were you running before?

You could try to email the maintainer listed, Uwe Steinmann 
u...@steinmann.cx or ste...@php.net, but it looks like it's been a while
since anyone has touched that code.

If this is because of backwards incompatible changes in PHP (e.g.,
http://www.php.net/manual/en/migration54.incompatible.php,
http://php.net/manual/en/migration53.incompatible.php), you could try to
avoid the PHP bindings Uwe developed and merely use PHP to call a C program
that directly deals with his project pslib:
http://pslib.sourceforge.net/

Sorry for the trouble,

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] seg fault with pecl ps extension

2012-11-28 Thread Adam Richardson
On Thu, Nov 29, 2012 at 12:18 AM, Ray r...@stilltech.net wrote:

 ...I first had to deal with a
 change in the way call by reference worked in php. (I had to delete the ''
 from some function calls.) Did that correspond to the 5.3 - 5.4 upgrade?


Yep, 5.4 removed call-time pass-by-reference:
http://www.php.net/manual/en/language.references.pass.php

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] globbed includes?

2012-11-18 Thread Adam Richardson
On Sun, Nov 18, 2012 at 3:29 PM, tamouse mailing lists 
tamouse.li...@gmail.com wrote:

 There are certain times I'd like to include all files in a given
 directory (such as configuration stuff that is split out by type, a la
 apache conf.d). Anyone have something handy that implements that?


http://stackoverflow.com/questions/599670/how-to-include-all-php-files-from-a-directory

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] serialize() casts numeric string keys to integers

2012-11-12 Thread Adam Richardson
On Mon, Nov 12, 2012 at 2:18 AM, eyal.t eya...@zend.com wrote:

 Hi all,

 Was wondering whether the fact that serialize() casts numeric string keys
 to integers, is a bug, intended behaviour, or just something that is minor
 enough not to have bothered anyone yet?


This behavior is consistent with the standard key casts for arrays:
http://php.net/manual/en/language.types.array.php

Try dumping the array before the serialize operations.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: Re: [PHP] TURBOPY cloud framework + IDE beta available NOW

2012-10-31 Thread Adam Richardson
On Tue, Oct 30, 2012 at 7:33 AM, ma...@behnke.biz ma...@behnke.biz wrote:


 In times of testability and several design patters, the use of static
 calls is
 really outdated.
 I understand that you can read and write the invocations of the methods
 much
 faster, but you should think more to the future on that point.


What?

Where is it written that the use of static calls is really outdated?
Functional programming is on the rise, and this is largely because of the
virtues of testability, scalability, and simplified patterns. Using a class
to organize a set of static functions can benefit the code in PHP (allow
for autoloading in PHP because functions can't be autoloaded, essentially
serves as a child namespace, etc.) whilst maintaining the benefits of a
more functional approach (unit testing purely written static functions is
much easier, putting all IO tasks in separate components makes for cleaner
modules, etc.)

I try to emulate functional approaches in PHP, such as what you'd find in
Scala, Clojure, or Haskell, and static calls in PHP can facilitate this
approach.

While OOP is one way to approach programming, it's not the only way. Even
Rasmus has said he leans procedurally:
http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] TURBOPY cloud framework + IDE beta available NOW

2012-10-31 Thread Adam Richardson
On Wed, Oct 31, 2012 at 4:46 PM, Marco Behnke ma...@behnke.biz wrote:


 1. If you have code using static methods and members and use phpunit for
 testing it, you have to either make sure, that everything is properly
 resetted after use OR have to run phpunit in a mode where every test is run
 in a single php call for itself. One is potentially harmful to the test if
 you forgot some side effects and one is time consuming.


There are potentially harmful conditions are present in all unit tests.
If there's an error in the test, you find it and fix it, whether it's due
to a failure to reset the static properties, accidental mutation of data,
instantiating the wrong object, etc.


 2. When thinking about dependency injection (give everything you use
 inside, from the ouside in), show me how one can do this with classes
 WITHOUT passing strings around? And without DI, how do you keep your
 application flexible to different environments and conditions?

  I try to emulate functional approaches in PHP, such as what you'd find in
 Scala, Clojure, or Haskell, and static calls in PHP can facilitate this
 approach.

 While OOP is one way to approach programming, it's not the only way. Even
 Rasmus has said he leans 
 procedurally:http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

  Are you serious quoting that post?
 Posted by Rasmus http://toys.lerdorf.com/authors/1-Rasmus on **Monday,
 February 27. 2006
 **


Yes, seriously, I quoted that post. There is nothing inherently wrong with
a procedural approach to programming, an OO approach to programming, a
functional approach to programming, an AO approach to programming, etc.
Each has there advantages, and not all are available when programming in
particular languages.

When I code in C, I'm not thinking in OO terms. Although I do sometimes use
function pointers in a way that allows me to emulate functional
programming, I'm mostly thinking in procedural terms because the language
affords this.

When I coded in Clojure, I learned to think in immutable terms and embrace
meta-programming.

As I'm learning Go, I'm learning how to think in terms of data and
algorithms involving a clean, convenient separation using interfaces.

When I code in PHP, I tend to take a functional programming approach. But,
I'll sometimes use OOP principles if the situation feels right (although
this is rare.)

Now, back to your comment on DI. DI is cool for OOP, but I don't find I
need it as much when I'm working from a functional programming paradigm.
Others have spoken on the topic of DI in functional languages, but I tend
to use other approaches, such as passing in first-class functions (PHP's
Closure objects create the appearance of this.)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] Rest

2012-10-27 Thread Adam Tong
Hi,

I need to develop a rest API.I want your feedback on how you develop
rest apis. I don't want to use a heavy framework just for that, and I
find url rewriting time consuming.

Any suggestions?

Thank you

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



Re: [PHP] PDO

2012-10-22 Thread Adam Richardson
On Mon, Oct 22, 2012 at 5:27 PM, Silvio Siefke siefke_lis...@web.de wrote:
 Hello,

 i have built php 5.4.7 on Ubuntu with the configure Arguments like on my
 Gentoo System. But on Gentoo run the website without Problems, under Ubuntu
 want not work. I become in error.log:

 [22-Oct-2012 21:15:00 UTC] PHP Fatal error:  Call to a member function
 prepare() on a non-object in html/index.html on line 23


Can you show the code in db.php (just remember to remove any login
credentials)? It looks like there's an issue creating the $db object
you're using.

Adam



-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] PHP to decode AES

2012-10-18 Thread Adam Richardson
On Thu, Oct 18, 2012 at 12:06 PM, Rick Dwyer rpdw...@earthlink.net wrote:
 Hello all.

 Has anyone ever tried to decode a JAVA AES/CBC encrypted string with PHP 
 before?

 I found a tutorial online with the following code to use as starting point, 
 but it fails to return anything readable:

 $code ='Hello World';
 $key = 'my key';

 function decrypt($code, $key) {
 $key = hex2bin($key);
 $code = hex2bin($code);
 $td = mcrypt_module_open(rijndael-128, , cbc, );
 mcrypt_generic_init($td, $key, fedcba9876543210);
 $decrypted = mdecrypt_generic($td, $code);
 mcrypt_generic_deinit($td);
 mcrypt_module_close($td);
 return utf8_encode(trim($decrypted));
 }


 function hex2bin($hexdata) {
 $bindata = ;
 for ($i = 0; $i  strlen($hexdata); $i += 2) {
 $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
 }
 return $bindata;
 }
 echo decrypt($code, $key);

 The above returns output containing a series of unprintable characters.

 I thought maybe it was due to $code not being in a hex format, but after 
 converting to hex and resubmitting, I still unprintable characters.

 Any info is appreciated.

Can you post the Java code you're using? There are things such as the
padding specification that could cause some issues.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] Wrong time being displayed by PHP!

2012-10-16 Thread Adam Richardson
On Tue, Oct 16, 2012 at 2:02 PM, Richard S. Crawford
rich...@underpope.com wrote:
 The value of date.timezone in php.ini is set to America/Los_Angeles.

 The local time is 11:02 a.m. Yet the output of date(h:i a e) is:

 02:02 pm America/Los_Angeles

 which is three hours ahead of the real time.

 Why is this? What's going on?

The server's time could be wrong. Or, code somewhere could be
(re)setting the timezone.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] stream_read function for registered wrapper class.

2012-09-19 Thread Adam Richardson
On Wed, Sep 19, 2012 at 12:43 PM, Rob rob_ad...@hotmail.com wrote:
 I have a very large XML file that I have to process.  It's about 7 GB.
 Some of the individual elements that I need are larger than 8192 bytes.
 I'm trying to write a Stream wrapper class to give me a specific element
 at a time, but I keep running into issues with the stream wrapper and
 fread, stream_get_content functions.

You could just use the XML Parser (SAX) as it doesn't require loading
the entire document into memory:
http://php.net/manual/en/book.xml.php

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] PHP array unions

2012-09-14 Thread Adam Richardson
On Fri, Sep 14, 2012 at 2:30 AM, Matijn Woudt tijn...@gmail.com wrote:

 It doesn't need to be clunky.. just use array_flip and you've got the old
 array again..


Well, array_flip has it's own potential issues (duplicate values are
lost, so my example of using zeros would not work.) I suppose I could
duplicate the keys as the values (e.g., array('value 1' = 'value 1',
'value 2' = 'value 2', ...).) Then, the keys would  allow me to
utilize the nice properties of hash maps whilst maintaining the
ability to work with the values as one normally does in typical array
functions.

Ex:

$a1 = array('apples' = 'apples', 'oranges' = 'oranges', 'pears' = 'pears');
$a2 = array('oranges' = 'oranges', 'kiwi' = 'kiwi');
// can use the union operator without any additional calls and the
performance is stellar
$a3 = $a1 + $a2
// can use the values of the array using the convention that the value
is what you expect to handle/manipulate
foreach ($a3 as $val) {
  echo $val
}

Here, the clunkiness is the redundancy in the array, but, as Claude
Shannon has demonstrated, redundancy isn't all bad :)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] PHP Threading on Windows

2012-09-14 Thread Adam Richardson
On Fri, Sep 14, 2012 at 9:40 PM, Joe Watkins joe.watk...@live.co.uk wrote:
 https://github.com/krakjoe/pthreads

 Windows Download on downloads page, it's a couple of days behind. Keep
 watching ... enough to get you started ...

That's pretty slick, Joe. Nice work!

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] PHP array unions

2012-09-13 Thread Adam Richardson
On Wed, Sep 12, 2012 at 2:37 PM, Sebastian Krebs krebs@gmail.com wrote:
 Hi,

 In PHP the array is in fact a hash map, but especially it is _used_ for
 nearly everything map-, set-, ...-like thing. So in short: The is no
 operator or built-in function, that merges two arrays _and_ treat them as
 set (instead of the hashmap, what they are). Your solution is the way to go.

Sure, I know about the underlying implementation. I was just hopeful
because several of the array functions handle the maps differently
depending on whether the keys are numeric or string or both.

If I wanted to get cute, I could store the value in the key (e.g.,
array('value 1' = 0, 'value 2' = 0, ...)), and that allows me to use
the '+' operator. In spite of the nice performance benefits of this
approach (leveraging the hashes benefits), the code that utilizes the
arrays becomes quite clunky.

Thanks,

Adam

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



Re: [PHP] The end of mysql

2012-09-07 Thread Adam Richardson
On Fri, Sep 7, 2012 at 9:58 PM, Jim Giner jim.gi...@albanyhandball.com wrote:
 So with the announced end of the mysql functions (and switching to a
 different extension), one would think that my isp/hoster would be a bit more
 interested in my dilemma.  I tried today to create my first mysqli-based
 test script and found that I didn't have that extension.  A series of emails
 with my tech support told me that the shared server farm does not get
 mysqli - only their business servers.  Since I dont' have a need for and
 want to pay more for a 'business server', I'm told I'm s... outta luck.

What about PDO? Is that available?

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] templeting

2012-09-04 Thread Adam Richardson
On Mon, Sep 3, 2012 at 9:14 PM, David McGlone da...@dmcentral.net wrote:
 Does anyone use any templeting system for any projects? If so what would
 anyone recommend? I looked at Code Ignitor, but it seems the templeting system
 is optional and left out by default.

 --
 Regards
 David M.

Well, for a different take on templating, my web framework is
basically just a combination of input validation and output mechanisms
(templating.) The library takes a functional programming approach in
terms of architecture.

Here's an example of the markup:
http://nephtaliproject.com/documentation/markup/

Page output regions are broken up into pipes, and if one pipe errors
out, it does not impact the other output regions.

It does other things, too (config settings, debugging output, avoid
prompts on back clicks after posting data, convenient PDO wrappers,
etc.), but at its core, it's really a templating framework with input
validation capabilities.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] include selectively or globally?

2012-08-28 Thread Adam Richardson
On Tue, Aug 28, 2012 at 7:39 AM, Matijn Woudt tijn...@gmail.com wrote:
 On Tue, Aug 28, 2012 at 3:49 AM, Adam Richardson simples...@gmail.com wrote:
 On Mon, Aug 27, 2012 at 6:54 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Mon, Aug 27, 2012 at 10:56 PM, Haluk Karamete
 halukkaram...@gmail.com wrote:

 First of all, I believe PHP is smart enough to not generate bytecode
 for functions that are not used in the current file. Think about the
 fact that you can write a function with errors, which will run fine
 until you call the function. (except for syntax errors).

I believe this is untrue. PHP generates the bytecode and then parses
the bytecode per request to generate the userland infrastructure,
including classes and functions, for the entire include file. During
the generation of bytecode, PHP doesn't know apriori which functions
will be called at runtime. I suspect if you asked for confirmation of
this on the internals list, they'd confirm this. In terms of errors,
there are certainly different stages that errors can occur, and what
you're referring to are runtime errors. Runtime errors don't
necessarily show up in every possible execution branch. That doesn't
mean that PHP didn't generate the code for the userland functionality.

 The speed difference between loading 5K file or 50K file (assuming
 continuous blocks) is extremely small. If you split this library, you
 would have PHP files that require you to load maybe 3 or 4 different
 files to have all their functions.

Here's where I believe we have a communication issue. I never spoke of
splitting up the library into 3 or 4, or any number of different
files. The opening post states that only 10% of the pages need the
library. I suggested that he only include the library in the 10% of
the pages that need the library. That said, it's possible I
misinterpreted him.

I will say that I do disagree with your analysis that difference
between loading a 5K or 50K php file is extremely small. So I just put
this to the test.

I created a 5K file and a 50K file, both of which have the form:

function hello1(){
echo hello again;
}

function hello2(){
echo hello again;
}

etc.

I have XDegub installed, have APC running, warmed the caches, and then
test a few times. There results all hover around the following:

Including the 5K requires around 50 microseconds. Including the 50K
requires around 180 microseconds. The point is that there is a
significant difference due to the work PHP has to do behind the
scenes, even when functions (or classes, etc. are unused.) And,
relevant to the dialog for this current thread, avoiding including an
unused 50K PHP on 90% of the pages (the pages that don't need the
library) will lead to a real difference.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] include selectively or globally?

2012-08-28 Thread Adam Richardson
On Tue, Aug 28, 2012 at 3:28 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Tue, Aug 28, 2012 at 7:18 PM, Adam Richardson simples...@gmail.com wrote:

 Finally, you're the first one that actually has measured something.
 You should redo your test with real world files, because in real world
 functions aren't that small.

In terms of redoing the test with real world files, that's an
entirely different debate (and one I won't enter into at this time,
though this list has discussed this topic before, most recently in a
post Ted made talking about screen height.)

The point is, there is a real difference. The question remains if the
difference is enough to act on in future code bases (and I would say
yes if my tests showed this difference, you may say no.)

 In functions with more lines (say ~100 lines per function), you'll see
 a different ratio between 5k and 50k. In my tests it is:
 - 5K: 22ms
 - 50K: 34 ms

Those trends/results depend significantly on the contents of the
functions, too. The overly simplistic example we've used both helps
and hurts the analysis (I'll admit my example likely has more
functions than other 5K/50K files, and I suspect most functions
require more complicated work behind the scenes to build up than echo
statements.)

The point I'd make here is that it's very difficult to have apriori
knowledge of how something will perform without testing it.

 When I create files that only contain 1 function, with just a number
 of echo Hello world; lines until 5k or 50k, the results are:
 - 5K: 15 ms
 - 50K: 17 ms

Ummm... sure. What did you say about real world before :)

Have a nice day!

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] OT (maybe not): Drupal vs WordPress

2012-08-28 Thread Adam Richardson
On Tue, Aug 28, 2012 at 3:07 PM, Larry Garfield la...@garfieldtech.com wrote:
 Only semi-joking line that's been making the rounds lately:

 If you want to build a blog, use Wordpress.
 If you want to build Wordpress, use Drupal.
 If you want to build Drupal, use Symfony2.

Here's another semi-joking line :)

If build a blog using Wordpress, build Wordpress using Drupal, build a
Drupal using Symfony2, I'd feel the same way I feel after drinking
several beers, eating a pizza, snacking on some hot wings, and
polishing it all off with a banana split: bloated :)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] include selectively or globally?

2012-08-27 Thread Adam Richardson
On Mon, Aug 27, 2012 at 6:54 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Mon, Aug 27, 2012 at 10:56 PM, Haluk Karamete
 halukkaram...@gmail.com wrote:

 Now, the question is... should you use a global include that points to
 this library - across the board - so that ALL the pages ( including
 the 90% that do not need the library ) will get it, or should you
 selectively add that include reference only on the pages you need?


 Since searching for files is one of the most expensive (in time)
 operations, you're probably best off with only a single PHP file.

Maybe I misinterpreted the question, but I don't think I agree.

If you have a 50K PHP file that's only needed in only 10% of the
pages, then, when solely considering performance, that file should
only be included on the 10% of the pages that actually use the file.
Now, there are reasons where you might want to include the file
globally (maintenance purposes, etc.) Loading the 50K of PHP code
requires building up all of the associated infrastructure (zvals,
etc.) for the user code (even if APC is used, the cached opcode/PHP
bytecode still has to be parsed and built up for the user-defined
classes and functions per request, even if they're unused), is
certainly going to perform more slowly than selectively including the
library on only the pages that need the library.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] multiple forms one page

2012-08-26 Thread Adam Richardson
On Mon, Aug 27, 2012 at 12:08 AM, Rosie Williams
rosiemariewilli...@hotmail.com wrote:

 Hi all,
 I am a newbie to PHP. I have several php forms which were originally on 
 separate pages now included in the one page. Each form had the following code 
 in it:
 function mysql_fix_string($string){ if (get_magic_quotes_gpc()) $string = 
 stripslashes($string);return mysql_real_escape_string($string);}
 function mysql_entities_fix_string($string){return 
 htmlentities(mysql_fix_string($string));}
 However I am only able to include it in one of the forms on the new page with 
 multiple scripts due to the fatal error that I can only declare the function 
 once.

You only have to declare the function(s) once, then you can use them
later in the page. You can also put code into files and then
dynamically include them in other files to make it easier to share
functionality.

 So for testing I have commented these lines out of the other scripts. I need 
 to know what the security implications of  this are?

For security, the simple rule (at least in terms of statement of
intent, not necessarily in terms of implementation) is that you should
validate input and escape output according to context. Without seeing
more code, it's hard to tell what this means for your particular
example.

 Do the scripts that do not contain these lines run without it or is it 
 included automatically every time the database is accessed regardless of 
 which script is accessing it?
 If not how do I deal with it?
 thanks in advanceRosie

Hard to know from your example. There are some great resources
covering general PHP security practices that can help you get up to
speed a bit. Here's an oldie but goodie that might help shed some
light on some of the code you're seeing:
http://www.ibm.com/developerworks/opensource/library/os-php-secure-apps/index.html

Happy learning!

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] redefine a define ...

2012-08-25 Thread Adam Richardson
On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine les...@lsces.co.uk wrote:
 What I was not expecting was a string of 'Notices:' complaining about the
 redefines. So how does one get around this message? One can't 'if defined'
 as the string needs to be replaced with the more appropriate one. I would
 say, why is this even a problem, or alternatively I just give up on E_STRICT
 and make sure it's disabled again on PHP5.4?

 Having spent several months getting the code clean on E_STRICT, switching it
 off again will really pig me off, but I can't see any real alternative given
 the number of languages and strings that will need reworking simply to get
 things clean :(

Well, I'd do the following to avoid issues in the future.

1) Create a function like that below, which provides global access to
variables and allows you to update existing values:

function val($name, $value = null)
{
static $values = array();

if ($value === null) {
return isset($values[$name]) ? $values[$name] : null;
} else {
return $values[$name];
}
 }

2) Create a php script that searches out define(SOME_NAME_PATTERN,
value) and replaces that with val(some_name_pattern, value).

3) Create a php script that searches out SOME_NAME_PATTERN and
replaces with val(SOME_NAME_PATTERN);

Not too bad in terms of work, as PHP's parsing capabilities are really nice.

Hope this gives you ideas :)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] syntax error breaking in and out of php into html code

2012-08-25 Thread Adam Richardson
On Sat, Aug 25, 2012 at 6:54 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 I've just inherited some (pretty awful code) that I have to make some
 edits to, and came across a bit of a problem. A lot of the code breaks
 in and out of PHP and into HTML code:

  ?php
 while(condition)
 {
 ?
 lisome html here/li
 ?php
 }
 ?

 But when I check this my PHP parser is saying that this is a syntax
 error (checked in the browser and CLI). I know this is code from a
 working site, so it must be a setting within my PHP configuration.

I honestly can't think of a config setting that would cause a syntax
error for this type of example.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] Is PHP unsuitable for HTML5 WebSockets?

2012-08-13 Thread Adam Richardson
 I have read in some places on the net that PHP is not suitable for WebSockets 
 due to it's nature. That WebSockets are designed for long running 
 threads/processes which each maintain multiple event-driven connections, 
 whereas PHP was designed around the short-lived single process procedural 
 paradigm.

Well, you could certainly run into trouble if you're not careful. For
example, using an Apache module PHP installation would not likely end
nicely :)

 Yet on the other hand I see lots of guides and libraries (such as 
 http://socketo.me/) on the net that deal with PHP WebSockets. So I don't know 
 what to think at this stage. Is PHP a suitable platform for developing a web 
 application that requires WebSockets?

I'm sure you could get get your application running with PHP. That
said, I personally would not use PHP for the web socket implementation
in my stack. I'd probably use Go, node.js or even Erlang for the web
socket server itself (non-blocking IO is baked into these
environments, which is handy for limiting the resources required for
this type of application), but I'd likely use PHP for components that
weren't directly tied to the web sockets (db frontend, etc.)

Obviously, that's just my personal preference, and as you've noted,
people are doing nice things in the web sockets world with PHP, so it
can be done. That said, I suspect I'd have an easier time with one of
the other languages for this particular aspect of an application, as
the resource management should be much easier to manage. I don't think
there's a right tool for the job, but I do believe some language
environments may better facilitate this specific type of development.

Have fun!

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



RE: [PHP] What do you call the end-user?

2012-07-20 Thread Adam Nicholls


 -Original Message-
 From: Tedd Sperling [mailto:t...@sperling.com]
 Sent: 19 July 2012 18:27
 To: php-general@lists.php.net General
 Subject: [PHP] What do you call the end-user?
 
 What do you call the people who ultimately use your code?
 
 I call them the end-user, but others have stated other terms, such as
 customer or user.
 
 Cheers,
 
 tedd
 
 
 t...@sperling.com
 http://sperling.com



I suppose if you're working in Agile, you could also call them Stakeholders or 
the Product Owner.

Personally if I'm feeling a bit cheeky I'll go with Muggle - (thanks to J K 
Rowling!) - people just don't appreciate the magic involved behind the scenes 
in usability, infrastructure, application logic etc.

Thanks
Adam.
=

This email is intended solely for the recipient and is confidential and not for 
third party unauthorised distribution. If an addressing or transmission error 
has misdirected this email, please notify the author by replying to this email 
or notifying the system manager (online.secur...@hl.co.uk).  If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
this email. 

Any opinions expressed in this document are those of the author and do not 
necessarily reflect the opinions of Hargreaves Lansdown. In addition, staff are 
not authorised to enter into any contract through email and therefore nothing 
contained herein should be construed as such. Hargreaves Lansdown makes no 
warranty as to the accuracy or completeness of any information contained within 
this email. In particular, Hargreaves Lansdown does not accept responsibility 
for any changes made to this email after it was sent. 

Hargreaves Lansdown Asset Management Limited (Company Registration No 1896481), 
Hargreaves Lansdown Fund Managers Limited (No 2707155), Hargreaves Lansdown 
Pensions Direct Limited (No 3509545) and Hargreaves Lansdown Stockbrokers 
Limited (No 1822701) are authorised and regulated by the Financial Services 
Authority and registered in England and Wales. The registered office for all 
companies is One College Square South, Anchor Road, Bristol, BS1 5HL. 
Telephone: 0117 988 9880

__
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
__


RE: [PHP] Entry point of an MVC framework

2012-07-13 Thread Adam Nicholls


 -Original Message-
 From: Simon Dániel [mailto:simondan...@gmail.com]
 Sent: 12 July 2012 21:21
 To: php-general@lists.php.net
 Subject: [PHP] Entry point of an MVC framework
 
 Hi,
 
 I have started to develop a simple MVC framework.
 
 I have a base controller class which is abstract and all of the controllers 
 are
 inherited from that. Every controller contains actions represented by
 methods. (E. g. there is a controller for managing product items in a
 webshop, and there are seperate actions for create, modify, remove, etc.)
 There is also a default action (usually an index page), which is used when
 nothing is requested.
 
 But what is the best way to invoke an action? I can't do it with the
 baseController constructor, becouse parent class can't see inherited classes.
 And I can't do it with the constructor of the inherited class, becouse this 
 way I
 would overwrite the parent constructor. And as far as I know, it is not a good
 practice to call a method outside of the class, becouse the concept of
 operation of the class should be hidden from the other parts of the
 application.
 
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
 http://www.php.net/unsub.php

Hi Simon,

You'll probably want to look at Bootstrapping your framework too. Ideally the 
bootstrap will include (or have an autoload function) to load your classes - 
controllers/models/views, and it'll also deal with routing so deciding which 
controller and action to call based on the URL, this usually involves doing an 
explode() on the $_SERVER['QUERY_STRING'], and using Apache's mod_rewrite to 
forward all requests to your bootstrap (often named index.php)

Building frameworks and going through the motions are a great way to build up 
experience and play with areas of the language you might not normally use, you 
might want to get inventive with the Reflection class to check actions or 
controllers exist and then forward the user to a 404 page later on.

Cheers
Adam.

=

This email is intended solely for the recipient and is confidential and not for 
third party unauthorised distribution. If an addressing or transmission error 
has misdirected this email, please notify the author by replying to this email 
or notifying the system manager (online.secur...@hl.co.uk).  If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
this email. 

Any opinions expressed in this document are those of the author and do not 
necessarily reflect the opinions of Hargreaves Lansdown. In addition, staff are 
not authorised to enter into any contract through email and therefore nothing 
contained herein should be construed as such. Hargreaves Lansdown makes no 
warranty as to the accuracy or completeness of any information contained within 
this email. In particular, Hargreaves Lansdown does not accept responsibility 
for any changes made to this email after it was sent. 

Hargreaves Lansdown Asset Management Limited (Company Registration No 1896481), 
Hargreaves Lansdown Fund Managers Limited (No 2707155), Hargreaves Lansdown 
Pensions Direct Limited (No 3509545) and Hargreaves Lansdown Stockbrokers 
Limited (No 1822701) are authorised and regulated by the Financial Services 
Authority and registered in England and Wales. The registered office for all 
companies is One College Square South, Anchor Road, Bristol, BS1 5HL. 
Telephone: 0117 988 9880

__
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
__


RE: [PHP] database hell

2012-07-12 Thread Adam Nicholls


 -Original Message-
 From: Nick Edwards [mailto:nick.z.edwa...@gmail.com]
 Sent: 12 July 2012 12:30
 To: php-general@lists.php.net
 Subject: [PHP] database hell
 
 Hi
 
 We have a program that manages users, throughout all database calls
 
 created as:
 $connect = mysql_connect($db_host--other variables);
 mysql_query(Delete from clients where id=$User);
 
 All this works good, but, we need, in the delete function to delete from
 another database
 
 $connmy=mysql_connect(host,user,pass);
 mysql_select_db(vsq,$connmy);
 mysql_query(DELETE from userprefs where 
 clientr='$User');
 $mysql_close($connmy); this fails, unless we use a mysql_close prior to it,
 and then reconnect to original database after we run this delete, how can we
 get around this without closing and reopening?
 We have a  perl script doing similar for manual runs, and it works well
 knowing that $connmy is not $connect, I'm sure there is a simple way to tell
 php but  I'm darned if I can see it.
 
 Thanks
 Niki
 
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
 http://www.php.net/unsub.php


Just create a new resource/connection to MySQL and pass the identifier into 
mysql_query().
You'll also want to use mysql_real_escape_string() by the looks of it to 
attempt to stop SQL injection.


Something like this will do it:

$db1 = mysql_connect($host,$user,$pass);
$db2 = mysql_connect($host,$user,$pass);

mysql_select_db('db1',$db1);
mysql_select_db('db2',$db2);

// do your queries with $DB1

$result = mysql_query(delete from userprefs where 
clientr=.mysql_real_escape_string($user,$db1)., $db1);

// do your queries again with $DB1

mysql_close($db1);//close db1
mysql_close($db2);//close db2


Cheers
Adam.

=

This email is intended solely for the recipient and is confidential and not for 
third party unauthorised distribution. If an addressing or transmission error 
has misdirected this email, please notify the author by replying to this email 
or notifying the system manager (online.secur...@hl.co.uk).  If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
this email. 

Any opinions expressed in this document are those of the author and do not 
necessarily reflect the opinions of Hargreaves Lansdown. In addition, staff are 
not authorised to enter into any contract through email and therefore nothing 
contained herein should be construed as such. Hargreaves Lansdown makes no 
warranty as to the accuracy or completeness of any information contained within 
this email. In particular, Hargreaves Lansdown does not accept responsibility 
for any changes made to this email after it was sent. 

Hargreaves Lansdown Asset Management Limited (Company Registration No 1896481), 
Hargreaves Lansdown Fund Managers Limited (No 2707155), Hargreaves Lansdown 
Pensions Direct Limited (No 3509545) and Hargreaves Lansdown Stockbrokers 
Limited (No 1822701) are authorised and regulated by the Financial Services 
Authority and registered in England and Wales. The registered office for all 
companies is One College Square South, Anchor Road, Bristol, BS1 5HL. 
Telephone: 0117 988 9880

__
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
__


Re: [PHP] Re: show info from mysql db

2012-06-10 Thread Adam Richardson
On Sun, Jun 10, 2012 at 8:25 AM, Tim Dunphy bluethu...@gmail.com wrote:
 $dbc = mysqli_connect('127.0.0.1','admin',secret','trek_db')
     or die ('Could not connect to database');

 used to be...

 $dbc = mysqli_conect('127.0.0.1','admin','Duk30fZh0u','trek_db')
     or die ('Could not connect to database');

You had been keeping the password secret, but it looks like you
accidentally leaked it, so a replacement might be in order :)

Glad you got it fixed. Typos can be little buggers to find sometimes.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] SQL Injection

2012-06-08 Thread Adam Richardson
On Fri, Jun 8, 2012 at 12:37 PM, Ethan Rosenberg eth...@earthlink.net wrote:
 Is it possible to have a meeting of the minds to come up with (an)
 appropriate method(s)?

Minds, meet prepared statements :)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] Too many arrays! My head is exploding!

2012-05-29 Thread Adam Richardson
On Tue, May 29, 2012 at 10:55 AM, Tedd Sperling t...@sperling.com wrote:
 On 29 May 2012 18:15, Gary listgj-phpgene...@yahoo.co.uk wrote:

 Okay, let's assume I have three things, A, B, and C. I need to produce
 an array with a list of all possible combinations of them, however many
 there might be in those combinations: e.g. A, B, C, D, AB, AC, AD, BC,
 ABC (not sure if I've missed any!). Normally I'm pretty good at working
 this stuff out, but to be honest I'm struggling with this one, at least
 to do it in any kind of elegant way. Does anyone have any ideas?

 Sure, but what you are asking for is a permutation and not a combination.

His example seems to suggest order does not matter (I've omitted 'D',
which I suspect was a typo given the set of A, B, and C):

A
B
C
AB
AC
BC
ABC

If order did matter, he would have included BA, etc.

That all said, combinations typically involve a consistent number of
choices, and his example includes various ranges of r.

These would be combinations for r = 1:
A
B
C

These would be combinations for r = 2:
AB
AC
BC

This would be the combination for r = 3:
ABC

What it seems like he's after is the power set of set ABC (minus the empty set):
http://en.wikipedia.org/wiki/Power_set

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] Variables via url

2012-05-12 Thread Adam Richardson
On Sat, May 12, 2012 at 12:25 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 As this method requires an Apache restart, I don't see what advantage
 you have over using an .htaccess file?

Performance:

http://httpd.apache.org/docs/current/howto/htaccess.html

You should avoid using .htaccess files completely if you have access
to httpd main server config file. Using .htaccess files slows down
your Apache http server. Any directive that you can include in a
.htaccess file is better set in a Directory block, as it will have the
same effect with better performance.

...putting this configuration in your server configuration file will
result in less of a performance hit, as the configuration is loaded
once when httpd starts, rather than every time a file is requested.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] session lost problem

2012-04-24 Thread Adam Richardson
On Tue, Apr 24, 2012 at 12:58 AM, bug zhu bugw...@gmail.com wrote:
 there are tow php files a.php and b.php,

 content of a.php as follows:
 ?php
 session_start();
 if (!isset($_GET['flag']))
 {
 header('Location: b.php');
 }
 else
 {
 var_dump($_SESSION);
 }

 content of  b.php as follows:
 ?php
 session_start();
 session_commit();
 $_SESSION['test'] = 'test';
 session_commit();
 header('Location: a.php?flag=1');

 when i visit a.php, the dumped $_SESSION array is empty
 but if i commented the first session_commit() in b.php and then visit
 a.php, i cound see the $_SESSION array,which is not empty
 i wish i have descibed  clear about my problem and someone could give me a
 feedback~

Hi,

So, you:
1) Visit page a.php (I'm assuming without the flag)
2) Are forwarded to page b.php, which you're expecting to store a
session variable 'test'.
3) Then forwarded back to page a.php.

You're likely expecting that you're return visit to page a.php should
reveal the 'test' variable.

The issue is that you're calling session_commit(), which is actually
an alias for session_write_close(). This function actually stops the
current session. So, when you hit the line $_SESSION['test'] = 'test',
your session has already terminated.

Try removing the session_commit() calls (or at least permanently
remove the first call.) You only want to call session_commit() when
you're done accessing/updating $_SESSION variables.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] Variable representation

2012-04-01 Thread Adam Randall
It would better to just use an array, and then iterate through that.

$images[] =  stripslashes( $row['image_1'] );
$images[] =  stripslashes( $row['image_2'] );
$images[] =  stripslashes( $row['image_3'] );
$images[] =  stripslashes( $row['image_4'] );

foreach( $images as $k = $v ) {
$k++; // increment k since it starts at 0, instead of 1
if ( strlen( trim( $v ) ) ) {
echo lia href=\http://www.theverseoftheday.info/store-images/;
. $v . \ title=\Image  . $k . \Image  . $k . /a/li\r\n;
}
}

Adam.

On Sun, Apr 1, 2012 at 8:52 PM, Ron Piggott
ron.pigg...@actsministries.orgwrote:

 Hi Everyone:

 I am assigning the value of 4 images to variables following a database
 query:

 $image_1 = stripslashes( $row['image_1'] );
 $image_2 = stripslashes( $row['image_2'] );
 $image_3 = stripslashes( $row['image_3'] );
 $image_4 = stripslashes( $row['image_4'] );

 What I need help with is how to represent the variable using $i for the
 number portion in the following WHILE loop.  I am not sure of how to
 correctly do it.  I am referring to: $image_{$i}

 ===
 $i = 1;
 while ( $i = 4 ) {

if ( trim( $image_{$i} )   ) {

echo lia href=\http://www.theverseoftheday.info/store-images/;
 . $image_{$i} . \ title=\Image  . $i . \Image  . $i .
 /a/li\r\n;

}

 ++$i;
 }
 ===

 How do I substitute $i for the # so I may use a WHILE loop to display the
 images?  (Not all 4 variables have an image.)

 Ron Piggott



 www.TheVerseOfTheDay.info




-- 
Adam Randall
http://www.xaren.net
AIM: blitz574
Twitter: @randalla0622

To err is human... to really foul up requires the root password.


Re: [PHP] PHP: superior code quality

2012-03-28 Thread Adam Richardson
On Wed, Mar 28, 2012 at 11:21 AM,  kirk.john...@zootweb.com wrote:
 A little note about our favorite language:

 
 Linux 2.6, PHP 5.3, and PostgreSQL 9.1 are recognized as open source
 projects with superior code quality and can be used as industry
 benchmarks, achieving defect densities of .62, .20, and .21 respectively.
 

 http://www.coverity.com/html/press/open-source-code-quality-on-par-with-proprietary-code-in-2011-coverity-scan-report.html

Very nice! Thanks for sharing, Kirk.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Adam Richardson
On Wed, Mar 21, 2012 at 2:39 PM, Jay Blanchard
jay.blanch...@sigmaphinothing.org wrote:
 ...
 I have a project where I have multiple queries and each query uses the 
 results from the previous query to get it's results. I need to do one of two 
 things, either out put a multidimensional array that I can use json_encode() 
 on or I have to format the output from the queries as a JSON string. The 
 resulting JSON will be used by a JavaScript widget and must be formed 
 correctly. I created the following array by hand:

 $userList = array(John = array(
                     email = j...@demo.com,
                     website = www.john.com,
                     age = 22,
                     password = pass,
                     description = array(
                        hair = blonde,
                        eyes = blue,
                        build = medium
                     )),
                  Anna = array(
                     email = a...@demo.com,
                     website = www.anna.com,
                     age = 24,
                     password = pass,
                     description = array(
                        hair = brunette,
                        eyes = hazel,
                        build = petite
                        )
                     ));

 I ran it through json_encode() and got the following output

 {John:{email:j...@demo.com,website:www.john.com,age:22,password:pass,description:{hair:blonde,eyes:blue,build:medium}},Anna:{email:a...@demo.com,website:www.anna.com,age:24,password:pass,description:{hair:brunette,eyes:hazel,build:petite}}}

 jslint.com verifies this as good JSON (although I thought there had to be 
 square brackets around child arrays).

Speaking to your belief that arrays had to have square brackets,
json_encode examines the PHP array and only encodes sequential numbers
JSON arrays. Others (as in your case) are encoded as object literals:
http://php.net/manual/en/function.json-encode.php

That said, you can still access Javascript Object properties with
array access if you prefer in the client code:
http://www.quirksmode.org/js/associative.html

 If you were me would you just generate the JSON? If not what is he best way 
 to output an array that will nest properly for each subsequent query?

Because of the options json_encode provides and the flexibility it
affords while in PHP, I would generate PHP and then always use
json_encode to generate the JSON as needed.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] $POST and $_SESSION

2012-03-15 Thread Adam Richardson
On Thu, Mar 15, 2012 at 11:04 AM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 Hi gang:

 What's a better/shorter way to write this?

 $first_name = $_SESSION['first_name'] ? $_SESSION['first_name'] : null;
 $first_name = isset($_POST['first_name']) ? $_POST['first_name'] : 
 $first_name;
 $_SESSION['first_name'] = $first_name;

When not working within my framework (which facilitates this
automatically), I tend to have a function for each just to save time:

function g($key){
   return isset($_GET[$key]) ? $_GET[$key] : null;
}

function p($key){
   return isset($_POST[$key]) ? $_POST[$key] : null;
}

function c($key){
   return isset($_COOKIE[$key]) ? $_COOKIE[$key] : null;
}

function s($key, $val = null){
   !isset($_SESSION)  session_start();

   if ($val === null) {
  return isset($_SESSION[$key]) ? $_SESSION[$key] : null;
   } else {
  return $_SESSION[$key] = $val;
   }
}

Then, you can just write:

$first_name = s('first_name', p('first_name'));

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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



Re: [PHP] Insert new array after specific key in multidimensional array

2012-02-28 Thread Adam Richardson
On Mon, Feb 27, 2012 at 9:12 PM, Micky Hulse mickyhulse.li...@gmail.comwrote:

 Howdy!

 Example code:

 https://gist.github.com/1928452

 What would be the best way to insert $o_insert array into $o array
 after specified key?

 I hate to just ask for example code, but I can't seem to find the
 perfect solution. :(

 Many thanks in advance for the help!

 Cheers,
 Micky

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


Out of curiosity, why are you worried about the order of elements in an
associative array?

Thanks,

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] How do I enable more useful PHP error logging?

2012-02-28 Thread Adam Richardson
On Tue, Feb 28, 2012 at 6:14 PM, Daevid Vincent dae...@daevid.com wrote:

 My question is, is there a way to enable some PHP configuration that would
 output more verbose information, such as a backtrace or the URL attempted?

 In our PHP error log, we have the usual semi-useful information. However
 this is only a partial story as it's hard to re-create the URL that caused
 the error. In the first Actor example, yeah actor_id 2206 doesn't exist and
 so now I have put a try/catch on all pages that have new Actor($actor_id)
 but it doesn't tell me WHY this is happening. How did someone get to this
 point? I doubt they just randomly picked '2206' which happens to be one of
 only a handful of actually missing actors out of 100k. Sure I guess it
 could
 be a bot that sequentially tried them all, but this is not likely since we
 have SEO style URLs and so we re-map an actor name back to the ID. So the
 bot would have to try NAMEs not IDs. This means we must have some link
 somewhere that points to this. Same with the common foreach() warnings
 below. Yeah, the array being passed is empty/null. Sure I can check the
 array before doing the foreach() or even @foreach() but that doesn't tell
 me
 the root cause. What video are they trying to access that has no scenes or
 invalid actors?

 We do NOT have apache logging turned on as we get 30,000 hits per second
 and
 it would be too expensive. I only care about PHP errors like this. And the
 apache error log (which we do have enabled) doesn't have useful info
 related
 to these kinds of issues as they're really not apache's problem. That log
 only deals with missing files/images/pages/etc.

 [28-Feb-2012 13:43:19 UTC] PHP Fatal error:  Uncaught exception
 'ObjectNotFound' with message 'There is no such object Actor [2206].' in
 /home/SHARED/classes/base.class.php:103
 Stack trace:
 #0 /home/SHARED/classes/actor.class.php(61): Base-load_from_sql()
 #1 /home/m.videosz.com/browse_scenes.php(89): Actor-__construct(2206)
 #2 {main}
   thrown in /home/SHARED/classes/base.class.php on line 103

 [28-Feb-2012 10:54:01 UTC] PHP Warning:  Invalid argument supplied for
 foreach() in /home/m.dev.com/scene.php on line 138

 [28-Feb-2012 07:22:50 UTC] PHP Warning:  Invalid argument supplied for
 foreach() in /home/SHARED/classes/scene.class.php on line 423



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


I tend to set up a custom error handler that throws exceptions
(set_error_handler()), then set up an exception handler
(set_exception_handler()) that logs the backtrace (or saves it to a db)
available using debug_backtrace().

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] Great video by Bret Victor: Inventing on Principle

2012-02-25 Thread Adam Richardson
Saw this on the Clojure list and thought it was worth sharing here, too:
http://vimeo.com/36579366

Worth the hour of time to watch it, as it has some great ideas for
improving the experience of developers.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] Race Condition In PHP Session Handler

2012-02-20 Thread Adam Tauno Williams
php-5.3.3-3.el6_2.6.x86_64
2.6.32-220.4.2.el6.x86_64

After some testing we moved our production PHP intranet site from an old
server to a new CentOS 6.2 instance running the mentioned versions.  At
first it worked well and then user's started to experience a hung site.
Upon some digging it appears that the PHP module is getting stuck in a
race condition regarding the sessions file -

[root@yannigan-orange fd]# strace -p  22607
Process 22607 attached - interrupt to quit
flock(53, LOCK_EX^C unfinished ...

where file handle 53 is 

...
lr-x--. 1 root root 64 Feb 17 15:24 52
- /opt/informix/msg/en_us/0333/cli.iem
lrwx--. 1 root root 64 Feb 17 15:24 53
- /var/lib/php/session/sess_ulgsl9joplobb9o4fue3n2e1k0
l-wx--. 1 root root 64 Feb 17 15:24 6 - pipe:[660246]


The PHP session file.  Originally I had a tmpfs mounted for the session
files.  I removed that and used the underlying filesystem.  Same issue.
I disabled APC.  Same issue.

Switching the the memcache session handler resolved the issue,  although
that may be less optimal.  But this seems like a PHP bug.

Tips, comments, pointers?

Backtrace of a hung httpd -
#0  0x7fa175af9be7 in flock () from /lib64/libc.so.6
#1  0x7fa16cb59dfc in ?? () from /etc/httpd/modules/libphp5.so
#2  0x7fa16cb5a047 in ?? () from /etc/httpd/modules/libphp5.so
#3  0x7fa16cb56e4c in php_session_start ()
from /etc/httpd/modules/libphp5.so
#4  0x7fa16cb57559 in ?? () from /etc/httpd/modules/libphp5.so
#5  0x7fa16cc9afe8 in ?? () from /etc/httpd/modules/libphp5.so
#6  0x7fa16cc72320 in execute () from /etc/httpd/modules/libphp5.so
#7  0x7fa16cc4ca5d in zend_execute_scripts ()
from /etc/httpd/modules/libphp5.so
#8  0x7fa16cbfacf8 in php_execute_script ()
from /etc/httpd/modules/libphp5.so
#9  0x7fa16ccd59a5 in ?? () from /etc/httpd/modules/libphp5.so
#10 0x7fa17751da60 in ap_run_handler ()
#11 0x7fa17752131e in ap_invoke_handler ()
#12 0x7fa17752c990 in ap_process_request ()
#13 0x7fa177529858 in ?? ()
#14 0x7fa177525568 in ap_run_process_connection ()
#15 0x7fa177531767 in ?? ()
#16 0x7fa177531a7a in ?? ()
#17 0x7fa177531dab in ap_mpm_run ()
#18 0x7fa177509900 in main ()



-- 
System  Network Administrator [ LPI  NCLA ]
http://www.whitemiceconsulting.com
OpenGroupware Developer http://www.opengroupware.us
Adam Tauno Williams



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



Re: [PHP] Race Condition In PHP Session Handler

2012-02-20 Thread Adam Tauno Williams
On Mon, 2012-02-20 at 20:02 +0100, Matijn Woudt wrote:
 On Mon, Feb 20, 2012 at 7:21 PM, Adam Tauno Williams
 awill...@whitemice.org wrote:
  php-5.3.3-3.el6_2.6.x86_64
  2.6.32-220.4.2.el6.x86_64
  The PHP session file.  Originally I had a tmpfs mounted for the session
  files.  I removed that and used the underlying filesystem.  Same issue.
  I disabled APC.  Same issue.
  Switching the the memcache session handler resolved the issue,  although
  that may be less optimal.  But this seems like a PHP bug.
  Backtrace of a hung httpd -
  #0  0x7fa175af9be7 in flock () from /lib64/libc.so.6
  #1  0x7fa16cb59dfc in ?? () from /etc/httpd/modules/libphp5.so
  #2  0x7fa16cb5a047 in ?? () from /etc/httpd/modules/libphp5.so
  #3  0x7fa16cb56e4c in php_session_start ()
  from /etc/httpd/modules/libphp5.so
  #4  0x7fa16cb57559 in ?? () from /etc/httpd/modules/libphp5.so
  #5  0x7fa16cc9afe8 in ?? () from /etc/httpd/modules/libphp5.so
  #6  0x7fa16cc72320 in execute () from /etc/httpd/modules/libphp5.so
 It sounds like a bug in memcache to me, but anyway, there's little

No, switching *to* memcache as the session handler worked around the
issue.

 chance you're getting any info from this mailing list. 

Expected;  just thought I might get lucky with somone who was using the
same current packages.

 You should opena bug report at bugs.php.net for this. If you want to be even 
 more
 helpful, provide a backtrace with debug symbols included.

I'm working on getting a full stack trace, but the CentOS debuginfo
packages are lagging behind.

-- 
System  Network Administrator [ LPI  NCLA ]
http://www.whitemiceconsulting.com
OpenGroupware Developer http://www.opengroupware.us
Adam Tauno Williams


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



Re: [PHP] Help! Having trouble getting one XML field from this feed reliably

2012-02-09 Thread Adam Richardson
On Thu, Feb 9, 2012 at 9:10 AM, Yared Hufkens y4...@yahoo.de wrote:

 I wonder why you use cURL as SimpleXML itself can load URLs:

 $vastdata = new
 SimpleXMLElement('http://afe.specificclick.net/?l=32259t=xrnd=123456
 ',0,true);

 See http://de.php.net/manual/en/simplexmlelement.construct.php


It is pretty convenient that SimpleXMLElement allows you to grab URL's, but
curl allows me to manually set a timeout limit (along with many other
things, although they're not necessarily needed in Rob's example), so I
tend to use curl in this type situation, too.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Help! Having trouble getting one XML field from this feed reliably

2012-02-08 Thread Adam Richardson
On Wed, Feb 8, 2012 at 10:44 PM, Rob Gould gould...@mac.com wrote:

 Can anyone tell me what I'm doing wrong here?  I'm trying to get the
 VASTAdTagURI field from the XML data at this url:

 http://afe.specificclick.net/?l=32259t=xrnd=123456




 Here's my code.  (below).  It works maybe 30% of the time, but most of the
 time it just returns nothing from that field.  Yet when I go to the above
 url in Firefox, I always see the data.  This is very strange.





 // Lets get the ad!

 $curl_handle=curl_init();
 curl_setopt($curl_handle,CURLOPT_URL,'
 http://afe.specificclick.net/?l=32259t=xrnd=123456');
 curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
 curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
 $buffer = curl_exec($curl_handle);
 curl_close($curl_handle);

 $vastdata = new SimpleXMLElement($buffer);

 $vasturi = $vastdata-Ad-Wrapper-VASTAdTagURI;

 echo If the script works, vasturi =  . $vasturi;

 echo brbrbr;

 print_r($vastdata);


I'd try adding some error checks to see what issues curl may be having:

$str = curl_exec($ch);
$error_no = curl_errno($ch);
curl_close ($ch);

if ($error_no != 0)
throw new Exception('There was an error retrieving the string contents
of the url \''.$url.'\'. CURL error number:'.$error_no);

I wonder if you transaction is timing out, which you can set as below:

curl_setopt($ch, CURLOPT_TIMEOUT, $transaction_timeout = 2);

Adam


-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Adam Richardson
On Tue, Feb 7, 2012 at 1:56 PM, Mike Mackintosh 
mike.mackint...@angrystatic.com wrote:

 I was curious to see what everyones favorite design patterns were, if you
 use any, and why/when have you used it?

 Choices include slots and signals (observer), singleton, mvc, hmvc,
 factory, commander etc..


Higher-order functions:

http://programmers.stackexchange.com/questions/72557/how-do-you-design-programs-in-haskell-or-other-functional-programming-languages

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Long Live GOTO

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 4:07 AM, Tim Streater t...@clothears.org.uk wrote:

 On 06 Feb 2012 at 07:47, Adam Richardson simples...@gmail.com wrote:

  While not purely focused on PHP, I toss this out to the group because I
  believe there are some novel, interesting points regarding the potential
  benefits of using the goto construct as implemented in PHP:
 
  http://adamjonrichardson.com/2012/02/06/long-live-the-goto-statement/

 Your val_nested() function looks like a straw-man to me. I've not used a
 goto since I stopped writing in FORTRAN in 1978, and not missed it [1].
 Neither do I ever have deeply nested if-then-else - these are a good source
 of bugs. I suppose the rest of your article might have been dealing with
 simplifying val_nested() but TBH I wasn't interested enough to find out.


I disagree that the nested function is a straw-man. I (just as the other
authors I'd linked to describing the arrow pattern of code) have seen
plenty of examples of similar code.

PHP provides a restricted implementation of the goto construct that, in my
opinion, can hold great value for developers.

Thanks for the feedback,

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Long Live GOTO

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 4:25 AM, Adam Richardson simples...@gmail.comwrote:

 On Mon, Feb 6, 2012 at 4:07 AM, Tim Streater t...@clothears.org.uk wrote:

 On 06 Feb 2012 at 07:47, Adam Richardson simples...@gmail.com wrote:

  While not purely focused on PHP, I toss this out to the group because I
  believe there are some novel, interesting points regarding the potential
  benefits of using the goto construct as implemented in PHP:
 
  http://adamjonrichardson.com/2012/02/06/long-live-the-goto-statement/

 Your val_nested() function looks like a straw-man to me. I've not used a
 goto since I stopped writing in FORTRAN in 1978, and not missed it [1].
 Neither do I ever have deeply nested if-then-else - these are a good source
 of bugs. I suppose the rest of your article might have been dealing with
 simplifying val_nested() but TBH I wasn't interested enough to find out.


 I disagree that the nested function is a straw-man. I (just as the other
 authors I'd linked to describing the arrow pattern of code) have seen
 plenty of examples of similar code.

 PHP provides a restricted implementation of the goto construct that, in my
 opinion, can hold great value for developers.

 Thanks for the feedback,

 Adam


Tim,

One quick follow-up. I'd thoroughly enjoy viewing a refactored version of
the val_nested() function from you (or anyone one else on the list) to see
the techniques PHP users tend to use to avoid the deep nesting.

That would be very useful in terms of properly evaluating the range of the
possible refactoring options and PHP user preferences.

Thanks again,

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Long Live GOTO

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 10:05 AM, Robert Cummings rob...@interjinn.comwrote:

 On 12-02-06 04:07 AM, Tim Streater wrote:

 On 06 Feb 2012 at 07:47, Adam 
 Richardsonsimpleshot@gmail.**comsimples...@gmail.com
  wrote:

  While not purely focused on PHP, I toss this out to the group because I
 believe there are some novel, interesting points regarding the potential
 benefits of using the goto construct as implemented in PHP:

 http://adamjonrichardson.com/**2012/02/06/long-live-the-goto-**
 statement/http://adamjonrichardson.com/2012/02/06/long-live-the-goto-statement/


 Your val_nested() function looks like a straw-man to me. I've not used a
 goto since I stopped writing in FORTRAN in 1978, and not missed it [1].
 Neither do I ever have deeply nested if-then-else - these are a good source
 of bugs. I suppose the rest of your article might have been dealing with
 simplifying val_nested() but TBH I wasn't interested enough to find out.

 [1] Not quite true - a Pascal compiler I once had to use in 1983 lacked a
 return statement, so I had to fake it by putting a 999: label at the end of
 the function and goto-ing to that.


 Goto has it's uses, demonizing it due to the poor implementation and
 misuse of it's same-named historical counterparts is an exercise in
 closed-mindedness. Goto can really shine in parsers and various other
 scenarios. While the example shown may be contrived it doesn't miss the
 point. Since goto cannot jump out of the function nor jump into the
 function it is well constrained to provide readability while eliminating
 complexity. Additionally, it is quite likely that it is more optimal. A
 single jump target versus one or more state variables to control nested
 conditionals or loops results in faster execution (also important for
 parsers).

 I've had a strong opinion on goto for a very long time. I was one of the
 proponents who argued on internals for its inclusion several years ago. I
 stand by its utility and refer the reader to the fact that many open source
 projects, especially ones that use some kind of parser, have goto hidden
 within their implementation. You can find it in the C code for the PHP,
 MySQL, and Apache to name a few easily recognizable projects.

 Cheers,
 Rob.


All excellent points, Robert.

Tim mentioned that my example was a straw-man, and you mentioned it was
contrived. Actually, it's a refactoring of a real function in my web
framework that I've committed to trunk and going to use for a while (it's
functionally inspired, and having the ability to store and retrieve
immutable values is quite handy in this situation.)

I like experimenting with different approaches (my background is in
cognitive psychology), and there's certainly research to show that deeply
nested ifs are problematic, cognitively speaking. Then, there are the other
techniques mentioned in the blog post to deal with them (guard clauses,
pulling out functions, grouping conditions), but they have they're issues,
too, in terms of processing (they can hurt proximity of related concepts,
forcing programmers to work against the mental model they've built up of a
problem, etc.) There are going to be issues with the goto approach I took
to refactoring the function, too, but I'm keenly interested in playing
around with it a while and letting the evidence accrue over time. I've read
many, many sources that seem to reject ANY approach using GOTO even without
properly evaluating its use within a language like PHP that offers some
beneficial restrictions.

Thanks for the insights (and I'm glad you pushed for the construct :)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Re: Long Live GOTO

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 11:28 AM, Larry Martell
la...@software-horizons.comwrote:

 On Mon, Feb 6, 2012 at 9:23 AM, Alain Williams a...@phcomp.co.uk wrote:
  On Mon, Feb 06, 2012 at 11:12:53AM -0500, Jim Giner wrote:
  NO GO!
  As one who started back in the 70's with old style coding that utilized
 GoTo
  in Cobol, Fortran, etc. and had to deal with spaghetti code written by
  even earlier developers who never considered that someone else would
 have to
  maintain their code, I feel strongly that GoTo is not to be used.
 
  I remember being faced with spaghetti code 35 odd years ago - yes,
 horrible.
  But what do we mean by ''spaghetti code'' ? I remember code where every
 3rd
  statement was some form of GOTO - yuck!
 
  One very desirable feature of code is that it be clear, ie: lucid, able
 to be
  understood by others. Too many GOTO statements and it is hard.
 
  However: a few GOTOs can make things clearer.  Think of a function that
 can fail
  in several different places (eg data validation, ...).  But it is
 reading a file
  which needs to be closed before the function returns.  I have seen code
 where
  some $IsError variable is tested in many places to see if things should
 be done.
  That is just as bad as lots of GOTO -- often when having to write
 something like
  that I will have a GOTO (in several places) to the bottom of the
 function that
  closes the file and returns failure.
 
  That is much clearer than extra variables.
 
  If I survey my code I find that I use one GOTO in about 4,000 lines of
 code -
  that I do not find excessive.
 
  There are, however, people who consider any GOTO as communion with the
 devil.
  IMHO: not so - if used sparingly.

 Just for another data point, the FAA does not allow gotos in any code
 that goes into an airplane.

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


Can I have the source for this so I can read the rationale? I'm curious
which language implementation it's referencing (C, Ada, etc.) and what
restrictions the language places on the construct. Again, the PHP version
of the construct is beneficially quite restrictive. For instance, some
people don't like giving programmers access to pointers just because you
can get into so much trouble with them, but I wonder if they'd be concerned
about Go's pointers, which don't allow pointer arithmetic, limiting one are
of potential trouble:

http://golang.org/doc/go_for_cpp_programmers.html#Conceptual_Differences

Interesting.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Re: Long Live GOTO

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 12:09 PM, Larry Martell
la...@software-horizons.comwrote:


 The source is my own personal experience working for an avionics
 company and working with the FAA to get our code certified under the
 DO-178B standard. I never saw anything that said 'no GOTOs' but that's
 what I was told. I was also told no C++ was allowed nor was any
 recursion. This was important to me, as we had purchased some code
 that was all that (C++, with recursion and GOTOs) and I was given the
 task of rewriting it in C and removing the gotos and the recursion.


Now that was probably a lot of work! Interesting that C++ was not allowed.

Thanks for the background information,

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: Re: [PHP] Long Live GOTO

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 11:58 AM, Tim Streater t...@clothears.org.uk wrote:

 On 06 Feb 2012 at 09:48, Adam Richardson simples...@gmail.com wrote:

  On Mon, Feb 6, 2012 at 4:25 AM, Adam Richardson simples...@gmail.com
 wrote:
 
  On Mon, Feb 6, 2012 at 4:07 AM, Tim Streater t...@clothears.org.uk
 wrote:

  I disagree that the nested function is a straw-man. I (just as the other
  authors I'd linked to describing the arrow pattern of code) have seen
  plenty of examples of similar code.

 I guess what I meant was, that I'd never have written it that way in the
 first place, so as an example it felt contrived. Amateurs or people with no
 training (in particular physicists at CERN 40 years ago) should be kept
 well clear of the goto. I'd probably write your function like this:

 function val_nested ($name = null, $value = null, $is_mutable = false)
  {

  static $values   = array();
  static $mutables = array();

  if  ($name===null)  return $values;

 if  ($value===null)  return isset($values[$name]) ? $values[$name] :
 null;

 if  (isset($values[$name]))
  {

   if (!$val_is_mutable = in_array($name, $mutables))// Set
 existing value
   {
   $msg = 'The value ' . $name . ' is immutable and has
 already been set to ' . $values[$name] . '.';
throw new Exception ($msg);
}

   return $values[$name] = $value;

   }

  if ($is_mutable)  $mutables[] = $name; // Set new
 value
  $values[$name] = $value;

  return $value;

 }


 I always add blank lines for clarity. Remove those and the above is 30%
 shorter than yours - as far as I could tell, none of the else clauses was
 required.

 My approach is:

 1) deal with the trivial and error cases first

 2) deal with the real work next

 --
 Cheers  --  Tim


Thanks for providing your example, Tim. Bailing early through guard clauses
towards the top of the function body is a nice approach (I used it in my
second example, but I also used conditional grouping and factoring out
functions so I could display all three techniques listed in the post.)

I might try performing some experiments using the different versions of the
code and test for things like:
- Time it takes to add some additional piece of functionality to the code.
- Number of bugs in the revision.
- Time it takes for one to write a new function using only one of the
possible techniques (deep nesting, guard clauses, pulling out functions,
goto, etc.)
- Providing function input and testing accuracy of predicted output

Thanks for the time you've taken to provide your PHP coding preference in
this situation.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Headers on smart phone browsers

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 12:58 AM, Paul M Foster pa...@quillandmouse.comwrote:

 This is sort of obliquely related to PHP.

 I don't have a smart phone, but I need to know a couple of things:

 1) Do smart phones use the same browsers as the desktop, or do they have
 their own stripped down versions of browsers?


Both, although more and more smart phones join the ranks of the
desktop-quality browser every day (iPhone and Android both have very
capable browsers, with the iPhone's omission of flash support being the
biggest difference between these two.)



 2) When a browser broadcasts its header telling the server what kind of
 browser is involved, do they broadcast anything in the header to
 indicate that they're being run on a smart phone?


Yes, but that gets complicated quickly:
http://www.zytrax.com/tech/web/mobile_ids.html



 3) Bonus question: Is there a preferred method amongst coders to
 determine what type of environment is being browsed from, so as to serve
 up the proper type of page (desktop or smart phone version of a
 webpage)?


To supplement the alistapart link already mentioned, here's another recent
writeup:
http://dev.opera.com/articles/view/how-to-serve-the-right-content-to-mobile/

I develop mobile games and websites, and I never use the User Agent to
alter site/presentation. Media queries and types are the way I handle this
(sometimes creating separate mobile resources, but most of the time
creating designs that adapt accordingly.)

All this to say, I don't use PHP to handle this aspect of the development.

Adam


-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Re: Long Live GOTO

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 3:44 PM, Marco Behnke ma...@behnke.biz wrote:

 Am 06.02.12 17:23, schrieb Alain Williams:
  However: a few GOTOs can make things clearer. Think of a function that
  can fail in several different places (eg data validation, ...). But it
  is reading a file which needs to be closed before the function
  returns. I have seen code where some $IsError variable is tested in
  many places to see if things should be done. That is just as bad as
  lots of GOTO -- often when having to write something like that I will
  have a GOTO (in

 Good code uses Exceptions and try catch for that kind of scenarios.


Marco,

Do you know of any research (Human Factors, Bug Analysis, etc.) that
supports this? I'm certainly not saying that your assertion is incorrect.
However, I'm starting to compile relevant research related to this topic.

Thanks,

Adam


-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Headers on smart phone browsers

2012-02-06 Thread Adam Richardson
On Mon, Feb 6, 2012 at 3:50 PM, Adam Richardson simples...@gmail.comwrote:

 On Mon, Feb 6, 2012 at 12:58 AM, Paul M Foster pa...@quillandmouse.comwrote:

 This is sort of obliquely related to PHP.

 I don't have a smart phone, but I need to know a couple of things:

 1) Do smart phones use the same browsers as the desktop, or do they have
 their own stripped down versions of browsers?


 Both, although more and more smart phones join the ranks of the
 desktop-quality browser every day (iPhone and Android both have very
 capable browsers, with the iPhone's omission of flash support being the
 biggest difference between these two.)



 2) When a browser broadcasts its header telling the server what kind of
 browser is involved, do they broadcast anything in the header to
 indicate that they're being run on a smart phone?


 Yes, but that gets complicated quickly:
 http://www.zytrax.com/tech/web/mobile_ids.html



 3) Bonus question: Is there a preferred method amongst coders to
 determine what type of environment is being browsed from, so as to serve
 up the proper type of page (desktop or smart phone version of a
 webpage)?


 To supplement the alistapart link already mentioned, here's another recent
 writeup:

 http://dev.opera.com/articles/view/how-to-serve-the-right-content-to-mobile/



Apologies, I sent the wrong link last time:
http://dev.opera.com/articles/view/the-mobile-web-optimization-guide/

Adam


[PHP] Long Live GOTO

2012-02-05 Thread Adam Richardson
Hi,

While not purely focused on PHP, I toss this out to the group because I
believe there are some novel, interesting points regarding the potential
benefits of using the goto construct as implemented in PHP:

http://adamjonrichardson.com/2012/02/06/long-live-the-goto-statement/

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] differences in between these env. variables

2012-01-29 Thread Adam Richardson
On Sun, Jan 29, 2012 at 11:38 AM, Tedd Sperling tedd.sperl...@gmail.comwrote:

 On Jan 27, 2012, at 12:45 PM, Adam Richardson wrote:

  On Fri, Jan 27, 2012 at 12:09 PM, Tedd Sperling tedd.sperl...@gmail.com
 wrote:
  On Jan 11, 2012, at 9:24 PM, tamouse mailing lists wrote:
 
   Is there ever a case where SCRIPT_NAME does not equal PHP_SELF?
 
  Was this every answered? I would like to know.
 
  Cheers,
 
  tedd
 
  Yep, can be different:
 
 http://stackoverflow.com/questions/279966/php-self-vs-path-info-vs-script-name-vs-request-uri
 
  Adam

 I should have been more clear -- I understand:

 [PHP_SELF] = /test.php/foo/bar
 [SCRIPT_NAME] = /test.php/

 by practice is different.

 I should have used basename() in my question.

 The main point I was trying to get was which one is more secure and not
 subject to cross-site scripting or other such security issues?

 IOW, if you had to bet your life on it, which would be most secure in
 reporting an accurate basename()?


That's an interesting question.

Because $_SERVER['SCRIPT_NAME'] doesn't include path info appended to the
get request, it greatly limits the attack surface, so I try to use it when
I can. However, there are times when you want the ability to pass in
additional path info (e.g., pretty urls), and that makes
$_SERVER['PHP_SELF'] quite useful.

In terms of securely using $_SERVER['PHP_SELF'], the one thing I don't ever
recommend is trying to sanitize input (this view is in stark contrast to
some of the resources online that detail how to safely use
$_SERVER['PHP_SELF'] through a combination of techniques including
sanitization.) I suggest that any time script receives that doesn't meet
its expectations, the script should throw away the data and kindly
communicate to the user that they'll have to try the request again with
valid data.

To use $_SERVER['PHP_SELF'] safely, the most important thing is context. In
order for an XSS attack to succeed, it has to sneak in data that is
structurally meaningful in the context of its use. If the web page outputs
$_SERVER['PHP_SELF'] in an href such as the one below, then a double quote
(or any of its possible encodings which buggily sneak through older
browsers, but modern browsers seem to have corrected many of these issues)
must be escaped:

// if a double quote comes through PHP_SELF here and is not escaped, we're
in trouble
//
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.232_-_Attribute_Escape_Before_Inserting_Untrusted_Data_into_HTML_Common_Attributes
a href=?php echo $_SERVER['PHP_SELF']; ?Link back to this page/a

So, in the above case, I would first filter the PHP_SELF value through a
regex that establishes a whitelist of valid values and/or characters (if
you know all the possible paths of your app ahead of time, make sure
there's a match; if you know that the path info only includes letters a-z,
make sure there are they are the only characters you allow; etc.), and then
for valid input, escape the output using htmlspeciachars().

NOTE: Developers who fail don't use quotes on attributes would have to be
much more careful and escape several other characters in the above example.

That all said, if PHP_SELF was being echoed out into a script tag, the
above technique would be insufficient to protect against XSS, as the
content of the script tag has many more structurally meaningful characters
that have to be watched for and escaped.

So, it really varies by the context of use. I'd use SCRIPT_NAME where I
don't need the path info (but I'd still likely whitelist it's possible
values and escape it's output.) And, if I needed the path info, I'd
whitelist the possible PHP_SELF values and then escape the output according
to the context.

That all said, if my life depended on security of the app, I'd probably be
very slow to put up any web pages, as the amount of testing and auditing
I'd want to perform would be on the scale of years ;)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] differences in between these env. variables

2012-01-27 Thread Adam Richardson
On Fri, Jan 27, 2012 at 12:09 PM, Tedd Sperling tedd.sperl...@gmail.comwrote:

 On Jan 11, 2012, at 9:24 PM, tamouse mailing lists wrote:

  Is there ever a case where SCRIPT_NAME does not equal PHP_SELF?

 Was this every answered? I would like to know.

 Cheers,

 tedd


Yep, can be different:
http://stackoverflow.com/questions/279966/php-self-vs-path-info-vs-script-name-vs-request-uri

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] php://input

2012-01-14 Thread Adam Tong
Hi,

I am trying to read variables from input method.
I am using this tuorial:
http://www.lornajane.net/posts/2008/Accessing-Incoming-PUT-Data-from-PHP.
Here is my code:
?php
if($_SERVER['REQUEST_METHOD'] == 'GET') {
echo this is a get request\n;
echo $_GET['fruit']. is the fruit\n;
echo I want .$_GET['quantity']. of them\n\n;
} elseif($_SERVER['REQUEST_METHOD'] == 'PUT') {
echo this is a put request\n;
parse_str(file_get_contents(php://input),$post_vars);
echo $post_vars['fruit']. is the fruit\n;
echo I want .$post_vars['quantity']. of them\n\n;
}
?

I am using the firefox extension  poster to run this example. GET
works fine but when using PUT, file_get_contents(php://input)
returns an empty string.

I found a bug related to this: https://bugs.php.net/bug.php?id=51592

I am using xampp on win7 (
+ Apache 2.2.17
  + MySQL 5.5.8 (Community Server)
  + PHP 5.3.5 (VC6 X86 32bit) + PEAR)

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



Re: [PHP] Date function kill lots time !

2012-01-04 Thread Adam Richardson
On Wed, Jan 4, 2012 at 11:07 PM, xucheng helloworldje...@gmail.com wrote:

 hi all,
   I have a webapp which track visitors, and use xhprof for profiling my
 codes .
   After reading some reports produced by xhprof, i found that function
 Date() kills most time of my app !
   how can this happen ? Is this function has some internal issue that i
 should kown ?
   Any comment appreciate ! thanks !

 --
 RTFSC - Read The F**king Source Code :)!



Did you set the timezone? If not, PHP raises a notice, which causes
terrible performance (see the comment at the bottom):
https://bugs.php.net/bug.php?id=39968

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Re: Preferred Syntax

2011-12-16 Thread Adam Richardson
On Fri, Dec 16, 2011 at 11:53 PM, Eric Butera eric.but...@gmail.com wrote:

 To all the people who responded to this thread:
 It is 2011 - please stop writing code like this.

 To the OP:
 I'm glad you're asking questions and realizing you're not happy with
 your current abilities and suspect there's a better way.  I've read
 the replies in this thread and feel a bit let down.  Use a templating
 language - yes, I understand that is what php is for - but I won't go
 into it.  You should not be echoing, printing, or any other method of
 concatenating html dealing with escaping quotes inside your php logic
 code.  Please separate your concerns.

 Not sure what that means?  That's OK!  If you want to move forward,
 look up how modern frameworks deal with this issue using their views
 or template views.  You don't have to use a framework if you do not
 want to, that's perfectly fine.  If it works, it works.  But in the
 end, it the separation of logic and html is essential to code
 maintenance.


Eric,

There are many posters to this list, and there exists a broad range of
programming styles and abilities. I'll bet you're a competent programmer,
and that you've worked hard to hone your craft. It takes passion and drive
to improve one's skill set. However, I'd encourage you to focus that
passion on the list in a way that facilitates the growth of those with
questions whilst staying true to their current, specific needs.

Frankly, every answer on the list could begin with the suggestion that they
just use a framework. The list is here to help build up the entire skill
set of PHP developers.

Let's reexamine the original post:

Hello all.
 Can someone tell me which of the following is preferred and why?


Use of the word Which implies that there were a closed set of options
they wanted to consider, although we did offer some others, but they all
stayed relatively true to his original options.



  echo a style='text-align:left;size:**14;font-weight:bold'
 href='/mypage.php/$page_id'$**page_name/abr;
  echo a style='text-align:left;size:**14;font-weight:bold'
 href='/mypage.php/.$page_id.**'.$page_name./abr;


Simple.

Please note there is no logic anywhere in this example. PHP is truly
serving merely as a templating language here. So, while I agree with the
general notion that logic should not be intermingled with markup, this
particular example does not serve as the anti-pattern you suggest.

Also, note that we aren't sure where the $page_id and $page_name variables
are coming from. In instances where these are set manually within the
script (like a view variables at the top of the page), there's no need to
escape anything. That said, you're right, if the data is coming from
somewhere else, escaping should happen, but there's not enough information
to infer that, as you say, You should not be echoing, printing, or any
other method of concatenating html dealing with escaping quotes inside your
php logic code.



 When I come across the above code in line 1, I have been changing it to
 what you see in line 2 for no other reason than it delineates out better in
 BBEdit.  Is this just a preference choice or is one method better than the
 other?


The above statement suggests there's an existing codebase that was being
worked through. In this light, the answers mostly focused on answering the
OP's original question, realizing that this was existing code that he was
refactoring lightly as he goes.

This is not to say that I disagree with all that you said, as I actually
developed my own framework that:

   - Cleanly separates PHP from HTML to avoid the intermingling of logic
   and presenation:
   http://nephtaliproject.com/documentation/markup/
   - Automatically handles output escaping, input validation:
   http://nephtaliproject.com/documentation/examples/contact.php
   - And lots of other features that coincide with the general focus of
   your words.

Given that work, I think it's fair to say that I do agree with several of
your general points for web development overall. However, this question
wasn't a big picture question on how to do web development with PHP. It was
a simple question that was answered in a helpful, specific manner by
several on the list.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Preferred Syntax

2011-12-14 Thread Adam Richardson
On Wed, Dec 14, 2011 at 7:59 AM, Rick Dwyer rpdw...@earthlink.net wrote:

 Hello all.

 Can someone tell me which of the following is preferred and why?

  echo a style='text-align:left;size:**14;font-weight:bold'
 href='/mypage.php/$page_id'$**page_name/abr;

  echo a style='text-align:left;size:**14;font-weight:bold'
 href='/mypage.php/.$page_id.**'.$page_name./abr;

 When I come across the above code in line 1, I have been changing it to
 what you see in line 2 for no other reason than it delineates out better in
 BBEdit.  Is this just a preference choice or is one method better than the
 other?


I prefer sending arguments to the echo language construct (note, if you
send more than one argument, you can't use parentheses.) I perceive this
usage to be a clean presentation of the code's intent, easy to use in most
IDE's, and it's very fast relative to the other options:

echo a style='text-align:left;size:**14;font-weight:bold'
href='/mypage.php/$page_id'$**page_name/abr;

echo a style='text-align:left;size:**14;font-weight:bold'
href='/mypage.php/.$page_id.**'.$page_name./abr;

echo a style='text-align:left;size:**14;font-weight:bold'
href='/mypage.php/, $page_id, ', $**page_name, /abr;

And, for longer lines, I'll often break it up into separate lines by
argument like below:

echo
a style='text-align:left;size:**14;font-weight:bold'
href='/mypage.php/,
$page_id,
',
$**page_name,
/abr;

That all said, I don't change code that uses another convention, as I think
it's most beneficial to stay with the established conventions in any
codebase (unless you're establishing a new convention and refactoring the
entire code base.) This is just my general preference, and I don't believe
there is consensus as to the most appropriate.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] mcrypt_encrypt help needed

2011-11-30 Thread Adam Richardson
On Wed, Nov 30, 2011 at 3:57 PM, Rick Dwyer rpdw...@earthlink.net wrote:

 Hello all.

 I am using the following function to encrypt a string:

 define('SALT', 'myvalueforsalthere');

 function encrypt($text)
 {
return trim(base64_encode(mcrypt_**encrypt(MCRYPT_RIJNDAEL_256, SALT,
 $text, MCRYPT_MODE_ECB, 
 mcrypt_create_iv(mcrypt_get_**iv_size(MCRYPT_RIJNDAEL_256,
 MCRYPT_MODE_ECB), MCRYPT_RAND;
 }

 and then:

 $myval=hello;
 $mayval= encrypt($myval);


 echo decrypt($myval);

 returns hello great.



 But when my input string is more complicated I get unprintable characters
 out of the decyrpt side:

 $myval=var1=1var2=2var3=3;

 The above when decrypted will spit out a string of unprintable characters.
 Is encrypt/decrypt choking on the = sign?  I tried:

 $myval=htmlentities($myval);

 But it did not work.  Any help is appreciated.

 Thanks,

 --Rick


Hi Rick,

Can you show us the decrypt function, too (even though it should be just
the reverse order of operations using a decrypt function, I'd just like to
double check it before commenting.) By the way, I wouldn't recommend using
ECB mode unless you have a special circumstance:
http://www.quora.com/Is-AES-ECB-mode-useful-for-anything

Adam

(Sorry for the duplicate, Rick, I forgot to reply all the first time.)

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] mcrypt_encrypt help needed

2011-11-30 Thread Adam Richardson
On Wed, Nov 30, 2011 at 4:14 PM, Matijn Woudt tijn...@gmail.com wrote:

 On Wed, Nov 30, 2011 at 9:57 PM, Rick Dwyer rpdw...@earthlink.net wrote:
  Hello all.
 
  I am using the following function to encrypt a string:
 
  define('SALT', 'myvalueforsalthere');
 
  function encrypt($text)
  {
 return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT,
  $text, MCRYPT_MODE_ECB,
  mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
 MCRYPT_MODE_ECB),
  MCRYPT_RAND;
  }
 

 Can you post your decrypt function too?

 You create a random IV here, don't you need that IV to decrypt too?


You're normally right, Matijn,

However, ECB mode doesn't use an IV, so even though he's generating an IV,
it's not being used (and, the benefit of an IV is one of the main reasons
you try to avoid ECB.)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] mcrypt_encrypt help needed

2011-11-30 Thread Adam Richardson
On Wed, Nov 30, 2011 at 4:25 PM, Matijn Woudt tijn...@gmail.com wrote:

 On Wed, Nov 30, 2011 at 10:18 PM, Adam Richardson simples...@gmail.com
 wrote:
  On Wed, Nov 30, 2011 at 4:14 PM, Matijn Woudt tijn...@gmail.com wrote:
 
  On Wed, Nov 30, 2011 at 9:57 PM, Rick Dwyer rpdw...@earthlink.net
 wrote:
   Hello all.
  
   I am using the following function to encrypt a string:
  
   define('SALT', 'myvalueforsalthere');
  
   function encrypt($text)
   {
  return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT,
   $text, MCRYPT_MODE_ECB,
   mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
  MCRYPT_MODE_ECB),
   MCRYPT_RAND;
   }
  
 
  Can you post your decrypt function too?
 
  You create a random IV here, don't you need that IV to decrypt too?
 
 
  You're normally right, Matijn,
 
  However, ECB mode doesn't use an IV, so even though he's generating an
 IV,
  it's not being used (and, the benefit of an IV is one of the main reasons
  you try to avoid ECB.)
 
  Adam

 Ah, I see, you're right. I thought he was using CBC (which I would
 recommend).
 That also means that example #1 is wrong at mcrypt_encrypt help page[1].

 Matijn

 [1] http://php.net/manual/en/function.mcrypt-encrypt.php#example-884


Nice catch in the documentation, Matijn. While it will encrypt and decrypt
successfully, the IV isn't being used, so it would seem to be a better
illustration of use of someone switched the mode to one that's using the IV.

Someone with access to the documents want to make the change to one of the
other modes (as Matijn pointed out, CBC is pretty common?)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] PHPExcel

2011-11-29 Thread Adam Balogh
Hi,

*Heres the documentation:*
http://phpexcel.codeplex.com/releases/view/45412#DownloadId=212183

In user doc:
*4.2 Reading Only Named WorkSheets from a File*
*
*
and you can get all the sheet names:
http://www.auditbureau.org.au/a/Documentation/API/PHPExcel/PHPExcel.html#methodgetSheetNames


Re: [PHP] delete and recreate

2011-11-09 Thread Adam Richardson
On Wed, Nov 9, 2011 at 10:35 AM, Kirk Bailey kbai...@howlermonkey.netwrote:

 So, I want to create a script to delete an old file and create a new one
 which is empty. The script receives a password via query string. The
 obvious methods give me back a very useless 500 error. Any suggestions on
 how to accomplish what I seek?

 --
 end

 Very Truly yours,
 - Kirk Bailey,
   Largo Florida

   kniht
  +-+
  | BOX |
  +-+
   think


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


Make sure PHP has the permissions needed to delete and create files in the
directory.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Re: Writing out errors to a file

2011-11-03 Thread Adam Richardson
On Thu, Nov 3, 2011 at 9:04 PM, Jim Giner jim.gi...@albanyhandball.comwrote:

 Try reading the manual on set_error_handler.  I've never needed to do
 this
 kind of thing, but this sure looks like something that could do it.
 Basically, I'm imagining that it would open a file handle on some text file
 in some folder, then append a write of mysql_error() to that file and
 probably the line number and such and then close it.



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


The combination of set_error_handler() and within the handler using
error_log() works very well.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Friday Distraction

2011-10-28 Thread Adam Richardson
On Thu, Oct 27, 2011 at 10:18 AM, Richard Quadling rquadl...@gmail.comwrote:

 On 21 October 2011 17:27, Daniel Brown danbr...@php.net wrote:
 I'll get this week's Friday distraction kicked off here with
  something shared with me by a Facebook friend.  If you're on Facebook,
  try this.  It's pretty sweet (and safe for work and kids).
 
 http://www.takethislollipop.com/

 Sweet? SWEET!? What sort of sicko are you???

 I've got a deranged nutter hunting me down.

 He looks a LOT like you





 Cool though.


Well, Daniel,

I'll bet you never thought that your Friday Distraction would elicit such
a broad range of responses AND keep the commentary coming right through to
the next Friday.

Nice :)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Sequential access of XML nodes.

2011-09-26 Thread Adam Richardson
On Mon, Sep 26, 2011 at 12:24 PM, Richard Quadling rquadl...@gmail.comwrote:

 Hi.

 I've got a project which will be needing to iterate some very large
 XML files (around 250 files ranging in size from around 50MB to
 several hundred MB - 2 of them are in excess of 500MB).

 The XML files have a root node and then a collection of products. In
 total, in all the files, there are going to be several million product
 details. Each XML feed will have a different structure as it relates
 to a different source of data.

 I plan to have an abstract reader class with the concrete classes
 being extensions of this, each covering the specifics of the format
 being received and has the ability to return a standardised view of
 the data for importing into mysql and eventually MongoDB.

 I want to use an XML iterator so that I can say something along the lines
 of ...

 1 - Instantiate the XML iterator with the XML's URL.
 2 - Iterate the XML getting back one node at a time without keeping
 all the nodes in memory.

 e.g.

 ?php
 $o_XML = new SomeExtendedXMLReader('http://www.site.com/data.xml');
 foreach($o_XML as $o_Product) {
  // Process product.
 }


 Add to this that some of the xml feeds come .gz, I want to be able to
 stream the XML out of the .gz file without having to extract the
 entire file first.

 I've not got access to the XML feeds yet (they are coming from the
 various affiliate networks around, and I'm a remote user so need to
 get credentials and the like).

 If you have any pointers on the capabilities of the various XML reader
 classes, based upon this scenario, then I'd be very grateful.


 In this instance, the memory limitation is important. The current code
 is string based and whilst it works, you can imagine the complexity of
 it.

 The structure of each product internally will be different, but I will
 be happy to get back a nested array or an XML fragment, as long as the
 iterator is only holding onto 1 array/fragment at a time and not
 caching the massive number of products per file.

 Thanks.

 Richard.


 --
 Richard Quadling
 Twitter : EE : Zend : PHPDoc
 @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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


I believe the XMLReader allows you to pull node by node, and it's really
easy to work with:
http://www.php.net/manual/en/intro.xmlreader.php

In terms of dealing with various forms of compression, I believe you con use
the compression streams to handle this:
http://stackoverflow.com/questions/1190906/php-open-gzipped-xml
http://us3.php.net/manual/en/wrappers.compression.php

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] array problem

2011-09-09 Thread Adam Balogh
hi,

try to use print_r or var_dump to echo compound data type


Re: [PHP] how catch a warning by file_put_contents() ?

2011-08-19 Thread Adam Richardson
On Sat, Aug 20, 2011 at 1:23 AM, Simon J Welsh si...@welsh.co.nz wrote:

 On 20/08/2011, at 4:51 PM, Andreas wrote:

  Hi,
  I wrote stuff with file_put_contents() in a try{} catch{} and it worked.
 
  Then I'd like to check what happens when some error occurs so I
 writeprotected the targetfile.
  Instead of getting my own message by the catch{} block I got a standard
 warning in the browser.
 
  Can't I catch those warnings, too?
  And why does this function rise a warning when it can't acomplish it's
 task?
 
 
  Samplecode:
 try {
 $msg = date (d.m.Y H:i:s) . 'This should be stored in the
 file.';
 file_put_contents( '/tmp/exceptions.txt', $msg . \n,
 FILE_APPEND);
 }
 catch ( Exception $e ) {
 $msg = Exception  . $e-getCode() .  /  . $e-getMessage();
 echo p$msg/p;
 }

 file_put_contents() doesn't throw exceptions. As the note on the exception
 documentation says: Internal PHP functions mainly use Error reporting, only
 modern Object oriented extensions use exceptions.

 If you look at the documentation for its return value (
 http://php.net/file_put_contents), you'll see that false is returned on
 failure.

 In this case, a warning makes more sense than throwing an exception anyway.
 A warning can be ignored, either by changing the error_reporting level or
 using the error control operator, whereas an exception must be dealt with or
 execution halts.
 ---
 Simon Welsh
 Admin of http://simon.geek.nz/


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


Simon explains the rationale and heritage well.

If, however, you still wish to catch errors as exceptions, you can do so
with code like that below:

function error_handler($errno, $errstr, $errfile, $errline)
{
// must take into account error suppressor (@) and not do anything with them
(they equal 0)
// http://framework.zend.com/issues/browse/ZF-3829
// check against current error_reporting bitmasks
if (!(\error_reporting()  $errno)) {
return true;
} else {
$error_msg = dldtError Type (see
http://www.php.net/manual/en/errorfunc.constants.php):/dtdd$errno/dddtError
Message:/dtdd$errstr/dddtFile:/dtdd$errfile/dddtLine:/dtdd$errline/dd/dl;
throw new \Exception($error_msg);
}
}

set_error_handler('error_handler');

I just pulled some quick code from my web framework.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] How to sum monetary variables

2011-07-18 Thread Adam Richardson
2011/7/18 Martín Marqués martin.marq...@gmail.com

 I'm building a table (which is a report that has to be printed) with a
 bunch of items (up to 300 in some cases) that have unitary price
 (stored in a numeric(9,2) field), how many there are, and the total
 price for each item. At the end of the table there is a total of all
 the items.

 The app is running on PHP and PostgreSQL is the backend.

 The question is, how do I get the total of everything?

 Running it on PHP gives one value, doing a sum() on the backend gives
 another, and I'm starting to notice that even using python as a
 calculator gives me errors (big ones). Right now I'm doing the maths
 by hand to find out who has the biggest error, or if any is 100%
 accurate.

 Any ideas?


Hi,

I've not had issues with PostgreSQL when using the numeric data type. That
said, when you need more precision than PHP's standard handling of floating
points (http://php.net/manual/en/language.types.float.php),  you can use
PHP's BC Math functions to enforce arbitrary precision:
http://www.php.net/manual/en/ref.bc.php
http://www.php.net/manual/en/ref.bc.php
Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] How to sum monetary variables

2011-07-18 Thread Adam Richardson
2011/7/18 Richard Quadling rquadl...@gmail.com

 2011/7/18 Martín Marqués martin.marq...@gmail.com:
 
  Any ideas?

 For financial values, I use the money type.

 I use MS SQL, but PostgreSQL has
 http://www.postgresql.org/docs/9.0/interactive/datatype-money.html


The version of PostgreSQL plays a role, too, as at one point the money type
was deprecated (and I still tend to use numeric, even though work has been
done to improve the money type):
http://archives.postgresql.org/pgsql-general/2008-05/msg00979.php
http://www.postgresql.org/docs/8.2/static/datatype-money.html

http://archives.postgresql.org/pgsql-general/2008-05/msg00979.phpAdam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Linking A C Program Example to PHP

2011-07-10 Thread Adam Richardson
On Sun, Jul 10, 2011 at 5:56 PM, Thomas Dineen tdin...@ix.netcom.comwrote:

   I am attempting to link a C Program example to PHP using the
 tutorial shown at the link below:
 http://voloreport.com/making-**a-c-extension-for-php-in-11-**easy-stepshttp://voloreport.com/making-a-c-extension-for-php-in-11-easy-steps

   Everything worked fine up through step 9 in the tutorial:

   Now the problem:

   The example works fine from the command line with either of the
 commands shown below:

 php test.php
 php -c /etc/apache2/php.ini test.php

   But the example will NOT work via the web browser on my Apache 2
 (2.2.17) / PHP (5.3.5) Web Server!


Did you reload or restart apache after making the edits to php.ini? For
example:
$ /etc/init.d/apache2 restart

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] ApiGen - a tool for generating source code documentation

2011-06-29 Thread Adam Richardson
I'll try it on my PHP 5.3 web framework later today. Thanks for working on
this project!

Adam

2011/6/29 Ondřej Nešpor kon...@andrewsville.cz

 Hi everybody!

 We'd like to introduce you our documentation generator - ApiGen 2. We use
 it as a replacement for PhpDocumentor (that is not being developed for more
 than 3 years). You can find it on Github https://github.com/apigen/**
 apigen https://github.com/apigen/apigen along with a comprehensive
 readme (describing its features and command line options). Compared to
 PhpDocumentor, ApiGen si significantly faster and more flexible. Currently
 we are preparing PHP 5.4 support (mainly traits).


 An interesting feature is that it describes the source using reflection,
 however not the PHP's reflection as you know it. We have developed our own
 library that emulates reflection using the tokenized source code. This
 library may be useful everywhere you need to process the PHP source code and
 don't want to include/require it. You can find it in a separate repository:
 https://github.com/**Andrewsville/PHP-Token-**Reflectionhttps://github.com/Andrewsville/PHP-Token-Reflection


 You can see some examples here:
 http://andrewsville.github.**com/PHP-Token-Reflection/http://andrewsville.github.com/PHP-Token-Reflection/
 http://api.nella-project.org/**framework/http://api.nella-project.org/framework/
 http://jyxo.github.com/php/
 http://doc.kukulich.cz/**doctrine/ http://doc.kukulich.cz/doctrine/
 http://doc.kukulich.cz/**phpunit/ http://doc.kukulich.cz/phpunit/
 http://doc.kukulich.cz/zend/


 To install it you can either use our PEAR channel (as described in the
 readme) or simple download it from GitHub.


 We'd be grateful for any feedback, so if you're interested please give it a
 try a let us know what you think :) Thanks.



 Ondřej Nešpor (and...@andrewsville.cz)
 Jaroslav Hanslík (kukul...@kukulich.cz)

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




-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] Php filter validate url

2011-06-26 Thread Adam Tong
Hi,

I wanted tu use php filters for validation to avoid regular expresions.
Is it possible that FILTER_VALIDATE_URL only checks if the string has
http:// and do not check for the format domain.something?

$url = 'http://wwwtestcom';
$url = filter_var($url,FILTER_VALIDATE_URL);
echo $url;
-

Or I am doing something wrong

Thank you

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



Re: [PHP] newbie date time question

2011-06-22 Thread Adam Balogh
$dt is an object as the error says, so you cant echo it, becouse its not a
string (it can be with __toString magic method, or use print_r/var_dump to
output your object). Try the format (
http://www.php.net/manual/en/datetime.format.php) method on your $dt object.

On Wed, Jun 22, 2011 at 4:41 PM, David Nicholls d...@dcnicholls.com wrote:

 On 23/06/11 12:23 AM, Adam Balogh wrote:

 hi,

 you have a PM(/AM) in your date ($d[0]), so put an A (Uppercase Ante
 meridiem and Post meridiem) format char to your $format variable.

 b3ha


 Thanks, Adam.  Tried that and it's now throwing an error:

 Catchable fatal error: Object of class DateTime could not be converted to
 string in xxx.php on line 12

 Line 12 follows the attempt at conversion

 10  $format = 'd/m/Y h:i:s A';
 11  $dt = DateTime::createFromFormat($**format, $d[0]);
 12  echo $dt,...;

 DN


[PHP] help with an array if its possible!

2011-06-22 Thread Adam Preece
Hi Gang!

i have 2 assoc arrays from 2 querys, 

first one is page categorys it consists of:
id
name

second is pages
name
cat_id

now, i am using smarty, so i pass arrays into the view. this i would like to 
pass to the view and display within a html select element.

select id=name
option value=CAT_IDCAT NAME
option disabled=disabledPAGE NAME ASSOCIATED TO THE 
CAT NAME/option
/option
/select

and i cannot think of how i can structure an array to pass in to achieve this 
and/or is it even possible :-/.

i hope this makes sense.

i'm truly stuck!

kind regards

Adam Preece

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



Re: [PHP] Can't use class 'DOMDocument

2011-06-08 Thread Adam Tong
Hi,

You're right. I just installed the package php-xml, and everything is
working properly now.

Is there anyway to know for each class or function which is the package needed?

thank you

On Tue, Jun 7, 2011 at 3:48 AM,  ad...@buskirkgraphics.com wrote:
 Did you install the php-xml ?

 Richard L. Buskirk

 -Original Message-
 From: Adam Tong [mailto:adam.to...@gmail.com]
 Sent: Monday, June 06, 2011 9:49 PM
 To: php-general@lists.php.net
 Subject: [PHP] Can't use class 'DOMDocument

 Hi,

 When I try using DOMDocument I get the following error:
 Fatal error: Class 'DOMDocument' not found in ...

 I guess something has to be fixed in my php.ini?

 Here is my php version:
 # php -version
 PHP 5.3.6 (cli) (built: Mar 17 2011 20:58:15)
 Copyright (c) 1997-2011 The PHP Group
 Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

 I also noticed when I click reply in gmail it does not reply to the
 list. Sorry for that inconvenience for poeple who tried to help me
 while the previous issue was already resolved.

 Thank you

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



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



[PHP] advice on how to build this array from an array.

2011-06-07 Thread Adam Preece
hi all,

please forgive me if i do not make sense, ill try my best to explain.


i have this array or arrays.

Array ( [name] = super duplex stainless steels [id] = 30 [page_cat_id] = 10 
[main_nav] = true [cat_name] = material range ) 
Array ( [name] = standard stainless steels [id] = 31 [page_cat_id] = 10 
[main_nav] = true [cat_name] = material range )
 Array ( [name] = non ferrous [id] = 32 [page_cat_id] = 10 [main_nav] = 
true [cat_name] = material range ) 
Array ( [name] = carbon based steels [id] = 33 [page_cat_id] = 10 [main_nav] 
= true [cat_name] = material range ) 

is it possible to build an array  and use the [cat_name] as the key and assign 
all the pages to that cat_name?

what im trying to achieve is a category of pages but i want the cat_name as the 
key to all the pages associated to it

hope i make sense

kind regards

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



  1   2   3   4   5   6   7   8   9   10   >