Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-23 Thread ma...@behnke.biz

> my windowze dev box is completely frozen at startup now, before even
> mounting the drive that had the slow write rate today. booted into
> ubuntu which is still responsive, and ran disk utility to see that
> smart status and self-check for both system drive and the other drive
> that i noticed going slow today, is "good".
> I wonder what's gotten my dev box ill.. Hope it aint a virus, but
> can't start the virus scanner coz the thing is frozen... :S


I guess that is the reason why your dev system is slow ;)

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



Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-23 Thread rene7705
On Wed, May 23, 2012 at 10:09 AM, ma...@behnke.biz  wrote:
>
>> my windowze dev box is completely frozen at startup now, before even
>> mounting the drive that had the slow write rate today. booted into
>> ubuntu which is still responsive, and ran disk utility to see that
>> smart status and self-check for both system drive and the other drive
>> that i noticed going slow today, is "good".
>> I wonder what's gotten my dev box ill.. Hope it aint a virus, but
>> can't start the virus scanner coz the thing is frozen... :S
>
>
> I guess that is the reason why your dev system is slow ;)
>
Well it's very strange. My system unfroze itself yesterday night, the
drive in question can copy a 100mb file at regular speedy speeds with
windows explorer, but writing 45mb of html to a file using (thousands
of) fwrite() calls takes about 10 minutes (bit slow to say the least).
The same fwrite()ing code on my hosted server, with nearly as much
html to write out, works comfortably fast as well.

I'm very puzzled. Would appreciate any tips to test my home system further..

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



RE: [PHP]How to handle E_ERROR,E_PARSE with a user defined function

2012-05-23 Thread ma...@behnke.biz
 > -Original Message-
> From: Yuchen Wang [mailto:phob...@gmail.com]
> Sent: Tuesday, May 22, 2012 10:19 PM
> To: php-general Maillist
> Subject: [PHP]How to handle E_ERROR,E_PARSE with a user defined function
>
> Hi all,
>
> How to handle E_ERROR,E_PARSE with a user defined function ?

Aren't these startup errors? I am not quite sure, but if the y can't be
handled with php.

This is from the PHP docs

"The following error types cannot be handled with a user defined function:
E_ERROR , E_PARSE , E_CORE_ERROR , E_CORE_WARNING , E_COMPILE_ERROR ,
E_COMPILE_WARNING , and most of E_STRICT raised in the file where
set_error_handler() is called.
If errors occur before the script is executed (e.g. on file uploads) the
custom error handler cannot be called since it is not registered at that
time."

So the only thing you can do is have a watchdog on your phperror.log  and
dosomething if these errors occur.

To preparse syntax errors you can use find and php -l

$ find . -name "*.php" -exec php -l {} \;
No syntax errors detected in ./bootstrap.php
No syntax errors detected in ./htdocs/index.php
No syntax errors detected in ./templates/comment.php
No syntax errors detected in ./templates/postform.php
No syntax errors detected in ./templates/blog.php
No syntax errors detected in ./templates/main.php
No syntax errors detected in ./templates/error.php
No syntax errors detected in ./templates/commentform.php
No syntax errors detected in ./templates/post.php
No syntax errors detected in ./classes/rendering/View.php
No syntax errors detected in ./classes/storage/SqliteStorage.php
No syntax errors detected in ./classes/storage/Storage.php
No syntax errors detected in ./classes/models/Blog.php
No syntax errors detected in ./classes/models/Comment.php
No syntax errors detected in ./classes/models/Post.php
No syntax errors detected in ./classes/models/Model.php
No syntax errors detected in ./classes/helper/HTMLResult.php
No syntax errors detected in ./classes/helper/Result.php
No syntax errors detected in ./classes/helper/ApplicationConfig.php
No syntax errors detected in ./classes/helper/ErrorHandler.php
No syntax errors detected in ./classes/helper/Request.php
No syntax errors detected in ./classes/helper/ExceptionHandler.php
No syntax errors detected in ./classes/helper/JSONResult.php
No syntax errors detected in ./classes/app/Router.php
No syntax errors detected in ./classes/controller/BlogController.php
No syntax errors detected in ./classes/controller/Controller.php

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



Re: [PHP]How to handle E_ERROR,E_PARSE with a user defined function

2012-05-23 Thread Yuchen Wang
Thank you

I finally found a method to process these errors that using
register_shutdown_function()
You can read it from this  http://insomanic.me.uk/post/229851073  or
http://mo47.com/blog/2012/catching-fatal-errors

2012/5/23 ma...@behnke.biz 

>  > -Original Message-
> > From: Yuchen Wang [mailto:phob...@gmail.com]
> > Sent: Tuesday, May 22, 2012 10:19 PM
> > To: php-general Maillist
> > Subject: [PHP]How to handle E_ERROR,E_PARSE with a user defined function
> >
> > Hi all,
> >
> > How to handle E_ERROR,E_PARSE with a user defined function ?
>
> Aren't these startup errors? I am not quite sure, but if the y can't be
> handled with php.
>
> This is from the PHP docs
>
> "The following error types cannot be handled with a user defined function:
> E_ERROR , E_PARSE , E_CORE_ERROR , E_CORE_WARNING , E_COMPILE_ERROR ,
> E_COMPILE_WARNING , and most of E_STRICT raised in the file where
> set_error_handler() is called.
> If errors occur before the script is executed (e.g. on file uploads) the
> custom error handler cannot be called since it is not registered at that
> time."
>
> So the only thing you can do is have a watchdog on your phperror.log  and
> dosomething if these errors occur.
>
> To preparse syntax errors you can use find and php -l
>
> $ find . -name "*.php" -exec php -l {} \;
> No syntax errors detected in ./bootstrap.php
> No syntax errors detected in ./htdocs/index.php
> No syntax errors detected in ./templates/comment.php
> No syntax errors detected in ./templates/postform.php
> No syntax errors detected in ./templates/blog.php
> No syntax errors detected in ./templates/main.php
> No syntax errors detected in ./templates/error.php
> No syntax errors detected in ./templates/commentform.php
> No syntax errors detected in ./templates/post.php
> No syntax errors detected in ./classes/rendering/View.php
> No syntax errors detected in ./classes/storage/SqliteStorage.php
> No syntax errors detected in ./classes/storage/Storage.php
> No syntax errors detected in ./classes/models/Blog.php
> No syntax errors detected in ./classes/models/Comment.php
> No syntax errors detected in ./classes/models/Post.php
> No syntax errors detected in ./classes/models/Model.php
> No syntax errors detected in ./classes/helper/HTMLResult.php
> No syntax errors detected in ./classes/helper/Result.php
> No syntax errors detected in ./classes/helper/ApplicationConfig.php
> No syntax errors detected in ./classes/helper/ErrorHandler.php
> No syntax errors detected in ./classes/helper/Request.php
> No syntax errors detected in ./classes/helper/ExceptionHandler.php
> No syntax errors detected in ./classes/helper/JSONResult.php
> No syntax errors detected in ./classes/app/Router.php
> No syntax errors detected in ./classes/controller/BlogController.php
> No syntax errors detected in ./classes/controller/Controller.php
>



-- 
*Yuchen Wang*


[PHP] Re: w.r.t. mail() function

2012-05-23 Thread Maciek Sokolewicz

On 23-05-2012 06:12, Ashwani Kesharwani wrote:

Hi ,

I have a query w.r.t. mail() function in php.

I have hosted my site and i have created an email account as well.

when i am sending mail to different recipient from my php script using
above function it is getting delivered to respective recipients as expected.

However if I want to see those mail in the sent folder of my email account
, i can not see those mails there.

How can I achieve this.

Any suggestions.

Regards
Ashwani



Simply put: the email account you have created is being ignored by the 
mail() function.


It doesn't matter if you created an email account or not; if I wanted 
to, I could make mail() send emails from presid...@whitehouse.gov or 
from kofi.an...@un.org. The mails would never appear in their outboxes, 
simply because an outbox or sent mail folder is a local copy of your 
mail, made by the mail client. It has nothing, intrinsically, to do with 
emailing anyone.


