php-general Digest 24 May 2012 07:18:43 -0000 Issue 7824
Topics (messages 317952 through 317975):
Re: Function size
317952 by: shiplu
317953 by: Tedd Sperling
317954 by: Robert Cummings
317958 by: Matijn Woudt
317961 by: Tedd Sperling
317966 by: Ashley Sheridan
317967 by: Matijn Woudt
317971 by: shiplu
317973 by: Camilo Sperberg
317974 by: Jeremiah Dodds
openssl_sign() & openssl_verify() discrepancy
317955 by: jas
317959 by: Matijn Woudt
317960 by: jas
317962 by: Matijn Woudt
317965 by: jas
317970 by: Matijn Woudt
Re: w.r.t. mail() function
317956 by: Matijn Woudt
317963 by: Ashley Sheridan
317968 by: Matijn Woudt
317972 by: Jim Lucas
Re: Differences between PHP on LAMP and PHP on Windows Servers
317957 by: Matijn Woudt
317964 by: Ashley Sheridan
317969 by: Matijn Woudt
Need help on increment date
317975 by: Md Ashickur Rahman Noor
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling <t...@sperling.com> 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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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.
--- End Message ---
--- Begin Message ---
On Wed, May 23, 2012 at 5:49 PM, shiplu <shiplu....@gmail.com> wrote:
> On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling <t...@sperling.com> 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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
On Wed, 2012-05-23 at 20:59 +0200, Matijn Woudt wrote:
> On Wed, May 23, 2012 at 5:49 PM, shiplu <shiplu....@gmail.com> wrote:
> > On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling <t...@sperling.com> 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
--- End Message ---
--- Begin Message ---
On Wed, May 23, 2012 at 9:49 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:
> **
> On Wed, 2012-05-23 at 20:59 +0200, Matijn Woudt wrote:
>
> On Wed, May 23, 2012 at 5:49 PM, shiplu <shiplu....@gmail.com> wrote:
> > On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling <t...@sperling.com> 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
--- End Message ---
--- Begin Message ---
On Thu, May 24, 2012 at 1:56 AM, Matijn Woudt <tijn...@gmail.com> 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
--- End Message ---
--- Begin Message ---
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 <shiplu....@gmail.com> wrote:
>>> On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling <t...@sperling.com> 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
>
>
--- End Message ---
--- Begin Message ---
Tedd Sperling <t...@sperling.com> 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.
--- End Message ---
--- Begin Message ---
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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I2QtgpIwuvQSS/BAcymYKkxJZVxUMPCwdBwY+Pyo+
+lD4yGeki0E7x72uQy0bzulxa6iXhQOYFQEcShxyJEF6YN/R/XSIQBLTi9biWvGg
6QIDAQAB
-----END PUBLIC KEY-----";
--- End Message ---
--- Begin Message ---
On Wed, May 23, 2012 at 8:29 PM, jas <jason.ger...@utah.edu> 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
--- End Message ---
--- Begin Message ---
On 05/23/2012 01:05 PM, Matijn Woudt wrote:
On Wed, May 23, 2012 at 8:29 PM, jas<jason.ger...@utah.edu> 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.
--- End Message ---
--- Begin Message ---
On Wed, May 23, 2012 at 9:12 PM, Jason Gerfen <jason.ger...@utah.edu> wrote:
> On 05/23/2012 01:05 PM, Matijn Woudt wrote:
>>
>> On Wed, May 23, 2012 at 8:29 PM, jas<jason.ger...@utah.edu> 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
--- End Message ---
--- Begin Message ---
On 05/23/2012 01:26 PM, Matijn Woudt wrote:
On Wed, May 23, 2012 at 9:12 PM, Jason Gerfen<jason.ger...@utah.edu> wrote:
On 05/23/2012 01:05 PM, Matijn Woudt wrote:
On Wed, May 23, 2012 at 8:29 PM, jas<jason.ger...@utah.edu> 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);
--- End Message ---
--- Begin Message ---
On Wed, May 23, 2012 at 9:42 PM, Jason Gerfen <jason.ger...@utah.edu> wrote:
> On 05/23/2012 01:26 PM, Matijn Woudt wrote:
>>
>> On Wed, May 23, 2012 at 9:12 PM, Jason Gerfen<jason.ger...@utah.edu>
>> wrote:
>>>
>>> On 05/23/2012 01:05 PM, Matijn Woudt wrote:
>>>>
>>>> On Wed, May 23, 2012 at 8:29 PM, jas<jason.ger...@utah.edu> 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
--- End Message ---
--- Begin Message ---
On Wed, May 23, 2012 at 3:50 PM, Jonesy <gm...@jonz.net> 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-gene...@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
--- End Message ---
--- Begin Message ---
On Wed, 2012-05-23 at 20:36 +0200, Matijn Woudt wrote:
> On Wed, May 23, 2012 at 3:50 PM, Jonesy <gm...@jonz.net> 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-gene...@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
--- End Message ---
--- Begin Message ---
On Wed, May 23, 2012 at 9:33 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:
> **
> On Wed, 2012-05-23 at 20:36 +0200, Matijn Woudt wrote:
>
> On Wed, May 23, 2012 at 3:50 PM, Jonesy <gm...@jonz.net> wrote:
> > On Wed, 23 May 2012 00:24:25 -0400, admin wrote:
> >> -----Original Message-----
> >> From: Ashwani Kesharwani [mailto:ashwani.kesharw...@gmail.com
> >> <ashwani.kesharw...@gmail.com>]
> >> Sent: Wednesday, May 23, 2012 12:13 AM
> >> To: php-gene...@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
--- End Message ---
--- Begin Message ---
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/
--- End Message ---
--- Begin Message ---
On Tue, May 22, 2012 at 8:15 PM, Gates, Jeff <gat...@si.edu> 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
--- End Message ---
--- Begin Message ---
On Wed, 2012-05-23 at 20:54 +0200, Matijn Woudt wrote:
> On Tue, May 22, 2012 at 8:15 PM, Gates, Jeff <gat...@si.edu> 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
--- End Message ---
--- Begin Message ---
On Wed, May 23, 2012 at 9:35 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:
> **
> On Wed, 2012-05-23 at 20:54 +0200, Matijn Woudt wrote:
>
> On Tue, May 22, 2012 at 8:15 PM, Gates, Jeff <gat...@si.edu> 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
--- End Message ---
--- Begin Message ---
HI all
I need help to increment date in php. I found this code helpful
$date = strtotime("+1 day", strtotime("2007-02-28"));
>
> echo date("Y-m-d", $date);
>
>
But when My date is "2008-02-28" this code give output 2012-03-01. But it
should be 2008-02-29. Where I am getting wrong.
----------------------------------------------------------
Dedicated Linux Forum in Bangladesh <http://goo.gl/238Ck>
2048R/89C932E1 <http://goo.gl/TkP5U>
Volunteer, FOSS Bangladesh <http://fossbd.org/> && Mozilla
Reps<http://reps.mozilla.org>
01199151550
--- End Message ---