php-general Digest 20 Oct 2010 12:36:59 -0000 Issue 6997

Topics (messages 308865 through 308882):

Re: simple class & constructor
        308865 by: David McGlone
        308866 by: David McGlone
        308867 by: David Harkness
        308868 by: Tommy Pham
        308869 by: David McGlone
        308870 by: Jay Blanchard
        308871 by: David McGlone
        308872 by: David McGlone

Re: Fiscal Years and Quarters
        308873 by: admin.buskirkgraphics.com
        308875 by: admin.buskirkgraphics.com

Possible foreach bug; seeking advice to isolate the problem
        308874 by: Jonathan Sachs
        308876 by: richard gray
        308877 by: Gary
        308881 by: Tommy Pham

Re: PHP stream_socket_client OpenSSL error (unknown ca)
        308878 by: Richard

Unicode - Entitiy Encoding
        308879 by: Sebastian Detert

Error handler script
        308880 by: Teto

Re: Firs Day Of Week UNIX
        308882 by: Richard Quadling

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Tue, 2010-10-19 at 16:53 -0700, Tommy Pham wrote:
> > -----Original Message-----
> > From: David McGlone [mailto:[email protected]]
> > Sent: Tuesday, October 19, 2010 4:32 PM
> > To: [email protected]
> > Subject: Re: [PHP] simple class & constructor
> > 
> > On Tue, 2010-10-19 at 17:15 -0400, Paul M Foster wrote:
> > > On Tue, Oct 19, 2010 at 04:12:51PM -0400, David McGlone wrote:
> > <snip>
> > > You're trying to "instantiate the class". And the way you're doing it
> > > here is correct. When you do this, $test becomes an object of this
> > > class. If you had another function ("member") within the class called
> > > "myfunction()", you could run it this way (after you instantiate the
> > > class):
> > >
> > > $test->myfunction();
> > >
> > > >
> > > > Basically I want to learn how I can (if it's possible with this
> > > > simple
> > > > code) is display the output on a different page.
> > > >
> > > > I tried putting the line: $test=new simpleConstructer(); on the
> > > > index page and including the page the class is on, but it causes the
> > > > index page to go blank.
> > >
> > > You've likely got an error you're not seeing. Fix this first. If the
> > > file your class is in is syntactically correct, and you do
> > >
> > > include "simpleConstructerFile.php";
> > >
> > > in your index.php file, it should flawlessly include the code. Then,
> > > in your index.php, you do this:
> > >
> > > $test = new simpleConstructer;
> > >
> > > you should see the contents of the echo statement appear on the page.
> > > So you're on the right track. You just need to find the error first.
> > 
> > 
> > Ah ha! Thank you! Your mention of an error, was spot on. notice below I
> > misspelled the class name but got the Object name correct.
> > 
> > Also at first I had the setup like this because it wasn't working and I 
> > thought
> > I was doing it wrong: (this also added to my confusion)
> > 
> > myclass.php
> > 
> > class simpleConstructer {
> > 
> > function __construct() {
> >     echo "running the constructor";
> >    }
> > }
> > 
> > index.php
> > require_once 'myclass.php';
> > $test = new simpleConstructor();
> > 
> > But once I fixed the error I put it all back in myclass.php like so:
> > 
> > myclass.php
> > 
> > class simpleConstructer {
> > 
> > function __construct() {
> >     echo "running the constructor";
> >    }
> > }
> > $test = new simpleConstructor();
> > 
> > 
> > Now I am wondering what you meant when you said:
> > >>>If you had another function ("member") within the class called
> > >>>"myfunction()", you could run it this way (after you instantiate the
> > >>> class):
> > 
> > >>>$test->myfunction();"
> > 
> > If you don't mind my asking, how would you take the above example and
> > change it to what you describe above?
> > 
> 
> class simpleConstructer {
>  
> function __construct() {
>      echo "running the constructor";
>    }
> 
> function myFunction() {
>  echo 'this is another function/method within the class simpleConstructor';
>   }
> }
> 
> $test = new simpleConstructor();
> $test->myfunction();