If I try email someone, this happens:
1. I load my mail client
2. I type my mail and press send
3. My mail client stores a copy of this mail in the sent folder
4. My mail client contacts the server, and tells it that it has a mail 
from me, to a certain adress, and then hands it over.

5. My mail client tells me "mail sent successfully"

If I use PHP's mail function, the following happens:
1. The PHP script is ran
2. The mail() function is invoked with the email message to send as a string
3. The mail() function starts up a local program called sendmail (or a 
program which does roughly the same thing), which it then gives the 
entire message to send to.
4. sendmail contacts the server, and tells it that it has a mail from 
me, to a certain adress, and then hands it over.

5. the mail() function says "mail sent succesfully"

So, as you can see, the storage of the email in the sent box has nothing 
to do with actual sending of the mail, but purely with the use of your 
mail client, which PHP does not use (obviously). If you really do want 
to store the email, you'll have to do it yourself. "admin" (which is an 
annoying nickname on the internet! Please change it!) has already showed 
you a few ways to do so.


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



[PHP] Re: w.r.t. mail() function

2012-05-23 Thread Ashwani Kesharwani
Hi Maciek, admin,

Thanks for your responses.

Its really helpful.

Regards
Ashwani

On Wed, May 23, 2012 at 3:37 PM, Maciek Sokolewicz <
maciek.sokolew...@gmail.com> wrote:

> On 23-05-2012 06:12, Ashwani Kesharwani wrote:
>
>> Hi ,
>>
>> I have a query w.r.t. mail() function in php.
>>
>> I have hosted my site and i have created an email account as well.
>>
>> when i am sending mail to different recipient from my php script using
>> above function it is getting delivered to respective recipients as
>> expected.
>>
>> However if I want to see those mail in the sent folder of my email account
>> , i can not see those mails there.
>>
>> How can I achieve this.
>>
>> Any suggestions.
>>
>> Regards
>> Ashwani
>>
>>
> Simply put: the email account you have created is being ignored by the
> mail() function.
>
> It doesn't matter if you created an email account or not; if I wanted to,
> I could make mail() send emails from presid...@whitehouse.gov or from
> kofi.an...@un.org. The mails would never appear in their outboxes, simply
> because an outbox or sent mail folder is a local copy of your mail, made by
> the mail client. It has nothing, intrinsically, to do with emailing anyone.
>
> If I try email someone, this happens:
> 1. I load my mail client
> 2. I type my mail and press send
> 3. My mail client stores a copy of this mail in the sent folder
> 4. My mail client contacts the server, and tells it that it has a mail
> from me, to a certain adress, and then hands it over.
> 5. My mail client tells me "mail sent successfully"
>
> If I use PHP's mail function, the following happens:
> 1. The PHP script is ran
> 2. The mail() function is invoked with the email message to send as a
> string
> 3. The mail() function starts up a local program called sendmail (or a
> program which does roughly the same thing), which it then gives the entire
> message to send to.
> 4. sendmail contacts the server, and tells it that it has a mail from me,
> to a certain adress, and then hands it over.
> 5. the mail() function says "mail sent succesfully"
>
> So, as you can see, the storage of the email in the sent box has nothing
> to do with actual sending of the mail, but purely with the use of your mail
> client, which PHP does not use (obviously). If you really do want to store
> the email, you'll have to do it yourself. "admin" (which is an annoying
> nickname on the internet! Please change it!) has already showed you a few
> ways to do so.
>


Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-23 Thread rene7705
On Wed, May 23, 2012 at 10:17 AM, rene7705  wrote:
> On Wed, May 23, 2012 at 10:09 AM, ma...@behnke.biz  wrote:
>>
>>> my windowze dev box is completely frozen at startup now, before even
>>> mounting the drive that had the slow write rate today. booted into
>>> ubuntu which is still responsive, and ran disk utility to see that
>>> smart status and self-check for both system drive and the other drive
>>> that i noticed going slow today, is "good".
>>> I wonder what's gotten my dev box ill.. Hope it aint a virus, but
>>> can't start the virus scanner coz the thing is frozen... :S
>>
>>
>> I guess that is the reason why your dev system is slow ;)
>>
> Well it's very strange. My system unfroze itself yesterday night, the
> drive in question can copy a 100mb file at regular speedy speeds with
> windows explorer, but writing 45mb of html to a file using (thousands
> of) fwrite() calls takes about 10 minutes (bit slow to say the least).
> The same fwrite()ing code on my hosted server, with nearly as much
> html to write out, works comfortably fast as well.
>
> I'm very puzzled. Would appreciate any tips to test my home system further..

Forwarded to wampserver forums;
http://forum.wampserver.com/read.php?2,84673,84673#msg-84673
Could have been the wampserver going haywire somehow yesterday... not
a virus, coz virusses don't generally stop messing with you once
they've started to, hehe.

Anyways, I'd like to return to the point of my OP, which is to get
some end-user feature requests for my analytics code.