Thank you Tommy.

Now it all comes together and I believe I understand now.

Does the code immediately after the __construct automatically run, but
when adding more methods to the class, they need to be called with the
$name->Object_name? Is my thinking correct?

-- 
Blessings
David M.


--- End Message ---
--- Begin Message ---
On Tue, 2010-10-19 at 17:05 -0700, David Harkness wrote:
> Note that you still have a typo, but maybe it's only in your email messages:
> 
>      class simpleConstructer {
> 
>        function __construct() {
>          echo "running the constructor";
>        }
>      }
>      $test = new simpleConstructor();
> 
> The class is misspelled; it should be simpleConstructor. As a side note,
> it's common convention to name classes with a leading capital letter, e.g.
> SimpleConstructor. That's just convention, though, and I'm sure it differs
> in some languages. Even in PHP stdClass doesn't, but most other classes do.

Thank you David, the typo was in my code. :-/

As for the class names, I agree with you. I've read so many books where
things are changed up that I can't remember which way to do it. In this
case since I was playing around for learning purposes, I just guessed
and run with it.

I appreciate the heads up :-)


-- 
Blessings
David M.


--- End Message ---
--- Begin Message ---
The "constructor" is the __construct() method, and it gets executed
automatically when you instantiate the class into an object. The class
defines the state (fields/properties) and behavior (methods/functions) that
its objects will have. Instantiating the class is the fancy term for
creating a new object with that state and behavior and calling the class's
constructor on it. From then on you can call other methods on the object and
access its public state.

David

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: David McGlone [mailto:[email protected]]
> Sent: Tuesday, October 19, 2010 5:32 PM
> To: [email protected]
> Subject: RE: [PHP] simple class & constructor
> 
> On Tue, 2010-10-19 at 16:53 -0700, Tommy Pham wrote:
> > > -----Original Message-----
> > > From: David McGlone [mailto:[email protected]]
> > > Sent: Tuesday, October 19, 2010 4:32 PM
> > > To: [email protected]
> > > Subject: Re: [PHP] simple class & constructor
> > >
> > > On Tue, 2010-10-19 at 17:15 -0400, Paul M Foster wrote:
> > > > On Tue, Oct 19, 2010 at 04:12:51PM -0400, David McGlone wrote:
> > > <snip>
> > > > You're trying to "instantiate the class". And the way you're doing
> > > > it here is correct. When you do this, $test becomes an object of
> > > > this class. If you had another function ("member") within the
> > > > class called "myfunction()", you could run it this way (after you
> > > > instantiate the
> > > > class):
> > > >
> > > > $test->myfunction();
> > > >
> > > > >
> > > > > Basically I want to learn how I can (if it's possible with this
> > > > > simple
> > > > > code) is display the output on a different page.
> > > > >
> > > > > I tried putting the line: $test=new simpleConstructer(); on the
> > > > > index page and including the page the class is on, but it causes
> > > > > the index page to go blank.
> > > >
> > > > You've likely got an error you're not seeing. Fix this first. If
> > > > the file your class is in is syntactically correct, and you do
> > > >
> > > > include "simpleConstructerFile.php";
> > > >
> > > > in your index.php file, it should flawlessly include the code.
> > > > Then, in your index.php, you do this:
> > > >
> > > > $test = new simpleConstructer;
> > > >
> > > > you should see the contents of the echo statement appear on the page.
> > > > So you're on the right track. You just need to find the error first.
> > >
> > >
> > > Ah ha! Thank you! Your mention of an error, was spot on. notice
> > > below I misspelled the class name but got the Object name correct.
> > >
> > > Also at first I had the setup like this because it wasn't working
> > > and I thought I was doing it wrong: (this also added to my
> > > confusion)
> > >
> > > myclass.php
> > >
> > > class simpleConstructer {
> > >
> > > function __construct() {
> > >     echo "running the constructor";
> > >    }
> > > }
> > >
> > > index.php
> > > require_once 'myclass.php';
> > > $test = new simpleConstructor();
> > >
> > > But once I fixed the error I put it all back in myclass.php like so:
> > >
> > > myclass.php
> > >
> > > class simpleConstructer {
> > >
> > > function __construct() {
> > >     echo "running the constructor";
> > >    }
> > > }
> > > $test = new simpleConstructor();
> > >
> > >
> > > Now I am wondering what you meant when you said:
> > > >>>If you had another function ("member") within the class called
> > > >>>"myfunction()", you could run it this way (after you instantiate
> > > >>>the
> > > >>> class):
> > >
> > > >>>$test->myfunction();"
> > >
> > > If you don't mind my asking, how would you take the above example
> > > and change it to what you describe above?
> > >
> >
> > class simpleConstructer {
> >
> > function __construct() {
> >      echo "running the constructor";
> >    }
> >
> > function myFunction() {
> >  echo 'this is another function/method within the class simpleConstructor';
> >   }
> > }
> >
> > $test = new simpleConstructor();
> > $test->myfunction();
> 
> Thank you Tommy.
> 
> Now it all comes together and I believe I understand now.
> 
> Does the code immediately after the __construct automatically run, but
> when adding more methods to the class, they need to be called with the
> $name->Object_name? Is my thinking correct?
> 
> --
> Blessings
> David M.
> 

I had a misspell there due to copy and paste :))  ... Anyway, when you 
instantiate the class, the __construct() is executed.  What you specified 
inside that __construct() will run automatically when instantiate (create the 
class object).  Example:

class MyClass()
{
  function __construct() {
    $this->init();
}
  function init() {
  // init your class for whatever you want to do
  }

  function executeTaskOne() {
  // to do one task
  }

  function executeTaskTwo() {
  // to do another task
}

}

There's no limit on how many methods you can have for the  class but it comes 
down to overall application design for the purpose needed.  There's also 
something called visibility too.  You might want to check [1] for indepth 
explaination and samples.

Regards,
Tommy

[1] http://www.php.net/manual/en/language.oop5.php





--- End Message ---
--- Begin Message ---
On Tue, 2010-10-19 at 17:41 -0700, David Harkness wrote:
> The "constructor" is the __construct() method, and it gets executed
> automatically when you instantiate the class into an object. The class
> defines the state (fields/properties) and behavior (methods/functions) that
> its objects will have. Instantiating the class is the fancy term for
> creating a new object with that state and behavior and calling the class's
> constructor on it. From then on you can call other methods on the object and
> access its public state.

Ye! Ha! Just as I suspected! I can now say I have a very thorough
understanding of Classes, Objects and methods. :-)

-- 
Blessings
David M.


--- End Message ---
--- Begin Message ---
[snip]
Ye! Ha! Just as I suspected! I can now say I have a very thorough
understanding of Classes, Objects and methods. :-)
[/snip]

May I suggest Head First OOP? They don't do PHP in it but it is very
valuable for learning about things like encapsulation and some other
cool words.

--- End Message ---
--- Begin Message ---
On Tue, 2010-10-19 at 20:25 -0500, Jay Blanchard wrote:
> [snip]
> Ye! Ha! Just as I suspected! I can now say I have a very thorough
> understanding of Classes, Objects and methods. :-)
> [/snip]
> 
> May I suggest Head First OOP? They don't do PHP in it but it is very
> valuable for learning about things like encapsulation and some other
> cool words.
> 

You sure can :-) I'm open to anything that I can use to make me better
at programming. I'll check it out on amazon and maybe add it to my
wishlist.

IIRC there was a discussion about PHP books a while back. I'm also gonna
see if I can dig that thread up. I was at half price books today looking
for a good book on PHP to add to my collection, because the ones I have
a quickly becoming outdated but I didn't find anything. Maybe better
luck next time.

I am reluctant to buy books off the internet, because I'm afraid when I
receive them, they aren't actually any good and they become a waste of
my money.