I think I'll leave it untouched for a few days
(http://mediabeez.ws/stats/ and
http://skatescene.biz/sites/mediabeez.ws/stats) to give ya'll a chance
to view it without me introducing errors during more dev of my own.

I've kinda run out of ideas, besides ofcourse serving slightly
different stats and graphs for non-developer viewers, and the error
details only to developers. That one's obvious.

And another obvious one, I also think that plugging in location
software by http://www.maxmind.com/app/geolitecity will be a good
idea, altho I'd probably opt to work with their data in a sql table
rather than the faster php mod that they offer, coz we can't use that
from shared hosting (I think, plz correct me if I'm wrong).

But maybe you can throw me some not so obvious ones to include in this
free analytics software ;)

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



Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-23 Thread ma...@behnke.biz


rene7705  hat am 23. Mai 2012 um 13:51 geschrieben:

> I think I'll leave it untouched for a few days
> (http://mediabeez.ws/stats/ and


404 on
http://mediabeez.ws/stats/code/libraries_rv/rajmvServiceLog-1.0.0/ajax_makeLogEntry.php?rajmvServiceLog_initialID=212.48.107.10__1337775183&project_hd_root=/var/chroot/home/content/69/8082269/html/sites/mediabeez.ws/stats/

Seen in firebug. No log is loaded.

I know that you are not into optimizing bandwidth, but over 4 MB of image
data is a killer.

Could you seperate you log api code from jquery? Currently it is delivered
in one file. Makes it hard to read.

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



Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-23 Thread rene7705
On Wed, May 23, 2012 at 2:17 PM, ma...@behnke.biz  wrote:
>
>
> rene7705  hat am 23. Mai 2012 um 13:51 geschrieben:
>
>> I think I'll leave it untouched for a few days
>> (http://mediabeez.ws/stats/ and
>
>
> 404 on
> http://mediabeez.ws/stats/code/libraries_rv/rajmvServiceLog-1.0.0/ajax_makeLogEntry.php?rajmvServiceLog_initialID=212.48.107.10__1337775183&project_hd_root=/var/chroot/home/content/69/8082269/html/sites/mediabeez.ws/stats/
>
> Seen in firebug. No log is loaded.

That 404 is also on my todo list, and will get fixed together with
removal of project_hd_root from html or js output.

And please explain what you mean by "no log is loaded". No graph? No
$hits under "structure" tab, no $errors under same tab?

This morning I fixed an error in the tabs component that was causing
the entire app to fail sometimes. But you saw it after that update
probably..

>
> I know that you are not into optimizing bandwidth, but over 4 MB of image
> data is a killer.

It's entirely un-optimized at the moment, but I'll replace the tab
page buttons with 70k instead of 2.5mb worth of art soon.. Easier than
eating pie ;)

>
> Could you seperate you log api code from jquery? Currently it is delivered
> in one file. Makes it hard to read.

I thought putting many scripts in 1 call was the right thing to do.
But you can also call
.../get_rajmv_javascript.php?want=animatedJavascriptWidgets and
.../get_rajmv_javascript.php?want=rajmvServiceLog to get the log api
js code in a seperate file.
Or, you can just search for "rajmv.serviceLog =" in the
get_rajmv_javascript.php call that I use on the demos now.

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



Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-23 Thread ma...@behnke.biz


rene7705  hat am 23. Mai 2012 um 14:46 geschrieben:

> you're right, and i'm putting it on the top of my todo list.
>
> i take it you were referring to project_hd_root, or anything else as
well?

Yes.


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



Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-23 Thread ma...@behnke.biz


rene7705  hat am 23. Mai 2012 um 14:55 geschrieben:

> And please explain what you mean by "no log is loaded". No graph? No
> $hits under "structure" tab, no $errors under same tab?

As I wrote the mail to the list no tab had anything to display.
Now it's working. No idea what changed.

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



[PHP] Re: w.r.t. mail() function

2012-05-23 Thread Jonesy
On Wed, 23 May 2012 00:24:25 -0400, admin wrote:
> -Original Message-
> From: Ashwani Kesharwani [mailto:ashwani.kesharw...@gmail.com] 
> Sent: Wednesday, May 23, 2012 12:13 AM
> To: php-general@lists.php.net
> Subject: [PHP] w.r.t. mail() function
>
> Hi ,
>
> I have a query w.r.t. mail() function in php.
>
> I have hosted my site and i have created an email account as well.
>
> when i am sending mail to different recipient from my php script using above
> function it is getting delivered to respective recipients as expected.
>
> However if I want to see those mail in the sent folder of my email account ,
> i can not see those mails there.
>
> How can I achieve this.
>
> Any suggestions.
>
>>> Bad quoting above by the below: <
>
> You can change the settings of sendmail
> http://www.devshed.com/c/a/Administration/Getting-Started-with-Sendmail/12/
>
> OR
> You can log text or database each email.
> $query = "INSERT INTO mail_log (`subject`,`to`,`from`,`message`,`mail_date`)
> values ('".mysql_real_escape_string( $subject )."',
> '".mysql_real_escape_string( $to )."', '".mysql_real_escape_string( $from
> )."', '".mysql_real_escape_string( $message )."', '".date("Y-m-d H:i:s")."')
> ";
>

Or, you can Bcc: yourself and filter (procmail) the email into your 
sent-mail folder.

Jonesy


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



[PHP] Function size

2012-05-23 Thread Tedd Sperling
Hi gang:

On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
>  A rule of thumb is no more than 50 lines per
> function, most much less. Back in the day when we didn't have nifty
> gui screens and an 24 line terminals (yay green on black!), if a
> function exceeded one printed page, it was deemed too long and marked
> for refactoring.

You hit upon a theory of mine -- and that is our functions grow in size up to 
our ability to view them in their totality. When our functions get beyond that 
limit, we tend to refactor and reduce.

I know from the last several decades of programming, my functions have 
increased in number of lines. But, they have reached a limit that limit is 
generally about the number of lines I can read in half of my monitor's height. 
This of course, is dependent on monitor resolution, font-size, and how far I am 
sitting from the monitor. But I think this is a natural and physical limit that 
we don't normally recognize. I can cite studies that support my theory.

It would be an interesting survey to ask programmers to review their code and 
provide the average number of lines in their functions AND how many lines of 
code their monitor's can display. In other words, look at your editor; count 
the number of lines your monitor can display; estimate the number of lines in 
your average function; and report the findings.  For example, mine is about 
half -- my monitor can display 55 lines of code and my average function is 
around 25 lines. YMMV.

Interesting, yes?

Cheers,

tedd


_
tedd.sperl...@gmail.com
http://sperling.com






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



Re: [PHP] Differences between PHP on LAMP and PHP on Windows Servers

2012-05-23 Thread Mark Rousell
On 22/05/2012 19:15, Gates, Jeff wrote:
> Can anyone tell me what differences I might encounter by working with PHP on 
> a Unix server verses working with PHP on a Windows server. We use Windows 
> production servers here but many of us would like to get more LAMP 
> environments.
> 
> So, I'm wondering if I can use the hive mind here to get a sense of the pros 
> and cons of each platform.
> 
> Thanks.
> 
> Jeff

In addition to Ashley's response, server variables can be populated with
different values on PHP/Apache/Linux versus PHP/IIS/Windows. This can be
a particular issue if you're writing 404 handlers or anything that
relies on query strings.

In particular you need to test and check for differences between Apache
and IIS in how the REQUEST_URI, QUERY_STRING, URL, and ORIG_PATH_INFO
variables are populated depending on whether your script is being called
directly or as a 404 handler.

When redirecting due to a 404 or some other redirect or error IIS will
populate some variables with values like this
"/404.php?404;http://www.server.com:80/blah.php?v=1&t=2"; whereas Apache
will populate the same variable with "/blah.php?v=1&t=2" in the same
situation. This means the query string needs to be parsed differently.
You need to test for your own usage scenarios.



-- 
MarkR

PGP public key: http://www.signal100.com/markr/pgp
Key ID: C9C5C162


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



Re: [PHP] Differences between PHP on LAMP and PHP on Windows Servers

2012-05-23 Thread Mark Rousell
On 22/05/2012 19:32, Ashley Sheridan wrote:
> After that, you have file permissions. In Unix, you have file, owner and
> group permissions; Windows has read/write permissions and I believe on
> newer versions you can get something similar to what Unix/Linux has had
> for the last however many years but I'm not 100% sure on that one.

Just to clarify on this point, Windows (or rather NTFS) permissions use
full ACLs and so, for each file system object, any number of users
and/or groups can have any number of allow or deny permissions assigned
to them for a range of activities (e.g. read, write, append, delete,
create, execute, traverse, read/write attributes, read/write
permissions, etc.). There's a good article here that begins to explain
it: 'Understanding Windows NTFS Permissions'
http://www.windowsecurity.com/articles/Understanding-Windows-NTFS-Permissions.html

NTFS ACLs are similar to (not not identical to) Posix Access Control
Lists that are available for Linux and Unixes.


-- 
MarkR

PGP public key: http://www.signal100.com/markr/pgp
Key ID: C9C5C162


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



Re: [PHP] Function size

2012-05-23 Thread shiplu
On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling  wrote:

> Hi gang:
>
> On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> >  A rule of thumb is no more than 50 lines per
> > function, most much less. Back in the day when we didn't have nifty
> > gui screens and an 24 line terminals (yay green on black!), if a
> > function exceeded one printed page, it was deemed too long and marked
> > for refactoring.
>
> You hit upon a theory of mine -- and that is our functions grow in size up
> to our ability to view them in their totality. When our functions get
> beyond that limit, we tend to refactor and reduce.
>

When number of lines becomes the criteria of function size? Wouldn't it
depends on the task the function is doing? I follow this rule, *Each time I
end up need a code block I wrote earlier, I convert it to a function. *So
simple.  This way you re-factor your code automatically and you dont do any
copy paste.  Last year someone on Stackoverflow asked something like
this[1]. And that was my answer.


[1] http://stackoverflow.com/a/8597409/376535





> --

Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] Function size

2012-05-23 Thread Tedd Sperling

On May 23, 2012, at 11:49 AM, shiplu wrote:
> On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> When number of lines becomes the criteria of function size? Wouldn't it 
> depends on the task the function is doing? 

You missed the point.

Of course, the difficulty of the task of a specific function will directly 
contribute to the number of lines of code for that function, but that's not 
what I was talking about.

What I was talking about was that what we can grasp in one view, we can 
understand better. If the code lies outside of our view, then we understand it 
less. I can support this claim with numerous articles/books/studies of human 
visual limits vs short-term memory. I am only bringing this forward for us to 
consider in our writing code. If we know why we do things, then we can better 
understand what we do.

Cheers,

tedd

_
t...@sperling.com
http://sperling.com

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



Re: [PHP] Function size

2012-05-23 Thread Robert Cummings

On 12-05-23 12:15 PM, Tedd Sperling wrote:


On May 23, 2012, at 11:49 AM, shiplu wrote:

On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
When number of lines becomes the criteria of function size? Wouldn't it depends 
on the task the function is doing?


You missed the point.

Of course, the difficulty of the task of a specific function will directly 
contribute to the number of lines of code for that function, but that's not 
what I was talking about.

What I was talking about was that what we can grasp in one view, we can 
understand better. If the code lies outside of our view, then we understand it 
less. I can support this claim with numerous articles/books/studies of human 
visual limits vs short-term memory. I am only bringing this forward for us to 
consider in our writing code. If we know why we do things, then we can better 
understand what we do.


That's why I code in 5px font. On my huge monitor I sometimes find the 
code is shaped like a tiger, or a dragon, I swear I even saw Piccolo. It 
really does help to see the big picture :B


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



[PHP] openssl_sign() & openssl_verify() discrepancy

2012-05-23 Thread jas

I have run into a problem that I am altogether unfamiliar with.

A scenario. I retrieve a users private key from a database.

I then use the openssl_pkey_get_private() function to load it as a 
resource object and proceed to call the openssl_sign() function to 
obtain a digital signature of a string.


No problem, I get a valid signature which I then base64 encode and store 
in a database.


Now lets say a couple of days from now I load up the public key which 
corresponds to the private key which was used to originally sign the 
data to verify it and it does not work.


The kicker is if I perform the very same routine without saving the 
signature and attempting to verify it it works without problems.


Example script:

/* this part works */
$id = openssl_pkey_get_private($key, $pass);
openssl_sign($unsigned, $signed, $id);

$id = openssl_pkey_get_public($pub);
openssl_verify($unsigned, $signed, $id);

/* this doesn't (here I use the existing signature instead of generating 
a new one) */

$id = openssl_pkey_get_public($pub);
openssl_verify($unsigned, $signature, $id);

/* below here is all of the existing variables the above uses */

$unsigned = 
"w9A5Tt8JA/GVBn89WwpvXnnVsHvyWbEDu5GdX36m+ZQ=:ek4L55qc/VKAmiYdlIQhow==:ek4L55qc/VKAmiYdlIQhow==:6IraS+ArqK+/Yc472tfFqmhk5VdIACUQPCR7+kbLoAEldjejS/P1cSa8EMHxcV2s:50dt57IoKeQZ7eiwoILMR3E91MtbCgt+xVn483+9J1cNzBQGll02Qj40RVhNM/Rh:qEFBUlZzNYZNb7nksj8Fhd8Du52RVDjMBwoT/O0tdzKGfGVOeK2xrpuq1OdoAo2CN63U+Fra4zcfkzwkD3QxDA==:1337713224"


$pass = "$2a$07$31a9f929d102f5f0374deuu.cfoTJbmZtGKk92CuAOP63XaRUAVIW";

$signature = 
"h+SdcyxuQ9kpb2CXZRA/grJjlYj+drlOH2f7Ifsnt5A8dSj9lkMYU11rtjT9sdaEhf3rvoIl9JUMvkzc6dJ4DMypqgGniqbesbK6yf30FmPd0an+bTyIpeQFasmUwxtB1y6wBjIENEzEDTyb6QHPTAZg6ep2m/NjZFfUn/iiDOnDt71KQD1whouwtRZ0+UcDfPvtLQ3bAGw9C5ThDoIHRlg1kzVLrq40QsjA/3zYJE+PKwG9i1srI8zbP6uW/0t6mnUpGQrZmz6sdekkdCjjc7R9bIsFdyZ2Gisr6W1pBH64/X4nGaDkYX99ss8vYfuQMp+fLyZGgEKXuAwHjT02iQ==";


$key = "-BEGIN ENCRYPTED PRIVATE KEY-
MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIgeRB2NhoaJgCAggA
MBQGCCqGSIb3DQMHBAgk9XLQVrN2UQSCBMgNQWJWdwpXarX8Do5xPGSdEw526jai
XlvAR0lX4QzkKGnx1Fe13r0Z7AwGsEyuZWhmiQTeL40sBGtKpqdwr3Eutj+W02Kg
7jlBcgeu5DnYeQHZ6kDUJD4o08LXtDlusTIjsVLOE0YtLA67M7X2GSJrCUOurW/r
nPTYGwNt9Z59jtB/EwPqa7kxvhPF0OTZ/6+5NRmWczPnF5KAltLaH0PsR6JI9y9K
ben/SZ6QYp4PTVva5HNDBXS2sYAW9AynA7ltEOzXtWTLK2SLcGsVuqWM/WBiTyKw
MeRDPA4y6MwJDUuUvZNzNAi9FXy8c10shGSJBHyP4xBrn6DTEXEIrrsGhePRaCB1
GaH26K/q6yxq1HJdRttexHMK7GCyH325ufHT4Fup+FaJqkC0nAK6uuMbCqML4feC
K73OVzCF9Sh2o43aaJR3Ktec5ACqW7SDSABirJMU+YQpE9Dyei5d6mo+3E1rulVr
7dfsjeLmJGx5SDf8ip+tEGj4VcVm48w7hWFAmi1KAif8YLbvFEaWwTYhJg0qrCPI
eQuFVR8k6EDhGMKs2KnrfkUUhU4riosbryXACB1fi/oHmJmYAEBiYgFhYgwsNX/O
QRqedbIPDYcTfCb/j0Z59kkN9Il5YuanzPvaU6zWDMBy6qo1SYdM0lstWH7RJodq
eg/WAvKq1zwBPLoedt32UgTgHioQe4r8rVTwmQd0kFAVN+mdsdCtn7xCFliul042
n7bYWtVwiLeXecSOoY0G/0oJ7MhgddAbD9CJlLMoMmM669V+xQldoE0FKQUbrr3W
vqOIoBWp1Bd8mQ0FHn5yn/blYYy0sgCEkuSvR+NqgBt620qJ+x7kIpnay9+tdDun
v8bXz4gonA8+MGyf3yjwVNR6elZMGH/SxK1dQn65lK1AsPFKTHy+2TC5UgBw1zhe
+DjkKkilgsL3TaIKIxr/aDctqja9PfxiZek5GkDRuJN1rk3StW75hpnCyJdIQYXo
q4mpdR7MYfknH7l8hsMBGYhDJNQ2iBJ/HZag4FWl2GWRQcqlJ0cZOWST+inMCTs5
UhEKYQoifKpZGLZ9vFUC1U6jiJ5SMmHp8LlEW4XlX1fbpYWU4xiLXjrCgATW9eLE
Af3/q0bqBKggjNLqI4ShXjzBhExRKlVOceWxO2PJUzBKYkmENJ3oV1ykuPFp2cwO
2jhmMvCIL9ja3d8xQXc/WbCkmKOIm94PvAT7SmZksf7tvKNlhRrKS53ncGyWxhNp
VwRtxQq/VnKJvyXWjImqE4bIeh3Ca1kzVoO0fmSS1la42hRXoXOlFOC59i3P9Tfs
qazgCepsMB+PfRoiarnxCRrTHunnExbNw+0aCWR8J0B6X9jTyfbga6dTNNqJvHBI
ffp9R9tDd+3trwC7RNbCLSv8E6qRKiNM1kv4UhP4avn0J21wnB0fjz32PASrArNe
NCauY0+sSCwrE03nDhdt4NUhylAa6JTJZwQlNM6zwt7ITBOnVTQh0EoZl+fJRN9f
QROdqPuvJUHaO1UbL05cm9bqpovs7+vn2UxkpMTkQ/lyS8Vfl5DbqX6dCKz3/3pP
KK7LjZegt9Ey2wZB/9OiKGyOPiXPwzXcXR/evC6TFeIA07/8018PRjdjefZV26c4
M4g=
-END ENCRYPTED PRIVATE KEY-";

$pub = "-BEGIN PUBLIC KEY-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyEFetjn8mpkqHTgtKATK
Gu7dgG6UXHD+Ft8UO6WoWgVGhnjgk+SlNI+4RG9BvCaG4jbPueu4nb15oO4aObQg
RXZ7el2gjgEYu90qRILsDSzouoGFc/qPe6tNOUZ/ZXR3kBTm9t3CAW4bNDsnfUnP
YFQVdFco03Pbz8vejc0SVSC8l2lw+ZSkMYDzDmhv09Uk1zh1kc/ACOU0AoofEaUM
2eyekwcQiVwzKksGjW70eOuI2QtgpIwuvQSS/BAcymYKkxJZVxUMPCwdBwY+Pyo+
+lD4yGeki0E7x72uQy0bzulxa6iXhQOYFQEcShxyJEF6YN/R/XSIQBLTi9biWvGg
6QIDAQAB
-END PUBLIC KEY-";



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



Re: [PHP] Re: w.r.t. mail() function

2012-05-23 Thread Matijn Woudt
On Wed, May 23, 2012 at 3:50 PM, Jonesy  wrote:
> On Wed, 23 May 2012 00:24:25 -0400, admin wrote:
>> -Original Message-
>> From: Ashwani Kesharwani [mailto:ashwani.kesharw...@gmail.com]
>> Sent: Wednesday, May 23, 2012 12:13 AM
>> To: php-general@lists.php.net
>> Subject: [PHP] w.r.t. mail() function
>>
>> Hi ,
>>
>> I have a query w.r.t. mail() function in php.
>>
>> I have hosted my site and i have created an email account as well.
>>
>> when i am sending mail to different recipient from my php script using above
>> function it is getting delivered to respective recipients as expected.
>>
>> However if I want to see those mail in the sent folder of my email account ,
>> i can not see those mails there.
>>
>> How can I achieve this.
>>
>> Any suggestions.
>>
 Bad quoting above by the below: <
>>
>> You can change the settings of sendmail
>> http://www.devshed.com/c/a/Administration/Getting-Started-with-Sendmail/12/
>>
>> OR
>> You can log text or database each email.
>> $query = "INSERT INTO mail_log (`subject`,`to`,`from`,`message`,`mail_date`)
>> values ('".mysql_real_escape_string( $subject )."',
>> '".mysql_real_escape_string( $to )."', '".mysql_real_escape_string( $from
>> )."', '".mysql_real_escape_string( $message )."', '".date("Y-m-d H:i:s")."')
>> ";
>>
>
> Or, you can Bcc: yourself and filter (procmail) the email into your
> sent-mail folder.
>
> Jonesy
>

Or, if your mail server has IMAP access, use any PHP  IMAP extension
to connect to your IMAP server and send it from there. Then it will
appear in your outbox.

- Matijn

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



Re: [PHP] Differences between PHP on LAMP and PHP on Windows Servers

2012-05-23 Thread Matijn Woudt
On Tue, May 22, 2012 at 8:15 PM, Gates, Jeff  wrote:
> Can anyone tell me what differences I might encounter by working with PHP on 
> a Unix server verses working with PHP on a Windows server. We use Windows 
> production servers here but many of us would like to get more LAMP 
> environments.
>
> So, I'm wondering if I can use the hive mind here to get a sense of the pros 
> and cons of each platform.
>
> Thanks.
>
> Jeff

Apart from all other suggestions, one of the most common errors are
because of different php.ini settings. If you can keep those settings
(mostly) equal, there will not be that many errors.

- Matijn

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



Re: [PHP] Function size

2012-05-23 Thread Matijn Woudt
On Wed, May 23, 2012 at 5:49 PM, shiplu  wrote:
> On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling  wrote:
>
>> Hi gang:
>>
>> On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
>> >  A rule of thumb is no more than 50 lines per
>> > function, most much less. Back in the day when we didn't have nifty
>> > gui screens and an 24 line terminals (yay green on black!), if a
>> > function exceeded one printed page, it was deemed too long and marked
>> > for refactoring.
>>
>> You hit upon a theory of mine -- and that is our functions grow in size up
>> to our ability to view them in their totality. When our functions get
>> beyond that limit, we tend to refactor and reduce.
>>
>
> When number of lines becomes the criteria of function size? Wouldn't it
> depends on the task the function is doing? I follow this rule, *Each time I
> end up need a code block I wrote earlier, I convert it to a function. *So
> simple.  This way you re-factor your code automatically and you dont do any
> copy paste.  Last year someone on Stackoverflow asked something like
> this[1]. And that was my answer.
>
>

Hi,

While this could be one reason to start a new function, it should not
(IMO) be the only reason. Sometimes you can have a large complicated
function, with say 200 LOC. While I wouldn't need any of these lines a
second time, I usually try to rip blocks of say 50 lines out and put
it in a seperate function, so that the main function itself is easier
to understand.

- Matijn

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



Re: [PHP] openssl_sign() & openssl_verify() discrepancy

2012-05-23 Thread Matijn Woudt
On Wed, May 23, 2012 at 8:29 PM, jas  wrote:
> I have run into a problem that I am altogether unfamiliar with.
>
> A scenario. I retrieve a users private key from a database.
>
> I then use the openssl_pkey_get_private() function to load it as a resource
> object and proceed to call the openssl_sign() function to obtain a digital
> signature of a string.
>
> No problem, I get a valid signature which I then base64 encode and store in
> a database.
>
> Now lets say a couple of days from now I load up the public key which
> corresponds to the private key which was used to originally sign the data to
> verify it and it does not work.
>
> The kicker is if I perform the very same routine without saving the
> signature and attempting to verify it it works without problems.
>

Have you checked what $signed looks like after running the script?
Compare it to $signature. Most likely you corrupted your date
elsewhere, maybe when inserting it into the database.

- Matijn

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



Re: [PHP] openssl_sign() & openssl_verify() discrepancy

2012-05-23 Thread Jason Gerfen

On 05/23/2012 01:05 PM, Matijn Woudt wrote:

On Wed, May 23, 2012 at 8:29 PM, jas  wrote:

I have run into a problem that I am altogether unfamiliar with.

A scenario. I retrieve a users private key from a database.

I then use the openssl_pkey_get_private() function to load it as a resource
object and proceed to call the openssl_sign() function to obtain a digital
signature of a string.

No problem, I get a valid signature which I then base64 encode and store in
a database.

Now lets say a couple of days from now I load up the public key which
corresponds to the private key which was used to originally sign the data to
verify it and it does not work.

The kicker is if I perform the very same routine without saving the
signature and attempting to verify it it works without problems.


Have you checked what $signed looks like after running the script?
Compare it to $signature. Most likely you corrupted your date
elsewhere, maybe when inserting it into the database.

- Matijn
The example that accompanies the post shows two examples, one works & 
one does not. Neither however use any type of database, as both simply 
assign or use the valid signature stored within either the $signature or 
$signed variables.


I wish I could say that is the problem, I took care to properly 
encode/decode when saving or retrieving the information and as well in 
the original post I removed this as a possible cause by simply defining 
the $signature variable and assigning a valid signature to it for testing.


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



Re: [PHP] Function size

2012-05-23 Thread Tedd Sperling
On May 23, 2012, at 12:21 PM, Robert Cummings wrote:
> On 12-05-23 12:15 PM, Tedd Sperling wrote:
>> What I was talking about was that what we can grasp in one view, we can 
>> understand better. If the code lies outside of our view, then we understand 
>> it less. I can support this claim with numerous articles/books/studies of 
>> human visual limits vs short-term memory. I am only bringing this forward 
>> for us to consider in our writing code. If we know why we do things, then we 
>> can better understand what we do.
> 
> That's why I code in 5px font. On my huge monitor I sometimes find the code 
> is shaped like a tiger, or a dragon, I swear I even saw Piccolo. It really 
> does help to see the big picture :B
> 
> Cheers,
> Rob.

Forgive me -- I should have know better.

This is a bit like talking to my grandkids -- if it doesn't involve dulling 
crayons, there's no point. :-)

Cheers,

tedd

_
t...@sperling.com
http://sperling.com




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



Re: [PHP] openssl_sign() & openssl_verify() discrepancy

2012-05-23 Thread Matijn Woudt
On Wed, May 23, 2012 at 9:12 PM, Jason Gerfen  wrote:
> On 05/23/2012 01:05 PM, Matijn Woudt wrote:
>>
>> On Wed, May 23, 2012 at 8:29 PM, jas  wrote:
>>>
>>> I have run into a problem that I am altogether unfamiliar with.
>>>
>>> A scenario. I retrieve a users private key from a database.
>>>
>>> I then use the openssl_pkey_get_private() function to load it as a
>>> resource
>>> object and proceed to call the openssl_sign() function to obtain a
>>> digital
>>> signature of a string.
>>>
>>> No problem, I get a valid signature which I then base64 encode and store
>>> in
>>> a database.
>>>
>>> Now lets say a couple of days from now I load up the public key which
>>> corresponds to the private key which was used to originally sign the data
>>> to
>>> verify it and it does not work.
>>>
>>> The kicker is if I perform the very same routine without saving the
>>> signature and attempting to verify it it works without problems.
>>>
>> Have you checked what $signed looks like after running the script?
>> Compare it to $signature. Most likely you corrupted your date
>> elsewhere, maybe when inserting it into the database.
>>
>> - Matijn
>
> The example that accompanies the post shows two examples, one works & one
> does not. Neither however use any type of database, as both simply assign or
> use the valid signature stored within either the $signature or $signed
> variables.
>
> I wish I could say that is the problem, I took care to properly
> encode/decode when saving or retrieving the information and as well in the
> original post I removed this as a possible cause by simply defining the
> $signature variable and assigning a valid signature to it for testing.
>

First of all, it seems $signature is in base64 format, so I think you
should base64_decode that one first. Then it appears to me that
$signature is not the same as $signed, on my system. If I
base64_encode $signed, save it by copying it from my browser, and then
enter it as $signature, and then use base64_decode on $signature it
works fine.

- Matijn

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



Re: [PHP] Re: w.r.t. mail() function

2012-05-23 Thread Ashley Sheridan
On Wed, 2012-05-23 at 20:36 +0200, Matijn Woudt wrote:

> On Wed, May 23, 2012 at 3:50 PM, Jonesy  wrote:
> > On Wed, 23 May 2012 00:24:25 -0400, admin wrote:
> >> -Original Message-
> >> From: Ashwani Kesharwani [mailto:ashwani.kesharw...@gmail.com]
> >> Sent: Wednesday, May 23, 2012 12:13 AM
> >> To: php-general@lists.php.net
> >> Subject: [PHP] w.r.t. mail() function
> >>
> >> Hi ,
> >>
> >> I have a query w.r.t. mail() function in php.
> >>
> >> I have hosted my site and i have created an email account as well.
> >>
> >> when i am sending mail to different recipient from my php script using 
> >> above
> >> function it is getting delivered to respective recipients as expected.
> >>
> >> However if I want to see those mail in the sent folder of my email account 
> >> ,
> >> i can not see those mails there.
> >>
> >> How can I achieve this.
> >>
> >> Any suggestions.
> >>
>  Bad quoting above by the below: <
> >>
> >> You can change the settings of sendmail
> >> http://www.devshed.com/c/a/Administration/Getting-Started-with-Sendmail/12/
> >>
> >> OR
> >> You can log text or database each email.
> >> $query = "INSERT INTO mail_log 
> >> (`subject`,`to`,`from`,`message`,`mail_date`)
> >> values ('".mysql_real_escape_string( $subject )."',
> >> '".mysql_real_escape_string( $to )."', '".mysql_real_escape_string( $from
> >> )."', '".mysql_real_escape_string( $message )."', '".date("Y-m-d 
> >> H:i:s")."')
> >> ";
> >>
> >
> > Or, you can Bcc: yourself and filter (procmail) the email into your
> > sent-mail folder.
> >
> > Jonesy
> >
> 
> Or, if your mail server has IMAP access, use any PHP  IMAP extension
> to connect to your IMAP server and send it from there. Then it will
> appear in your outbox.
> 
> - Matijn
> 


Are you sure? I connect to my email through Imap on both my desktop and
my phone, and neither sees the others sent emails. I thought sent was
just a local thing, unless the email client is specifically configured
to do something special.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Differences between PHP on LAMP and PHP on Windows Servers

2012-05-23 Thread Ashley Sheridan
On Wed, 2012-05-23 at 20:54 +0200, Matijn Woudt wrote:

> On Tue, May 22, 2012 at 8:15 PM, Gates, Jeff  wrote:
> > Can anyone tell me what differences I might encounter by working with PHP 
> > on a Unix server verses working with PHP on a Windows server. We use 
> > Windows production servers here but many of us would like to get more LAMP 
> > environments.
> >
> > So, I'm wondering if I can use the hive mind here to get a sense of the 
> > pros and cons of each platform.
> >
> > Thanks.
> >
> > Jeff
> 
> Apart from all other suggestions, one of the most common errors are
> because of different php.ini settings. If you can keep those settings
> (mostly) equal, there will not be that many errors.
> 
> - Matijn
> 


I would say that's not limited to the distinction between Windows and
Linux but any server. I've seen what appears to be an identical setup
(same version of PHP, MySQL, etc) fail only because of a small setting
in the php.ini file, just because the default was slightly different on
the second system; both were running Linux.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] openssl_sign() & openssl_verify() discrepancy

2012-05-23 Thread Jason Gerfen

On 05/23/2012 01:26 PM, Matijn Woudt wrote:

On Wed, May 23, 2012 at 9:12 PM, Jason Gerfen  wrote:

On 05/23/2012 01:05 PM, Matijn Woudt wrote:

On Wed, May 23, 2012 at 8:29 PM, jaswrote:

I have run into a problem that I am altogether unfamiliar with.

A scenario. I retrieve a users private key from a database.

I then use the openssl_pkey_get_private() function to load it as a
resource
object and proceed to call the openssl_sign() function to obtain a
digital
signature of a string.

No problem, I get a valid signature which I then base64 encode and store
in
a database.

Now lets say a couple of days from now I load up the public key which
corresponds to the private key which was used to originally sign the data
to
verify it and it does not work.

The kicker is if I perform the very same routine without saving the
signature and attempting to verify it it works without problems.


Have you checked what $signed looks like after running the script?
Compare it to $signature. Most likely you corrupted your date
elsewhere, maybe when inserting it into the database.

- Matijn

The example that accompanies the post shows two examples, one works&  one
does not. Neither however use any type of database, as both simply assign or
use the valid signature stored within either the $signature or $signed
variables.

I wish I could say that is the problem, I took care to properly
encode/decode when saving or retrieving the information and as well in the
original post I removed this as a possible cause by simply defining the
$signature variable and assigning a valid signature to it for testing.


First of all, it seems $signature is in base64 format, so I think you
should base64_decode that one first. Then it appears to me that
$signature is not the same as $signed, on my system. If I
base64_encode $signed, save it by copying it from my browser, and then
enter it as $signature, and then use base64_decode on $signature it
works fine.

- Matijn
Those are the same steps I just mentioned. The base64_decoding is a typo 
on the second example. It should read


openssl_verify($unsigned, base64_decode($signature), $id);

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



Re: [PHP] Function size

2012-05-23 Thread Ashley Sheridan
On Wed, 2012-05-23 at 20:59 +0200, Matijn Woudt wrote:

> On Wed, May 23, 2012 at 5:49 PM, shiplu  wrote:
> > On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling  wrote:
> >
> >> Hi gang:
> >>
> >> On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> >> >  A rule of thumb is no more than 50 lines per
> >> > function, most much less. Back in the day when we didn't have nifty
> >> > gui screens and an 24 line terminals (yay green on black!), if a
> >> > function exceeded one printed page, it was deemed too long and marked
> >> > for refactoring.
> >>
> >> You hit upon a theory of mine -- and that is our functions grow in size up
> >> to our ability to view them in their totality. When our functions get
> >> beyond that limit, we tend to refactor and reduce.
> >>
> >
> > When number of lines becomes the criteria of function size? Wouldn't it
> > depends on the task the function is doing? I follow this rule, *Each time I
> > end up need a code block I wrote earlier, I convert it to a function. *So
> > simple.  This way you re-factor your code automatically and you dont do any
> > copy paste.  Last year someone on Stackoverflow asked something like
> > this[1]. And that was my answer.
> >
> >
> 
> Hi,
> 
> While this could be one reason to start a new function, it should not
> (IMO) be the only reason. Sometimes you can have a large complicated
> function, with say 200 LOC. While I wouldn't need any of these lines a
> second time, I usually try to rip blocks of say 50 lines out and put
> it in a seperate function, so that the main function itself is easier
> to understand.
> 
> - Matijn
> 


I'm of the same mind. Generally I'll split a function if I'm reusing
more than a couple of lines of code. I only split a "large" function if
it's actually doing several things, if it happens to need 200 lines to
perform one 'step' then I'll leave it as is. While I do prefer my
functions to fit into a single 'screen', it rarely happens quite like
that, because I move from screen to screen with different resolutions,
so there's no constant limit for me.

As a rough example, on a random selection of 27 functions taken from a
controller on a site I worked on I get these general statistics:

Functions: 27
Mean lines: 22.5
Mode lines: 3
Max lines: 218

The function with 218 lines is a large switch, and it doesn't make sense
to do it any other way, because it would actually end up less readable.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Function size

2012-05-23 Thread Matijn Woudt
On Wed, May 23, 2012 at 9:49 PM, Ashley Sheridan
wrote:

> **
> On Wed, 2012-05-23 at 20:59 +0200, Matijn Woudt wrote:
>
> On Wed, May 23, 2012 at 5:49 PM, shiplu  wrote:
> > On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling  wrote:
> >
> >> Hi gang:
> >>
> >> On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> >> >  A rule of thumb is no more than 50 lines per
> >> > function, most much less. Back in the day when we didn't have nifty
> >> > gui screens and an 24 line terminals (yay green on black!), if a
> >> > function exceeded one printed page, it was deemed too long and marked
> >> > for refactoring.
> >>
> >> You hit upon a theory of mine -- and that is our functions grow in size up
> >> to our ability to view them in their totality. When our functions get
> >> beyond that limit, we tend to refactor and reduce.
> >>
> >
> > When number of lines becomes the criteria of function size? Wouldn't it
> > depends on the task the function is doing? I follow this rule, *Each time I
> > end up need a code block I wrote earlier, I convert it to a function. *So
> > simple.  This way you re-factor your code automatically and you dont do any
> > copy paste.  Last year someone on Stackoverflow asked something like
> > this[1]. And that was my answer.
> >
> >
>
> Hi,
>
> While this could be one reason to start a new function, it should not
> (IMO) be the only reason. Sometimes you can have a large complicated
> function, with say 200 LOC. While I wouldn't need any of these lines a
> second time, I usually try to rip blocks of say 50 lines out and put
> it in a seperate function, so that the main function itself is easier
> to understand.
>
> - Matijn
>
>
>
> I'm of the same mind. Generally I'll split a function if I'm reusing more
> than a couple of lines of code. I only split a "large" function if it's
> actually doing several things, if it happens to need 200 lines to perform
> one 'step' then I'll leave it as is. While I do prefer my functions to fit
> into a single 'screen', it rarely happens quite like that, because I move
> from screen to screen with different resolutions, so there's no constant
> limit for me.
>
> As a rough example, on a random selection of 27 functions taken from a
> controller on a site I worked on I get these general statistics:
>
> Functions: 27
> Mean lines: 22.5
> Mode lines: 3
> Max lines: 218
>
> The function with 218 lines is a large switch, and it doesn't make sense
> to do it any other way, because it would actually end up less readable.
>
>
I agree that large switch block are not always easy and useful to split,
however, writing too much code inside a switch block isn't considered good
practice too IMO. Though, it is unavoidable in some cases I think. I do
have some of these functions in my code too, I have one switch block of
more than 500 lines, but that's just because I have more than 400
individual case statements, and I don't think there's a better way to do
it. Doesn't mean I like it btw..

- Matijn


Re: [PHP] Re: w.r.t. mail() function

2012-05-23 Thread Matijn Woudt
On Wed, May 23, 2012 at 9:33 PM, Ashley Sheridan
wrote:

> **
> On Wed, 2012-05-23 at 20:36 +0200, Matijn Woudt wrote:
>
> On Wed, May 23, 2012 at 3:50 PM, Jonesy  wrote:
> > On Wed, 23 May 2012 00:24:25 -0400, admin wrote:
> >> -Original Message-
> >> From: Ashwani Kesharwani [mailto:ashwani.kesharw...@gmail.com 
> >> ]
> >> Sent: Wednesday, May 23, 2012 12:13 AM
> >> To: php-general@lists.php.net
> >> Subject: [PHP] w.r.t. mail() function
> >>
> >> Hi ,
> >>
> >> I have a query w.r.t. mail() function in php.
> >>
> >> I have hosted my site and i have created an email account as well.
> >>
> >> when i am sending mail to different recipient from my php script using 
> >> above
> >> function it is getting delivered to respective recipients as expected.
> >>
> >> However if I want to see those mail in the sent folder of my email account 
> >> ,
> >> i can not see those mails there.
> >>
> >> How can I achieve this.
> >>
> >> Any suggestions.
> >>
>  Bad quoting above by the below: <
> >>
> >> You can change the settings of sendmail
> >> http://www.devshed.com/c/a/Administration/Getting-Started-with-Sendmail/12/
> >>
> >> OR
> >> You can log text or database each email.
> >> $query = "INSERT INTO mail_log 
> >> (`subject`,`to`,`from`,`message`,`mail_date`)
> >> values ('".mysql_real_escape_string( $subject )."',
> >> '".mysql_real_escape_string( $to )."', '".mysql_real_escape_string( $from
> >> )."', '".mysql_real_escape_string( $message )."', '".date("Y-m-d 
> >> H:i:s")."')
> >> ";
> >>
> >
> > Or, you can Bcc: yourself and filter (procmail) the email into your
> > sent-mail folder.
> >
> > Jonesy
> >
>
> Or, if your mail server has IMAP access, use any PHP  IMAP extension
> to connect to your IMAP server and send it from there. Then it will
> appear in your outbox.
>
> - Matijn
>
>
>
> Are you sure? I connect to my email through Imap on both my desktop and my
> phone, and neither sees the others sent emails. I thought sent was just a
> local thing, unless the email client is specifically configured to do
> something special.
>

Yes, I have a few applications that send email through IMAP and they end up
in my sent mail box. Both with this Gmail account, and a mail server on a
different host. You're clients are probably configured to still use SMTP
for sending, not IMAP.

- Matijn


Re: [PHP] Differences between PHP on LAMP and PHP on Windows Servers

2012-05-23 Thread Matijn Woudt
On Wed, May 23, 2012 at 9:35 PM, Ashley Sheridan
wrote:

> **
> On Wed, 2012-05-23 at 20:54 +0200, Matijn Woudt wrote:
>
> On Tue, May 22, 2012 at 8:15 PM, Gates, Jeff  wrote:
> > Can anyone tell me what differences I might encounter by working with PHP 
> > on a Unix server verses working with PHP on a Windows server. We use 
> > Windows production servers here but many of us would like to get more LAMP 
> > environments.
> >
> > So, I'm wondering if I can use the hive mind here to get a sense of the 
> > pros and cons of each platform.
> >
> > Thanks.
> >
> > Jeff
>
> Apart from all other suggestions, one of the most common errors are
> because of different php.ini settings. If you can keep those settings
> (mostly) equal, there will not be that many errors.
>
> - Matijn
>
>
>
> I would say that's not limited to the distinction between Windows and
> Linux but any server. I've seen what appears to be an identical setup (same
> version of PHP, MySQL, etc) fail only because of a small setting in the
> php.ini file, just because the default was slightly different on the second
> system; both were running Linux.
>
>
Yes, ofcourse, that comment was meant for any two systems.

- Matijn


Re: [PHP] openssl_sign() & openssl_verify() discrepancy

2012-05-23 Thread Matijn Woudt
On Wed, May 23, 2012 at 9:42 PM, Jason Gerfen  wrote:
> On 05/23/2012 01:26 PM, Matijn Woudt wrote:
>>
>> On Wed, May 23, 2012 at 9:12 PM, Jason Gerfen
>>  wrote:
>>>
>>> On 05/23/2012 01:05 PM, Matijn Woudt wrote:

 On Wed, May 23, 2012 at 8:29 PM, jas    wrote:
>
> I have run into a problem that I am altogether unfamiliar with.
>
> A scenario. I retrieve a users private key from a database.
>
> I then use the openssl_pkey_get_private() function to load it as a
> resource
> object and proceed to call the openssl_sign() function to obtain a
> digital
> signature of a string.
>
> No problem, I get a valid signature which I then base64 encode and
> store
> in
> a database.
>
> Now lets say a couple of days from now I load up the public key which
> corresponds to the private key which was used to originally sign the
> data
> to
> verify it and it does not work.
>
> The kicker is if I perform the very same routine without saving the
> signature and attempting to verify it it works without problems.
>
 Have you checked what $signed looks like after running the script?
 Compare it to $signature. Most likely you corrupted your date
 elsewhere, maybe when inserting it into the database.

 - Matijn
>>>
>>> The example that accompanies the post shows two examples, one works&  one
>>>
>>> does not. Neither however use any type of database, as both simply assign
>>> or
>>> use the valid signature stored within either the $signature or $signed
>>> variables.
>>>
>>> I wish I could say that is the problem, I took care to properly
>>> encode/decode when saving or retrieving the information and as well in
>>> the
>>> original post I removed this as a possible cause by simply defining the
>>> $signature variable and assigning a valid signature to it for testing.
>>>
>> First of all, it seems $signature is in base64 format, so I think you
>> should base64_decode that one first. Then it appears to me that
>> $signature is not the same as $signed, on my system. If I
>> base64_encode $signed, save it by copying it from my browser, and then
>> enter it as $signature, and then use base64_decode on $signature it
>> works fine.
>>
>> - Matijn
>
> Those are the same steps I just mentioned. The base64_decoding is a typo on
> the second example. It should read
>
> openssl_verify($unsigned, base64_decode($signature), $id);
>

Well, then maybe you should explain the problem further, because with
this it works fine, and it appears to me the problem is not here but
it comes when you try to store/retrieve the data.

- Matijn

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



Re: [PHP] Function size

2012-05-23 Thread shiplu
On Thu, May 24, 2012 at 1:56 AM, Matijn Woudt  wrote:

> I agree that large switch block are not always easy and useful to split,
> however, writing too much code inside a switch block isn't considered good
> practice too IMO. Though, it is unavoidable in some cases I think. I do
> have some of these functions in my code too, I have one switch block of
> more than 500 lines, but that's just because I have more than 400
> individual case statements, and I don't think there's a better way to do
> it. Doesn't mean I like it btw.


I never encounter such big switch statement in PHP yet. However I saw huge
switch and had to optimize it while  working with a custom programming
language interpreter written in C.  When I see the language is OO, I try to
apply polymorphic behavior and eliminate any switch statements. Here is a
video that demonstrated the concept
http://www.youtube.com/watch?v=4F72VULWFvc

-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] w.r.t. mail() function