-- 
Blessings
David M.


--- End Message ---
--- Begin Message ---
On Tue, 2010-10-19 at 20:25 -0500, Jay Blanchard wrote:
> [snip]
> Ye! Ha! Just as I suspected! I can now say I have a very thorough
> understanding of Classes, Objects and methods. :-)
> [/snip]
> 
> May I suggest Head First OOP? They don't do PHP in it but it is very
> valuable for learning about things like encapsulation and some other
> cool words.
> 

You sure can :-) I'm open to anything that I can use to make me better
at programming. I'll check it out on amazon and maybe add it to my
wishlist.

IIRC there was a discussion about PHP books a while back. I'm also gonna
see if I can dig that thread up. I was at half price books today looking
for a good book on PHP to add to my collection, because the ones I have
a quickly becoming outdated but I didn't find anything. Maybe better
luck next time.

I am reluctant to buy books off the internet, because I'm afraid when I
receive them, they aren't actually any good and they become a waste of
my money.

-- 
Blessings
David M.



--- End Message ---
--- Begin Message ---
Don

If you are looking for current quarter you can do this.

$tm = date('Y-m-d H:i:s');
$Current_Fiscal_Quarter = ceil(date("m", $tm)/3);
This will return the quarter you are currently in.
Exmaple 1, 2, 3,or 4 

I have a great quarterly dates function posted on php.net
http://www.php.net/manual/en/function.date.php#100390











-----Original Message-----
From: Don Wieland [mailto:[email protected]] 
Sent: Tuesday, October 19, 2010 7:12 PM
To: [email protected]
Subject: [PHP] Fiscal Years and Quarters

Hello,

I have a preference field called "Fiscal_Year_Start_Month" which has  
the Month Names as options.

Based on this value, I need to calculate the following date in UNIX:

Current_1st_Quarter_Start_Date
Current_1st_Quarter_End_Date
Current_2nd_Quarter_Start_Date
Current_2nd_Quarter_End_Date
Current_3rd_Quarter_Start_Date
Current_3rd_Quarter_End_Date
Current_4th_Quarter_Start_Date
Current_4th_Quarter_End_Date

Last_1st_Quarter_Start_Date
Last_1st_Quarter_End_Date
Last_2nd_Quarter_Start_Date
Last_2nd_Quarter_End_Date
Last_3rd_Quarter_Start_Date
Last_3rd_Quarter_End_Date
Last_4th_Quarter_Start_Date
Last_4th_Quarter_End_Date

Next_1st_Quarter_Start_Date
Next_1st_Quarter_End_Date
Next_2nd_Quarter_Start_Date
Next_2nd_Quarter_End_Date
Next_3rd_Quarter_Start_Date
Next_3rd_Quarter_End_Date
Next_4th_Quarter_Start_Date
Next_4th_Quarter_End_Date

Then based on TODAY'S date

Current_Fiscal_Quarter - result will be 1, 2, 3,or 4



Don

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


--- End Message ---
--- Begin Message ---
Is there any way to get rid of, whatever wet behind the ears person whom has
this spam return for every post.

[email protected]

I get 3 and 4 of these for every reply, I am sure anyone who is posting to
the list gets the same emails.






-----Original Message-----
From: Don Wieland [mailto:[email protected]] 
Sent: Tuesday, October 19, 2010 7:12 PM
To: [email protected]
Subject: [PHP] Fiscal Years and Quarters

Hello,

I have a preference field called "Fiscal_Year_Start_Month" which has  
the Month Names as options.

Based on this value, I need to calculate the following date in UNIX:

Current_1st_Quarter_Start_Date
Current_1st_Quarter_End_Date
Current_2nd_Quarter_Start_Date
Current_2nd_Quarter_End_Date
Current_3rd_Quarter_Start_Date
Current_3rd_Quarter_End_Date
Current_4th_Quarter_Start_Date
Current_4th_Quarter_End_Date

Last_1st_Quarter_Start_Date
Last_1st_Quarter_End_Date
Last_2nd_Quarter_Start_Date
Last_2nd_Quarter_End_Date
Last_3rd_Quarter_Start_Date
Last_3rd_Quarter_End_Date
Last_4th_Quarter_Start_Date
Last_4th_Quarter_End_Date

Next_1st_Quarter_Start_Date
Next_1st_Quarter_End_Date
Next_2nd_Quarter_Start_Date
Next_2nd_Quarter_End_Date
Next_3rd_Quarter_Start_Date
Next_3rd_Quarter_End_Date
Next_4th_Quarter_Start_Date
Next_4th_Quarter_End_Date

Then based on TODAY'S date

Current_Fiscal_Quarter - result will be 1, 2, 3,or 4



Don

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


--- End Message ---
--- Begin Message ---
I've got a script which originally contained the following piece of
code:

foreach ( $objs as $obj ) {
   do_some_stuff($obj);
}

When I tested it, I found that on every iteration of the loop the last
element of $objs was assigned the value of the current element. I was
able to step through the loop and watch this happening, element by
element.

I originally encountered this problem using PHP v5.2.4 under Windows
XP. I later reproduced it in v5.3.2 under XP.

The function call wasn't doing it. I replaced the function call with
an echo statement and got the same result.

For my immediate needs, I evaded the problem by changing the foreach
loop to a for loop that references elements of $objs by subscript.

That leaves me with the question: what is going wrong with foreach?
I'm trying to either demonstrate that it's my error, not the PHP
engine's, or isolate the problem in a small script that I can submit
with a bug report. The current script isn't suitable for that because
it builds $objs by reading a database table and doing some rather
elaborate manipulations of the data.

I tried to eliminate the database by doing a var_export of the array
after I built it, then assigning the exported expression to a variable
immediately before the foreach. That "broke the bug" -- the loop
behaved correctly.

There's a report of a bug that looks similar in the comments section
of php.net's manual page for foreach, time stamped 09-Jul-2009 11:50.
As far as I can tell it was never submitted as a bug and was never
resolved. I sent an inquiry to the author but he didn't respond.

Can anyone make suggestions on this -- either insights into what's
wrong, or suggestions for producing a portable, reproducible example?

--- End Message ---
--- Begin Message ---
 On 20/10/2010 05:47, Jonathan Sachs wrote:
I've got a script which originally contained the following piece of
code:

foreach ( $objs as $obj ) {
    do_some_stuff($obj);
}

When I tested it, I found that on every iteration of the loop the last
element of $objs was assigned the value of the current element. I was
able to step through the loop and watch this happening, element by
element.

Are you are using a 'referencing' foreach? i.e.

foreach ($objs as &$obj) {
do_some_stuff($obj);
}

or is the above code a direct lift from your script?

Referencing foreach statements can cause problems as the reference to the last array entry is persistent after the foreach loop has terminated so any further foreach statements on the same array will overwrite the previous reference which is still pointing to the last item.

Rich


--- End Message ---
--- Begin Message ---
Jonathan Sachs wrote:
> I've got a script which originally contained the following piece of
> code:
>
> foreach ( $objs as $obj ) {
>    do_some_stuff($obj);
> }
>
> When I tested it, I found that on every iteration of the loop the last
> element of $objs was assigned the value of the current element.

I only had a few minutes to look at it, but here is my 2 Euro cents.