2012-05-23 Thread Jim Lucas

On 05/22/2012 09:12 PM, Ashwani Kesharwani wrote:

Hi ,

I have a query w.r.t. mail() function in php.

I have hosted my site and i have created an email account as well.

when i am sending mail to different recipient from my php script using
above function it is getting delivered to respective recipients as expected.

However if I want to see those mail in the sent folder of my email account
, i can not see those mails there.

How can I achieve this.

Any suggestions.

Regards
Ashwani



Why not BCC it to your self, and then setup a filter in your email 
client to move it where ever you want it to be.


--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

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



Re: [PHP] Function size

2012-05-23 Thread Camilo Sperberg
I use a lot of switches but they are always small in size because they look 
mostly like this:

switch($action) {
  case 'hello':
$someObject->executeAction();
break;
  case 'world':
$someOtherObject->executeOtherAction();
break;
  default:
$this->anotherAction();
break;
}

Maybe it's not the rule for some really specific small functionality which I 
know I won't be using ever again, but that's the latest trend I've acquired in 
order to improve readability. Personally I find that the particular switch 
statement disorders the code, but at least it is a lot better than a lot of 
if/elses xD

Haven't you tried this approach or does that particular function do have a lot 
of cases?

Greetings.

On 23 mei 2012, at 21:49, Ashley Sheridan wrote:

> On Wed, 2012-05-23 at 20:59 +0200, Matijn Woudt wrote:
> 
>> On Wed, May 23, 2012 at 5:49 PM, shiplu  wrote:
>>> On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling  wrote:
>>> 
 Hi gang:
 
 On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> A rule of thumb is no more than 50 lines per
> function, most much less. Back in the day when we didn't have nifty
> gui screens and an 24 line terminals (yay green on black!), if a
> function exceeded one printed page, it was deemed too long and marked
> for refactoring.
 
 You hit upon a theory of mine -- and that is our functions grow in size up
 to our ability to view them in their totality. When our functions get
 beyond that limit, we tend to refactor and reduce.
 
>>> 
>>> When number of lines becomes the criteria of function size? Wouldn't it
>>> depends on the task the function is doing? I follow this rule, *Each time I
>>> end up need a code block I wrote earlier, I convert it to a function. *So
>>> simple.  This way you re-factor your code automatically and you dont do any
>>> copy paste.  Last year someone on Stackoverflow asked something like
>>> this[1]. And that was my answer.
>>> 
>>> 
>> 
>> Hi,
>> 
>> While this could be one reason to start a new function, it should not
>> (IMO) be the only reason. Sometimes you can have a large complicated
>> function, with say 200 LOC. While I wouldn't need any of these lines a
>> second time, I usually try to rip blocks of say 50 lines out and put
>> it in a seperate function, so that the main function itself is easier
>> to understand.
>> 
>> - Matijn
>> 
> 
> 
> I'm of the same mind. Generally I'll split a function if I'm reusing
> more than a couple of lines of code. I only split a "large" function if
> it's actually doing several things, if it happens to need 200 lines to
> perform one 'step' then I'll leave it as is. While I do prefer my
> functions to fit into a single 'screen', it rarely happens quite like
> that, because I move from screen to screen with different resolutions,
> so there's no constant limit for me.
> 
> As a rough example, on a random selection of 27 functions taken from a
> controller on a site I worked on I get these general statistics:
> 
> Functions: 27
> Mean lines: 22.5
> Mode lines: 3
> Max lines: 218
> 
> The function with 218 lines is a large switch, and it doesn't make sense
> to do it any other way, because it would actually end up less readable.
> 
> -- 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 


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



Re: [PHP] Function size

2012-05-23 Thread Jeremiah Dodds
Tedd Sperling  writes:

> It would be an interesting survey to ask programmers to review their code and
> provide the average number of lines in their functions AND how many lines of
> code their monitor's can display. In other words, look at your editor; count 
> the
> number of lines your monitor can display; estimate the number of lines in your
> average function; and report the findings.  For example, mine is about half --
> my monitor can display 55 lines of code and my average function is around 25
> lines. YMMV.
>
> Interesting, yes?
>
> Cheers,
>
> tedd
>
>
> _
> tedd.sperl...@gmail.com
> http://sperling.com

My monitor can also display about 55 lines of code, my functions are, on
average, just a few lines of code though -- a maximum of about 20, with
an average of around 5 or so.

This is because the rule of thumb I follow is that a function should do
one thing, and should be named well. The biggest downside to the type of
style I have is that if not done "correctly", people can feel like
they're swimming in a sea of chasing down functions to find out wtf is
going on. When done "correctly", it leads to pretty clear code, IMO.

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