It only occurs when you have previously done
,----
| foreach ( $objs as &$obj ) {
|    //anything or nothing here
| }
`----
as described in the documentation.

> That leaves me with the question: what is going wrong with foreach?
> I'm trying to either demonstrate that it's my error, not the PHP
> engine's, or isolate the problem in a small script that I can submit
> with a bug report.

>From the post you reference in the manual's comments:
    $a = array('a', 'b','c');
    foreach($a as &$row){
        //you don't have to do anything here
    }
    print_r($a);
    foreach($a as $row){
        echo "<br />".$row;
    }
    print_r($a);

This suffices.

> I tried to eliminate the database by doing a var_export of the array
> after I built it, then assigning the exported expression to a variable
> immediately before the foreach. That "broke the bug" -- the loop
> behaved correctly.

Yup. I guess whatever database code used previously was doing the
equivalent of the first foreach in the previous code snippet.

> Can anyone make suggestions on this -- either insights into what's
> wrong, or suggestions for producing a portable, reproducible example?

Better. I can tell you how to solve it:
    $a = array('a', 'b','c');
    foreach($a as &$row){
        //you don't have to do anything here
    }
    unset($row); // <----<<< THIS IS KEY!
    print_r($a);
    foreach($a as $row){
        echo "<br />".$row;
    }
    print_r($a);

I admit though, it's not obvious, even from reading the manual, and is
definitely a bug in the sense it is unexpected behaviour. Documenting it
and calling it a "feature" is appalling.


--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Gary [mailto:[email protected]]
> Sent: Tuesday, October 19, 2010 11:38 PM
> To: [email protected]
> Subject: [PHP] Re: Possible foreach bug; seeking advice to isolate the
> problem
> 
> Jonathan Sachs wrote:
> > I've got a script which originally contained the following piece of
> > code:
> >
> > foreach ( $objs as $obj ) {
> >    do_some_stuff($obj);
> > }
> >
> > When I tested it, I found that on every iteration of the loop the last
> > element of $objs was assigned the value of the current element.
> 
> I only had a few minutes to look at it, but here is my 2 Euro cents.
> 
> It only occurs when you have previously done
> ,----
> | foreach ( $objs as &$obj ) {
> |    //anything or nothing here
> | }
> `----
> as described in the documentation.
> 
> > That leaves me with the question: what is going wrong with foreach?
> > I'm trying to either demonstrate that it's my error, not the PHP
> > engine's, or isolate the problem in a small script that I can submit
> > with a bug report.
> 
> From the post you reference in the manual's comments:
>     $a = array('a', 'b','c');
>     foreach($a as &$row){
>         //you don't have to do anything here
>     }
>     print_r($a);
>     foreach($a as $row){
>         echo "<br />".$row;
>     }
>     print_r($a);
> 
> This suffices.
> 
> > I tried to eliminate the database by doing a var_export of the array
> > after I built it, then assigning the exported expression to a variable
> > immediately before the foreach. That "broke the bug" -- the loop
> > behaved correctly.
> 
> Yup. I guess whatever database code used previously was doing the
> equivalent of the first foreach in the previous code snippet.
> 
> > Can anyone make suggestions on this -- either insights into what's
> > wrong, or suggestions for producing a portable, reproducible example?
> 
> Better. I can tell you how to solve it:
>     $a = array('a', 'b','c');
>     foreach($a as &$row){
>         //you don't have to do anything here
>     }
>     unset($row); // <----<<< THIS IS KEY!

Shouldn't that be $row = null since unset will remove the last value, not
just removing the variable also, from the array whereas the $row = null will
tell the reference pointer that it doesn't point to a value.

>     print_r($a);
>     foreach($a as $row){
>         echo "<br />".$row;
>     }
>     print_r($a);
> 
> I admit though, it's not obvious, even from reading the manual, and is
> definitely a bug in the sense it is unexpected behaviour. Documenting it
> and calling it a "feature" is appalling.
> 

Regards,
Tommy


--- End Message ---
--- Begin Message ---
 Hello again,

Just to say that I have tested the script on php.net manual that generates a cert and then trys to connect (slightly modified the end of file [removing the while(true) section to just test the connection]) and I get exactly the same error.

Source : http://php.net/manual/en/function.stream-socket-server.php

Here is the full test script :
<?php
// Hello World! SSL HTTP Server.
// Tested on PHP 5.1.2-1+b1 (cli) (built: Mar 20 2006 04:17:24)

// Certificate data:
$dn = array(
"countryName" => "UK",
"stateOrProvinceName" => "Somerset",
"localityName" => "Glastonbury",
"organizationName" => "The Brain Room Limited",
"organizationalUnitName" => "PHP Documentation Team",
"commonName" => "Wez Furlong",
"emailAddress" => "[email protected]"
);

// Generate certificate
$privkey = openssl_pkey_new();
$cert = openssl_csr_new($dn, $privkey);
$cert = openssl_csr_sign($cert, null, $privkey, 365);

// Generate PEM file
# Optionally change the passphrase from 'comet' to whatever you want, or leave it empty for no passphrase
$pem_passphrase = 'comet';
$pem = array();
openssl_x509_export($cert, $pem[0]);
openssl_pkey_export($privkey, $pem[1], $pem_passphrase);
$pem = implode($pem);

// Save PEM file
$pemfile = './server.pem';
file_put_contents($pemfile, $pem);

$context = stream_context_create();

// local_cert must be in PEM format
stream_context_set_option($context, 'ssl', 'local_cert', $pemfile);
// Pass Phrase (password) of private key
stream_context_set_option($context, 'ssl', 'passphrase', $pem_passphrase);

stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
stream_context_set_option($context, 'ssl', 'verify_peer', false);

// Create the server socket
$server = stream_socket_client('ssl://test.server.com:978', $errno, $errstr,30, STREAM_CLIENT_CONNECT, $context);

if($server)
{
print('ok');
}
?>

I still get the error :
Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca in /home/richard/test.php on line 44
I think this proves that it's not my certificate at fault but maybe a problem with OpenSSL…

What do you think ?

Thank you,

Richard

Le 19/10/10 20:46, Richard a écrit :
No I didn't have a passphrase on the local cert when I created it.

I noticed that I only sent it to you and then sent the same message to the list.

Thank you,

Richard

Le 19/10/10 20:28, Tommy Pham a écrit :
-----Original Message-----
From: Richard [mailto:[email protected]]
Sent: Tuesday, October 19, 2010 11:22 AM
To: Tommy Pham
Subject: Re: [PHP] PHP stream_socket_client OpenSSL error (unknown ca)

I left the pasphrase blank, I've just tried with a blank passphrase but
it
doesn't help.

<?php
$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'local_cert',
'./afnic.pem');
stream_context_set_option($context, 'ssl', 'passphrase', '');
stream_context_set_option($context, 'ssl', 'allow_self_signed',
TRUE);
stream_context_set_option($context, 'ssl', 'verify_peer', FALSE);

$connexion = stream_socket_client('ssl://epp.test.nic.fr:700',
$errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if($connexion) {
print('succes');
}
?>

What I meant was that did you have a passphrase on your actual local cert
when you created it?

PS: Please cc the list also so others would know what's going and can help
troubleshoot and not reiterate what've been tried already.

Le 19/10/10 20:16, Tommy Pham wrote :
-----Original Message-----
From: Richard [mailto:[email protected]]
Sent: Tuesday, October 19, 2010 10:50 AM
To: [email protected]
Subject: [PHP] PHP stream_socket_client OpenSSL error (unknown ca)

Hello,

I'm having some problems connecting to a server using the following php
script :

<?php
$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'local_cert',
'./cert.pem');
stream_context_set_option($context, 'ssl', 'allow_self_signed',
TRUE);
stream_context_set_option($context, 'ssl', 'verify_peer', FALSE);

$ctn = stream_socket_client('ssl://distant.server.com:987',
$errno,
$errstr,
30, STREAM_CLIENT_CONNECT, $context);
if($ctn) {
print('Connected !');
}
?>
Just curious,

'passphrase string

Passphrase with which your local_cert file was encoded' quoted from
[1].
Regards,
Tommy

[1] http://us3.php.net/manual/en/context.ssl.php


cert.pem is a self signed certificate that I generated a few days ago,
it
contains both RSA Key and Certificate and I have supplied the
certificate
to
the distant server.

When I launch the script I get the following errors :

Warning: stream_socket_client(): SSL operation failed with code 1.
OpenSSL Error messages:
error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca in
/path/to/my/test.php on line 7

As it is a self signed certificate there is no CA so I added the two
lines
:
stream_context_set_option($context, 'ssl', 'allow_self_signed',
TRUE);
stream_context_set_option($context, 'ssl', 'verify_peer', FALSE);

but that did not fix the problem.

This is my first script that connects through a socket using SSL, but I
think
that it doesn't even get out of the server because it doesn't like the certificate. Do you have any ideas about how I could get this working ?
or
maybe just point me in the right direction. If you need any more info
please
let me know.

Thank you,

Richard








--- End Message ---
--- Begin Message ---
Hi all,

I'm stuck with this problem: I am trying to convert a text with any kind of unicode characters to its octet and entity equivalents.

For example:
Ë is &#203; as octet and &Euml; as entity
Đ is &#272; as octet and &Dstrok; as entity

My code works fine for some characters ( Ë works fine, but Đ fails at entity encoding). Do you have a hint, how to solve this?

I try to get the octet encoding with mb_encode_numericentity which works fine for everything

$convmap = array(
0x22, 0x22, 0, 0xffff, # "
0x26, 0x27, 0, 0xffff, # &'
0x3c, 0x3c, 0, 0xffff, # <
0x3d, 0x3d, 0, 0xffff, # >
0x80, 0xffff, 0, 0xffff,
);
$oct_string = mb_encode_numericentity($test, $convmap, 'UTF-8');

I try to get all entity encodings with htmlentities

$entity_string = htmlentities($test, ENT_QUOTES, 'UTF-8');

But that fails for some characters like Đ. Is there a better way to get all entity encodings?

Thanks,
Sebastian

--- End Message ---
--- Begin Message ---
Hi,

I've been wondering if there was any php project focusing on providing
a neat php error handler ?
Up to now, I've been coding mine but I've seen videos on the web where
a guy was using a really impressive php error_handler. Of course I
could code it but if there was something generic I could use in
different projets,that could be useful.

Thx for any tip

matt

--- End Message ---
--- Begin Message ---
On 19 October 2010 14:59, Don Wieland <[email protected]> wrote:
> Hi gang,
>
> I need a bailout.
>
> I have a fields called "sys_first_day_of_week" and the user can select one
> value which will be from a menu with these options:
>
> Monday
> Tuesday
> Wednesday
> Thursday
> Friday
> Saturday
> Sunday
>
> Based on this "Preference" and TODAYS DATE, I want to calculate the first
> day of the week.
>
> So if my preference is "Monday" and Today's date is 10/19/2010, I want to
> return a value of: 1287374400 (which is 10/18/2010)
>
> if my preference is "Wednesday" and Today's date is 10/19/2010, I want to
> return a value of: 1286942400 (which is 10/13/2010)
>
> Appreciate any help.
>
> Don Wieland
> D W   D a t a   C o n c e p t s
> ~~~~~~~~~~~~~~~~~~~~~~~~~
> [email protected]
> Direct Line - (949) 336-4828
>
> Integrated data solutions to fit your business needs.
>
> Need assistance in dialing in your FileMaker solution? Check out our
> Developer Support Plan at:
> http://www.dwdataconcepts.com/DevSup.html
>
> Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9 or
> higher
> http://www.appointment10.com
>
> For a quick overview -
> http://www.appointment10.com/Appt10_Promo/Overview.html
>
>

<?php
echo date('r', strtotime('-1 week', strtotime('next sunday')));" //
Sun, 17 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next monday')));" //
Mon, 18 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next tuesday')));" //
Tue, 19 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next wednesday')));" //
Wed, 20 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next thursday')));" //
Thu, 14 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next friday')));" //
Fri, 15 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next saturday')));" //
Sat, 16 Oct 2010 00:00:00 +0100
?>

Take 1 week off the next day that they want. If today is the start of
the week, then today will be returned.



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

--- End Message ---

Reply via email to