php-general Digest 19 Oct 2010 12:00:35 -0000 Issue 6995
php-general Digest 19 Oct 2010 12:00:35 - Issue 6995 Topics (messages 308810 through 308824): Re: work online 308810 by: Enrico Weigelt Re: Formatting an ECHO statement. 308811 by: admin.buskirkgraphics.com 308814 by: Cris S 308815 by: Cris S 308819 by: Paul M Foster 308820 by: Shreyas Agasthya 308821 by: a...@ashleysheridan.co.uk Re: [PDO] Re: [PHP] PDO working via Apache but not at the command line? 308812 by: Wez Furlong 308813 by: Scott Baker 308818 by: Stanley Sufficool require_once 308816 by: jim 308817 by: æ æ°å®¸ Re: Questions from a Newbie 308822 by: Ethan Rosenberg Re: mytr...@mail.us auto responder 308823 by: Gary Sessions only work in SSL 308824 by: Daniel Houle 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 -- ---BeginMessage--- * Jordan Jovanov jovanovj...@gmail.com wrote: Hi, Does somebody know company for PHP programing where people can work from home? Actual I only want to know does have regular or part time job for PHP developers who work from home via internet. I'm not just php programmer (more software architect and systems integrator). Pure sw-development projects are mostly remote, integration often onsite. cu -- -- Enrico Weigelt, metux IT service -- http://www.metux.de/ phone: +49 36207 519931 email: weig...@metux.de mobile: +49 151 27565287 icq: 210169427 skype: nekrad666 -- Embedded-Linux / Portierung / Opensource-QM / Verteilte Systeme -- ---End Message--- ---BeginMessage--- I ask as you look at the comments and replies to your post, you think long term. Today you want the italic option, tomorrow you want to change the display to something else. Now you have to go back and change ever place you set the italic symbols to make your change. BUT if you use styles you can not only change the display to the desired look in one location but you can have flexibility. Example: Let's say the comments are coming from a database and you want to display the comment differently based on the contents of the comment. In my example I have 3 different classes in the style. Now as I foreach over the fake data array example, I simply pick the style to use based on each matching criteria. While the static examples style #wever_comment{font-style:italic} #good_comment{font-style:italic; color: green;} #bad_comment{font-weight:bold; color: red;} /style $variable_from_database = array('good','bad','whatever'); Foreach($variable as $key) { Echo 'Other Comments:'; If(preg_match(/bad/i,'$key')){Echo 'div class=bad_comment$key/div';} If(preg_match(/good/i,'$key')){Echo 'div class=good_comment$key/div';} If(preg_match(/whatever/i,'$key')){Echo 'div class=wever_comment$key/div';} Echo 'br/'; } In the long term the flexibility allows you to make faster changes with a higher degree, of what I like to call smarter code. Yes the filters are static, and I would not use static filters personally. It is meant as an explanation, not a how to. -Original Message- From: Shreyas Agasthya [mailto:shreya...@gmail.com] Sent: Monday, October 18, 2010 6:10 AM To: PHP General List Subject: [PHP] Formatting an ECHO statement. Team, A bit of silly one but like my book says, there are no dumb questions, I am asking it here. If I have : $other=Whatever; and I do: echo 'Other Comments:' .$other. 'br/ works perfectly well and prints the value. What if I want to, now, italicize the value of $other with the above syntax? How do I achieve it? I know we can do it this way : echo I am i$other/i; but I want to learn how to do it with the above syntax like I mentioned earlier. Regards, Shreyas Agasthya ---End Message--- ---BeginMessage--- At 13:03 18 10 10, a...@ashleysheridan.co.uk wrote: There's nothing wrong with using em as it indicates emphasised text, which is semantic. Use span tags with classes only when the content you're styling has no semantic alternative. strongimportant message/strong is much better for machines (including search engines, screen readers, etc) to infer a meaning for than span class=bold_textimportant message/span Thanks, Ash http://www.ashleysheridan.co.uk - Reply message - From: tedd tedd.sperl...@gmail.com Date: Mon, Oct 18, 2010 17:51 Subject: [PHP] Formatting an ECHO statement. To: php-gene...@lists.php.net At 9:47 AM -0400 10/18/10, Steve Staples wrote: or
Re: [PHP] Formatting an ECHO statement.
Thanks for that detailed mail, Admin. The i was an example and I wanted to understand how does one go about the whole formatting. Nonetheless, I am pretty well informed after this thread. Thanks once again, everyone. Regards, Shreyas On Tue, Oct 19, 2010 at 10:09 AM, Paul M Foster pa...@quillandmouse.comwrote: On Mon, Oct 18, 2010 at 10:46:41PM -0400, Cris S wrote: At 15:12 18 10 10, Shreyas Agasthya wrote: Thanks all for their input. Some of the learnings from the thread : 1. i tag is getting deprecated. Not in HTML5. 2. Use em and strong Both? Read that shit again, buckwheat. And by that shit I do mean the standards, not what Joe Bloe told you. 3. Have CSS used to do the kind of stuff I was trying. Uhm, yeah. @@ I must inform, this was already in place. Then why the fuck are we discussing this? 4. Keep an eye on the SE monster. and on the go fuck yourself monster too. Holy fuck, I've been lurking for months. I turn away for one day and this is the non-PHP crap that happens? Please go back to lurking. We'd all appreciate it, and you'll be happier. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shreyas Agasthya
Re: [PHP] Formatting an ECHO statement.
Steady on now, this thread started as a php question, and has only deviated a little. Most people on the list don't work purely with php, and I for one dont mind the odd off-topic thread, especially when the majority of the list is made of good php threads. Thanks, Ash http://www.ashleysheridan.co.uk - Reply message - From: Cris S ssski...@gmail.com Date: Tue, Oct 19, 2010 03:46 Subject: [PHP] Formatting an ECHO statement. To: php-general@lists.php.net At 15:12 18 10 10, Shreyas Agasthya wrote: Thanks all for their input. Some of the learnings from the thread : 1. i tag is getting deprecated. Not in HTML5. 2. Use em and strong Both? Read that shit again, buckwheat. And by that shit I do mean the standards, not what Joe Bloe told you. 3. Have CSS used to do the kind of stuff I was trying. Uhm, yeah. @@ I must inform, this was already in place. Then why the fuck are we discussing this? 4. Keep an eye on the SE monster. and on the go fuck yourself monster too. Holy fuck, I've been lurking for months. I turn away for one day and this is the non-PHP crap that happens? Someone needs to hire me now, to keep me busy and stop me from taking this issue apart one piece at a time. Kee-rist. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions from a Newbie
Tamara - Thanks. No error_log. This works ... htmlbody ?php phpinfo(); ? /body/html Ethan ++ At 02:23 AM 10/19/2010, Tamara Temple wrote: On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote: I've added the code you suggest, and I still get a blank screen. Should I be explicitly be using mysqli functions; eg mysqli_connect? Odd you should still get a blank screen and nothing in the error_log... Does phpinfo() work? Ethan At 11:00 PM 10/18/2010, you wrote: Where do you set $host, $user and $password? You should add the following after the new mysqli statement: if ($mysqli-connect_error) { die('Connect Error (' . $mysqli-connect_errno . ') ' . $mysqli-connect_error); } Tamara Temple -- aka tamouse__ mailto:tam...@tamaratemple.comtam...@tamaratemple.com May you never see a stranger's face in the mirror. On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote: At 05:37 PM 10/17/2010, Tamara Temple wrote: gah, i botched that up. For the first part, you want the following: $cxn = new mysql($host, $user, $password); $res = $cxn-query(create database test22:); if (!$res) { die(Failed to create database test22: . $cxn- error()); } Then, reopen the connection with the new data base: $cxn = new mysql($host, $user, $password, test22); Then the following code will work. Tamara Temple -- aka tamouse__ mailto:tam...@tamaratemple.comtam...@tamaratemple.com May you never see a stranger's face in the mirror. On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote: On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote: At 01:41 AM 10/17/2010, Tommy Pham wrote: I cannot get the following to work. In my Firefox [Iceweasel] browser, I enter the following URL: [w/ the http] Whenever you get a blank screen running a php application, the place to look is the http server's error_log. This is frequently found in / var/log/httpd/error_log or /var/log/apache2/error_log. (If your system is hosted someplace else, it could very easily be in a different place). Typically you need root permission to read this file. Tail the file after you run your PHP script to see the most recent errors. The code contained in the file CreateNew.php is: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); Better to use the OO approach: $cxn = new mysqli($host, $user, $password); echoCreate database test22; Instead of echo statements (which would just echo the contents to the output, i.e., your browser, you want to assign them to a variable, such as: $sql = create database test22; use test22; Then you need to execute the sql statement: $res = $cxn-query($sql); if (!$res) { die(Could not create database test22: . $cxn- error()); } echoCreate table Names2 $sql = create table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); ; // to close off the php statement $res = $cxn-query($sql); if (!$res) { die(Could not create table Names2: . $cxn- error()); } echo Create table Visit2 $sql = create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); ; // again, to close off the php statement $res = $cxn-query($sql); if (!$res) { die(Could not create table Visit2: . $cxn- error()); } $sql= SHOW DATABASES; This doesn't work in a programmatic setting. Terminate the database connection: $cxn-close(); ? /body/html I would also like to be able to add data to a table, using PHP, which I can do in MySQL as: load data infile '/home/ethan/Databases/tester21.dat.' replace into table Names fields escaped by '\\' terminated by '\t' lines terminated by '\n' ; That's a specific feature of the mysql program. You'd have to write something in php to be able to parse the file and insert the data. There are examples all over the net. Then you would need to set up sql insert or replace statements to actually get the data into the data base using mysqli::query. There are numerous examples of this as well. Here's one example: ?php $host = localhost; $user = root; $pwd = rootpassword; $db = test22; $table = table_to_insert_into; $cxn = new mysql($host, $user, $pwd, $db); $filename = tab-delimited.txt; $contents = file($filename); // returns the contents of the file into an array, one line of file per array $columns = explode(\t, $contents[0]); // get the column names from the first line
[PHP] Sessions only work in SSL
I have a strange issue here. I am running a CentOS machine, with apache 2.2.3 php 5.1.6 kernel 2.6.18-194.8.1.el5xen My sessions will work using https, but not using simple http. I've compared my configs with another identical machine which works with both, and I can't figure out why. Anyone got an idea? Here's the simple script I run to test. ?php session_start(); echo 'session started'; if (isset($_SESSION['name'])) { echo 'br /' . $_SESSION['name']; session_destroy(); } else { echo 'br /No session found'; $_SESSION['name'] = 'My session'; } phpinfo(); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Questions from a Newbie
-Original Message- From: Ethan Rosenberg [mailto:eth...@earthlink.net] Sent: Tuesday, October 19, 2010 12:05 AM To: php-general@lists.php.net Subject: Re: [PHP] Questions from a Newbie Tamara - Thanks. No error_log. The error log only exists if he configures it properly and the script has error. IE: log_errors error_log. Like I said, Ethan should start from the beginning of the manual. It covers the configuration of PHP in addition to the fundamentals of PHP. This works ... htmlbody ?php phpinfo(); ? /body/html Ethan ++ At 02:23 AM 10/19/2010, Tamara Temple wrote: On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote: I've added the code you suggest, and I still get a blank screen. Should I be explicitly be using mysqli functions; eg mysqli_connect? Odd you should still get a blank screen and nothing in the error_log... Does phpinfo() work? Ethan At 11:00 PM 10/18/2010, you wrote: Where do you set $host, $user and $password? You should add the following after the new mysqli statement: if ($mysqli-connect_error) { die('Connect Error (' . $mysqli-connect_errno . ') ' . $mysqli-connect_error); } Tamara Temple -- aka tamouse__ mailto:tam...@tamaratemple.comtam...@tamaratemple.com May you never see a stranger's face in the mirror. On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote: At 05:37 PM 10/17/2010, Tamara Temple wrote: gah, i botched that up. For the first part, you want the following: $cxn = new mysql($host, $user, $password); $res = $cxn-query(create database test22:); if (!$res) { die(Failed to create database test22: . $cxn- error()); } Then, reopen the connection with the new data base: $cxn = new mysql($host, $user, $password, test22); Then the following code will work. Tamara Temple -- aka tamouse__ mailto:tam...@tamaratemple.comtam...@tamaratemple.com May you never see a stranger's face in the mirror. On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote: On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote: At 01:41 AM 10/17/2010, Tommy Pham wrote: I cannot get the following to work. In my Firefox [Iceweasel] browser, I enter the following URL: [w/ the http] Whenever you get a blank screen running a php application, the place to look is the http server's error_log. This is frequently found in / var/log/httpd/error_log or /var/log/apache2/error_log. (If your system is hosted someplace else, it could very easily be in a different place). Typically you need root permission to read this file. Tail the file after you run your PHP script to see the most recent errors. The code contained in the file CreateNew.php is: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); Better to use the OO approach: $cxn = new mysqli($host, $user, $password); echoCreate database test22; Instead of echo statements (which would just echo the contents to the output, i.e., your browser, you want to assign them to a variable, such as: $sql = create database test22; use test22; Then you need to execute the sql statement: $res = $cxn-query($sql); if (!$res) { die(Could not create database test22: . $cxn- error()); } echoCreate table Names2 $sql = create table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); ; // to close off the php statement $res = $cxn-query($sql); if (!$res) { die(Could not create table Names2: . $cxn- error()); } echo Create table Visit2 $sql = create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); ; // again, to close off the php statement $res = $cxn-query($sql); if (!$res) { die(Could not create table Visit2: . $cxn- error()); } $sql= SHOW DATABASES; This doesn't work in a programmatic setting. Terminate the database connection: $cxn-close(); ? /body/html I would also like to be able to add data to a table, using PHP, which I can do in MySQL as: load data infile '/home/ethan/Databases/tester21.dat.' replace into table Names fields escaped by '\\' terminated by '\t' lines terminated by '\n' ; That's a specific feature of the mysql program. You'd have to write something in php to be able to parse the file and insert the
[PHP] Execute a php page and don't wait for it to finish
Hi List, I have a php page that updates data from one database to another when it is run. My query is, how can I trigger the execution of this update page from another php / javascript without the calling page having to wait for the update page to finish? Basically, I think the update page needs to use: ignore_user_abort(1); set_time_limit(0); // I don't think the script will take more than 1 min. At the other end I found this: 1) http://www.mindraven.com/blog/php/run-a-php-script-in-the-background-using-ajax/ 2) On that page a user suggested using *pclose(popen(‘/usr/bin/php /path/to/something.php /dev/null ’, ‘r’)* **However, I need this to be usable on windows servers also. 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for me? Which of the above 3 options is the better one? Other suggestions are welcome :) Thanks and Regards, Ferdi
Re: [PHP] Execute a php page and don't wait for it to finish
On Tue, 2010-10-19 at 18:50 +0530, Ferdi wrote: Hi List, I have a php page that updates data from one database to another when it is run. My query is, how can I trigger the execution of this update page from another php / javascript without the calling page having to wait for the update page to finish? Basically, I think the update page needs to use: ignore_user_abort(1); set_time_limit(0); // I don't think the script will take more than 1 min. At the other end I found this: 1) http://www.mindraven.com/blog/php/run-a-php-script-in-the-background-using-ajax/ 2) On that page a user suggested using *pclose(popen(‘/usr/bin/php /path/to/something.php /dev/null ’, ‘r’)* **However, I need this to be usable on windows servers also. 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for me? Which of the above 3 options is the better one? Other suggestions are welcome :) Thanks and Regards, Ferdi Ferdi: check out: http://us3.php.net/manual/en/function.ignore-user-abort.php I am looking to change a script/app that i have to use this (as the script takes a few seconds to finish, and there are people hitting the back button, or soemthign else that is screwing the submission. I haven't implemented it (life has been busy) yet, but it seems to be what I was looking for, which may be what you're looking for... Steve. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute a php page and don't wait for it to finish
What about simply having the script trip a flag that another background script checks every 60 seconds or so? Once a minutes a background script checks to see if it needs to preform any tasks. When a user hits a certain page it does an ajax request to trip this flag and immediately returns. The next time the background script checks if it needs to do anything, it sees the tripped flag and preforms the relevant database copy - or whatever :-) Chris. On Tue, Oct 19, 2010 at 9:20 AM, Ferdi ferdinan...@printo.in wrote: Hi List, I have a php page that updates data from one database to another when it is run. My query is, how can I trigger the execution of this update page from another php / javascript without the calling page having to wait for the update page to finish? Basically, I think the update page needs to use: ignore_user_abort(1); set_time_limit(0); // I don't think the script will take more than 1 min. At the other end I found this: 1) http://www.mindraven.com/blog/php/run-a-php-script-in-the-background-using-ajax/ 2) On that page a user suggested using *pclose(popen(‘/usr/bin/php /path/to/something.php /dev/null ’, ‘r’)* **However, I need this to be usable on windows servers also. 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for me? Which of the above 3 options is the better one? Other suggestions are welcome :) Thanks and Regards, Ferdi
Re: [PHP] require_once
I'm having a problem including files using Zend Framework. I have in a controller file this Jim why not use the Zend autoloader? Chris.
Re: [PHP] Sessions only work in SSL
On Mon, Oct 18, 2010 at 8:46 PM, Daniel Houle drho...@hotmail.com wrote: I have a strange issue here. I am running a CentOS machine, with apache 2.2.3 php 5.1.6 kernel 2.6.18-194.8.1.el5xen My sessions will work using https, but not using simple http. I've compared my configs with another identical machine which works with both, and I can't figure out why. Anyone got an idea? Here's the simple script I run to test. ?php session_start(); echo 'session started'; if (isset($_SESSION['name'])) { echo 'br /' . $_SESSION['name']; session_destroy(); } else { echo 'br /No session found'; $_SESSION['name'] = 'My session'; } phpinfo(); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Are you sure session.cookie_secure is not turned on somewhere? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute a php page and don't wait for it to finish
A simple AJAX script would do the trick, no? Or does the script which was triggered by JS get aborted if that page is unloaded? If javascript is unavailable you could trigger it through the img tag like so: img width='0' height='0' src=updater.php alt= / Again, not sure if it will keep running if the caller is unloaded. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute a php page and don't wait for it to finish
Ferdi schrieb: Hi List, I have a php page that updates data from one database to another when it is run. My query is, how can I trigger the execution of this update page from another php / javascript without the calling page having to wait for the update page to finish? Basically, I think the update page needs to use: ignore_user_abort(1); set_time_limit(0); // I don't think the script will take more than 1 min. At the other end I found this: 1) http://www.mindraven.com/blog/php/run-a-php-script-in-the-background-using-ajax/ 2) On that page a user suggested using *pclose(popen(‘/usr/bin/php /path/to/something.php /dev/null ’, ‘r’)* **However, I need this to be usable on windows servers also. 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for me? Which of the above 3 options is the better one? Other suggestions are welcome :) Thanks and Regards, Ferdi 1) I guess an asynchronous ajax request is what you are looking for. But it won't work on command line. 2) Maybe http://robert.accettura.com/blog/2006/09/14/asynchronous-processing-with-php/ could help you, but I never tried that. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Firs Day Of Week UNIX
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 ~ d...@dwdataconcepts.com 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
Re: [PHP] require_once
I am following an example. Also, doesn't that require the class name to be something like models_members? Jim On 10/19/2010 09:40 AM, chris h wrote: I'm having a problem including files using Zend Framework. I have in a controller file this Jim why not use the Zend autoloader? Chris.
[PHP] Firs Day Of Week UNIX
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
Re: [PHP] Firs Day Of Week UNIX
Don Wieland schrieb: 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 I'm not sure: You are searching the date of the last given weekdate? $sys_first_day_of_week: Monday = 1, ..., Saturday = 6, Sunday = 0 Try this one: date seems to be correct, but value is different, maybe different time zone? if ( date('w') $sys_first_day_of_week ) { $value = mktime(0,0,0,date('n'),date('j'),date('Y')) - ( 7 + date('w') - $sys_first_day_of_week ) * 24 * 60 * 60; } else { $value = mktime(0,0,0,date('n'),date('j'),date('Y')) - ( date('w') - $sys_first_day_of_week ) * 24 * 60 * 60; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Firs Day Of Week UNIX
On Tue, Oct 19, 2010 at 07:00:55AM -0700, Don Wieland 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. I would strongly suggest you use a date class which uses julian days internally to represent dates. This makes date calculations vastly more simple and accurate than using seconds to do the calculation. I have a date class I'll send you, if you like. Just get today's date, and today's day of the week. Then just add or subtract days to get the other dates needed. In fact, the date class I mentioned has two functions, begwk() and endwk() which allows you to return the beginning or ending of the week, based on today's date and a user-configurable end-of-week day. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] require_once
I see! Yes using an autoloader typically requires following a naming convention for your classes (though you can get around it by defining your own naming rules). I didn't care for it much at first, but it's nice that class names are explicit (less confusion when you have several) and not worrying about requiring all your files is a plus. Chris. On Tue, Oct 19, 2010 at 10:00 AM, jim jbw2...@earthlink.net wrote: I am following an example. Also, doesn't that require the class name to be something like models_members? Jim On 10/19/2010 09:40 AM, chris h wrote: I'm having a problem including files using Zend Framework. I have in a controller file this Jim why not use the Zend autoloader? Chris.
Re: [PHP] Formatting an ECHO statement.
At 12:39 AM -0400 10/19/10, Paul M Foster wrote: On Mon, Oct 18, 2010 at 10:46:41PM -0400, Cris S wrote: -snip- (of no importance) Please go back to lurking. We'd all appreciate it, and you'll be happier. Paul -- Paul M. Foster I agree with Paul on this one. Chris S has no idea of what we are talking about or what he is saying. PHP does not encompass all of web programming and part of learning PHP programming is to know where the boundaries are. Intermixing style elements and PHP is the topic of this thread. Determining what is the best practice in this aspect is what we are addressing. Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Execute a php page and don't wait for it to finish
-Original Message- From: Sebastian Detert [mailto:php-maill...@elygor.de] Sent: Tuesday, October 19, 2010 6:51 AM To: Ferdi; PHP General Subject: Re: [PHP] Execute a php page and don't wait for it to finish Ferdi schrieb: Hi List, I have a php page that updates data from one database to another when it is run. My query is, how can I trigger the execution of this update page from another php / javascript without the calling page having to wait for the update page to finish? Basically, I think the update page needs to use: ignore_user_abort(1); set_time_limit(0); // I don't think the script will take more than 1 min. At the other end I found this: 1) http://www.mindraven.com/blog/php/run-a-php-script-in-the- background-u sing-ajax/ 2) On that page a user suggested using *pclose(popen('/usr/bin/php /path/to/something.php /dev/null ', 'r')* **However, I need this to be usable on windows servers also. 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for me? Which of the above 3 options is the better one? Other suggestions are welcome :) Thanks and Regards, Ferdi 1) I guess an asynchronous ajax request is what you are looking for. But it won't work on command line. 2) Maybe http://robert.accettura.com/blog/2006/09/14/asynchronous-processing- with-php/ could help you, but I never tried that. What about having the script flags a field in the DB and have another script running as daemon either via cron or Windows Service/Scheduler and run the command based on the flag in the DB? This way, you don't have to worry about the security issues of *pclose(popen('/usr/bin/php /path/to/something.php /dev/null ', 'r')* You can also have another page that will flag the DB should the user wish to abort the command. The background script would check this abort flag so often based on your criteria and abort the corresponding command accordingly, especially if some of the command may run for extended period time. Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Firs Day Of Week UNIX
-Original Message- From: Paul M Foster [mailto:pa...@quillandmouse.com] Sent: Tuesday, October 19, 2010 7:37 AM To: php-general@lists.php.net Subject: Re: [PHP] Firs Day Of Week UNIX On Tue, Oct 19, 2010 at 07:00:55AM -0700, Don Wieland 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. I would strongly suggest you use a date class which uses julian days internally to represent dates. This makes date calculations vastly more simple and accurate than using seconds to do the calculation. I have a date class I'll send you, if you like. Just get today's date, and today's day of the week. Then just add or subtract days to get the other dates needed. In fact, the date class I mentioned has two functions, begwk() and endwk() which allows you to return the beginning or ending of the week, based on today's date and a user- configurable end-of-week day. Paul -- Paul M. Foster Date class with methods begwk() endwk()? Is that from PEAR/PECL? I don't see it in the manual. I do see getDate() [1]; ?php $today = getdate(); print_r($today); ? Array ( [seconds] = 40 [minutes] = 58 [hours] = 21 [mday]= 17 [wday]= 2 [mon] = 6 [year]= 2003 [yday]= 167 [weekday] = Tuesday [month] = June [0] = 1055901520 ) This would get you going. Regards, Tommy [1] http://us.php.net/manual/en/function.getdate.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Firs Day Of Week UNIX
On Tue, Oct 19, 2010 at 08:14:47AM -0700, Tommy Pham wrote: -Original Message- From: Paul M Foster [mailto:pa...@quillandmouse.com] Sent: Tuesday, October 19, 2010 7:37 AM To: php-general@lists.php.net Subject: Re: [PHP] Firs Day Of Week UNIX On Tue, Oct 19, 2010 at 07:00:55AM -0700, Don Wieland 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. I would strongly suggest you use a date class which uses julian days internally to represent dates. This makes date calculations vastly more simple and accurate than using seconds to do the calculation. I have a date class I'll send you, if you like. Just get today's date, and today's day of the week. Then just add or subtract days to get the other dates needed. In fact, the date class I mentioned has two functions, begwk() and endwk() which allows you to return the beginning or ending of the week, based on today's date and a user- configurable end-of-week day. Paul -- Paul M. Foster Date class with methods begwk() endwk()? Is that from PEAR/PECL? I don't see it in the manual. I do see getDate() [1]; No, it's from PMF. (I wrote it.) ;-} Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Questions from a Newbie
Dear List - The error log only exists if he configures it properly and the script has error. IE: log_errors error_log. I already had done that prior to the post. That came from the manual, the necessary section thereof which had been read. Now what? Ethan ++ At 08:31 AM 10/19/2010, Tommy Pham wrote: -Original Message- From: Ethan Rosenberg [mailto:eth...@earthlink.net] Sent: Tuesday, October 19, 2010 12:05 AM To: php-general@lists.php.net Subject: Re: [PHP] Questions from a Newbie Tamara - Thanks. No error_log. The error log only exists if he configures it properly and the script has error. IE: log_errors error_log. Like I said, Ethan should start from the beginning of the manual. It covers the configuration of PHP in addition to the fundamentals of PHP. This works ... htmlbody ?php phpinfo(); ? /body/html Ethan ++ At 02:23 AM 10/19/2010, Tamara Temple wrote: On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote: I've added the code you suggest, and I still get a blank screen. Should I be explicitly be using mysqli functions; eg mysqli_connect? Odd you should still get a blank screen and nothing in the error_log... Does phpinfo() work? Ethan At 11:00 PM 10/18/2010, you wrote: Where do you set $host, $user and $password? You should add the following after the new mysqli statement: if ($mysqli-connect_error) { die('Connect Error (' . $mysqli-connect_errno . ') ' . $mysqli-connect_error); } Tamara Temple -- aka tamouse__ mailto:tam...@tamaratemple.comtam...@tamaratemple.com May you never see a stranger's face in the mirror. On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote: At 05:37 PM 10/17/2010, Tamara Temple wrote: gah, i botched that up. For the first part, you want the following: $cxn = new mysql($host, $user, $password); $res = $cxn-query(create database test22:); if (!$res) { die(Failed to create database test22: . $cxn- error()); } Then, reopen the connection with the new data base: $cxn = new mysql($host, $user, $password, test22); Then the following code will work. Tamara Temple -- aka tamouse__ mailto:tam...@tamaratemple.comtam...@tamaratemple.com May you never see a stranger's face in the mirror. On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote: On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote: At 01:41 AM 10/17/2010, Tommy Pham wrote: I cannot get the following to work. In my Firefox [Iceweasel] browser, I enter the following URL: [w/ the http] Whenever you get a blank screen running a php application, the place to look is the http server's error_log. This is frequently found in / var/log/httpd/error_log or /var/log/apache2/error_log. (If your system is hosted someplace else, it could very easily be in a different place). Typically you need root permission to read this file. Tail the file after you run your PHP script to see the most recent errors. The code contained in the file CreateNew.php is: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); Better to use the OO approach: $cxn = new mysqli($host, $user, $password); echoCreate database test22; Instead of echo statements (which would just echo the contents to the output, i.e., your browser, you want to assign them to a variable, such as: $sql = create database test22; use test22; Then you need to execute the sql statement: $res = $cxn-query($sql); if (!$res) { die(Could not create database test22: . $cxn- error()); } echoCreate table Names2 $sql = create table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); ; // to close off the php statement $res = $cxn-query($sql); if (!$res) { die(Could not create table Names2: . $cxn- error()); } echo Create table Visit2 $sql = create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); ; // again, to close off the php statement $res = $cxn-query($sql); if (!$res) { die(Could not create table Visit2: . $cxn- error()); } $sql= SHOW DATABASES; This doesn't work in a programmatic setting. Terminate the database connection: $cxn-close(); ? /body/html I would also like to be able to add data to a table, using PHP, which I
RE: [PHP] Questions from a Newbie - Please Help
Dear List - I've checked the php.ini file [again] and cannot find any errors. I wrote a PHP script to open a non-existent data base, and receive no error. At this point, I am out of options. Let's all look at the code, and tell me 1]where the error is and 2]any corrections or additions to the ini file. For personal reasons, which I cannot explain in a public forum, I am under extreme pressure to learn PHP ASAP. Thank you. Ethan +++ At 08:31 AM 10/19/2010, Tommy Pham wrote: -Original Message- From: Ethan Rosenberg [mailto:eth...@earthlink.net] Sent: Tuesday, October 19, 2010 12:05 AM To: php-general@lists.php.net Subject: Re: [PHP] Questions from a Newbie Tamara - Thanks. No error_log. The error log only exists if he configures it properly and the script has error. IE: log_errors error_log. Like I said, Ethan should start from the beginning of the manual. It covers the configuration of PHP in addition to the fundamentals of PHP. This works ... htmlbody ?php phpinfo(); ? /body/html Ethan ++ At 02:23 AM 10/19/2010, Tamara Temple wrote: On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote: I've added the code you suggest, and I still get a blank screen. Should I be explicitly be using mysqli functions; eg mysqli_connect? Odd you should still get a blank screen and nothing in the error_log... Does phpinfo() work? Ethan At 11:00 PM 10/18/2010, you wrote: Where do you set $host, $user and $password? You should add the following after the new mysqli statement: if ($mysqli-connect_error) { die('Connect Error (' . $mysqli-connect_errno . ') ' . $mysqli-connect_error); } Tamara Temple -- aka tamouse__ mailto:tam...@tamaratemple.comtam...@tamaratemple.com May you never see a stranger's face in the mirror. On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote: At 05:37 PM 10/17/2010, Tamara Temple wrote: gah, i botched that up. For the first part, you want the following: $cxn = new mysql($host, $user, $password); $res = $cxn-query(create database test22:); if (!$res) { die(Failed to create database test22: . $cxn- error()); } Then, reopen the connection with the new data base: $cxn = new mysql($host, $user, $password, test22); Then the following code will work. Tamara Temple -- aka tamouse__ mailto:tam...@tamaratemple.comtam...@tamaratemple.com May you never see a stranger's face in the mirror. On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote: On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote: At 01:41 AM 10/17/2010, Tommy Pham wrote: I cannot get the following to work. In my Firefox [Iceweasel] browser, I enter the following URL: [w/ the http] Whenever you get a blank screen running a php application, the place to look is the http server's error_log. This is frequently found in / var/log/httpd/error_log or /var/log/apache2/error_log. (If your system is hosted someplace else, it could very easily be in a different place). Typically you need root permission to read this file. Tail the file after you run your PHP script to see the most recent errors. The code contained in the file CreateNew.php is: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); Better to use the OO approach: $cxn = new mysqli($host, $user, $password); echoCreate database test22; Instead of echo statements (which would just echo the contents to the output, i.e., your browser, you want to assign them to a variable, such as: $sql = create database test22; use test22; Then you need to execute the sql statement: $res = $cxn-query($sql); if (!$res) { die(Could not create database test22: . $cxn- error()); } echoCreate table Names2 $sql = create table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); ; // to close off the php statement $res = $cxn-query($sql); if (!$res) { die(Could not create table Names2: . $cxn- error()); } echo Create table Visit2 $sql = create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); ; // again, to close off the php statement $res = $cxn-query($sql); if (!$res) { die(Could not create table Visit2: . $cxn- error()); } $sql= SHOW DATABASES; This doesn't work in a programmatic
RE: [PHP] Questions from a Newbie
-Original Message- From: Ethan Rosenberg [mailto:eth...@earthlink.net] Sent: Tuesday, October 19, 2010 9:19 AM To: Tommy Pham; php-general@lists.php.net Subject: RE: [PHP] Questions from a Newbie Dear List - The error log only exists if he configures it properly and the script has error. IE: log_errors error_log. I already had done that prior to the post. That came from the manual, the necessary section thereof which had been read. Now what? Ethan ++ snip Here's what I perceive your scenario to be: 1) Connect to DB: success? If not, why not? Server problem? Network problem if everything is not on the same box? Firewall issue? Account privilege? 2) Send query to DB: success? If not, why not? Same questions as above... Did something happened after a successful connection? 3) What do I do with the success of the query? Check if it's as expected? Store it somewhere for later use? Display the results in html/xml? To achieve the above, you need to understand the fundamentals such as what a variable is and the types of variables. What control structures are (conditions, loops, etc.)... Did you read the all that I've mentioned? Since you've mentioned reading the MySQL/MySQLi section was too much for you to comprehend implies, to me, that you don't understand the fundamentals or didn't read the sections from the official manual that are required to begin working with PHP. Here's the code from OP: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); See point 1 for above. echoCreate database test22; See point 2. What's the difference between display it as text/html/xml and assigning it to use? If to use, you need to understand the fundamentals of SQL for the below statement, which is beyond the scope of this list. What database are you executing the below command for? You wouldn't know that unless you check the result. echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); See point 2. The below statement is the same as statement above in the process. echo Create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); See point 2. $sql= SHOW DATABASES; See point 2 3 for the above. ? /body/html Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[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 !'); } ? 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Questions from a Newbie - Please Help
thread has been trimmed to NOTHING i am pretty sure i read it on here already... but your PHP code looks wrong. ORIGNAL CODE: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); echo Create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); $sql= SHOW DATABASES; ? /body/html FIXED CODE: htmlbody ?php /* * Create Database test22 */ $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date );; echoCreate table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) );; $sql= SHOW DATABASES; ? /body/html END FIXX firstly... you are missing your ending ; AFTER the on most of your lines... and i've seen this before, where it wont throw the error. secondly, all this is doing, is echoing out lines to either the console, or the web page... it is not running the queries at all. So, if you're trying to execute this from a shell script, then the line starting with $cxn that created the connection to the database, is irrelevant. If you are trying to just run from the website, and show what you WANT to do, then you have to end your statements with the ; character. You should be able to copy and paste my FIXED code, and it should echo out something... it is helps, before you make the $cnx call, put in error_reporting(E_ALL); lastly, if you want to call the queries from php, then you will have to remove the echo, and make them function calls to the database... here is a VERY quick redo of your code to make the mysqli calls: htmlbody ?php /* * Create Database test22 */ $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; mysqli_query($cxn, Create table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date );); mysqli_query($cxn, Create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) );); $sql= SHOW DATABASES; $result = mysqli_query($cxn, $sql); echo 'pre'; print_r($result); echo '/pre'; ? /body/html GOOD LUCK! and just to note, i dont guarantee that this code will work, i am only taking what you had, and adding a little more to it, and I didn't test it out... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP stream_socket_client OpenSSL error (unknown ca)
-Original Message- From: Richard [mailto:php_l...@ghz.fr] Sent: Tuesday, October 19, 2010 10:50 AM To: php-general@lists.php.net 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Questions from a Newbie - Please Help
-Original Message- From: Steve Staples [mailto:sstap...@mnsi.net] Sent: Tuesday, October 19, 2010 11:07 AM To: Ethan Rosenberg Cc: php-general@lists.php.net Subject: RE: [PHP] Questions from a Newbie - Please Help thread has been trimmed to NOTHING i am pretty sure i read it on here already... but your PHP code looks wrong. ORIGNAL CODE: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); echo Create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); $sql= SHOW DATABASES; ? /body/html FIXED CODE: htmlbody ?php /* * Create Database test22 */ $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date );; echoCreate table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) );; $sql= SHOW DATABASES; ? /body/html END FIXX firstly... you are missing your ending ; AFTER the on most of your lines... and i've seen this before, where it wont throw the error. secondly, all this is doing, is echoing out lines to either the console, or the web page... it is not running the queries at all. So, if you're trying to execute this from a shell script, then the line starting with $cxn that created the connection to the database, is irrelevant. If you are trying to just run from the website, and show what you WANT to do, then you have to end your statements with the ; character. You should be able to copy and paste my FIXED code, and it should echo out something... it is helps, before you make the $cnx call, put in error_reporting(E_ALL); lastly, if you want to call the queries from php, then you will have to remove the echo, and make them function calls to the database... here is a VERY quick redo of your code to make the mysqli calls: htmlbody ?php /* * Create Database test22 */ $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; The 2 statements below would fail ;) mysqli_query($cxn, Create table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date );); mysqli_query($cxn, Create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) );); $sql= SHOW DATABASES; $result = mysqli_query($cxn, $sql); echo 'pre'; print_r($result); echo '/pre'; ? /body/html GOOD LUCK! and just to note, i dont guarantee that this code will work, i am only taking what you had, and adding a little more to it, and I didn't test it out... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP stream_socket_client OpenSSL error (unknown ca)
-Original Message- From: Richard [mailto:php_l...@ghz.fr] 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:php_l...@ghz.fr] Sent: Tuesday, October 19, 2010 10:50 AM To: php-general@lists.php.net 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP stream_socket_client OpenSSL error (unknown ca)
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:php_l...@ghz.fr] 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:php_l...@ghz.fr] Sent: Tuesday, October 19, 2010 10:50 AM To: php-general@lists.php.net 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Questions from a Newbie - Please Help
On Tue, 2010-10-19 at 11:18 -0700, Tommy Pham wrote: -Original Message- From: Steve Staples [mailto:sstap...@mnsi.net] Sent: Tuesday, October 19, 2010 11:07 AM To: Ethan Rosenberg Cc: php-general@lists.php.net Subject: RE: [PHP] Questions from a Newbie - Please Help thread has been trimmed to NOTHING i am pretty sure i read it on here already... but your PHP code looks wrong. ORIGNAL CODE: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); echo Create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); $sql= SHOW DATABASES; ? /body/html FIXED CODE: htmlbody ?php /* * Create Database test22 */ $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date );; echoCreate table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) );; $sql= SHOW DATABASES; ? /body/html END FIXX firstly... you are missing your ending ; AFTER the on most of your lines... and i've seen this before, where it wont throw the error. secondly, all this is doing, is echoing out lines to either the console, or the web page... it is not running the queries at all. So, if you're trying to execute this from a shell script, then the line starting with $cxn that created the connection to the database, is irrelevant. If you are trying to just run from the website, and show what you WANT to do, then you have to end your statements with the ; character. You should be able to copy and paste my FIXED code, and it should echo out something... it is helps, before you make the $cnx call, put in error_reporting(E_ALL); lastly, if you want to call the queries from php, then you will have to remove the echo, and make them function calls to the database... here is a VERY quick redo of your code to make the mysqli calls: htmlbody ?php /* * Create Database test22 */ $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; The 2 statements below would fail ;) ACUTALLY... the only reason they fail, is becuase i didn't realize that I kept the other echo above, and it didn't create the database... that should have been: mysqli_query($cxn, Create database test22); and then inside, creating the table Names2 needs to be test22.Names2 and the same for visit2. the other issue, is with the create Names2... where the primary key is default=1000 (should be default 1000), and auto_increment... can't have a default AND auto_increment. other than those, this works fine... providing he has the $user, $host, $password declared as well. I personally dont use this, i use the PEAR:MDB2 classes, so this was just a quick php.net search... WHICH would have helped the OP on this one. http://ca.php.net/manual/en/mysqli.query.php I hate to say it, since i was a noob once, but RTFM, or LRN2GOOGLE and you will find it easier, and then once you can't understand it, ask. but there was so much fail in the OP's code. sorry. I think the scary part, is that you're being forced to learn PHP to develop in, and you can't figure out a simple echo statement? Steve mysqli_query($cxn, Create table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date );); mysqli_query($cxn, Create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) );); $sql= SHOW DATABASES; $result = mysqli_query($cxn, $sql); echo 'pre'; print_r($result); echo '/pre'; ? /body/html GOOD LUCK! and just to note, i dont guarantee that this code will work, i am only taking what you had, and adding a little more to it,
Re: [PHP] Sessions only work in SSL
On 10/19/2010 09:41 AM, Andrew Ballard wrote: On Mon, Oct 18, 2010 at 8:46 PM, Daniel Houledrho...@hotmail.com wrote: I have a strange issue here. I am running a CentOS machine, with apache 2.2.3 php 5.1.6 kernel 2.6.18-194.8.1.el5xen My sessions will work using https, but not using simple http. I've compared my configs with another identical machine which works with both, and I can't figure out why. Anyone got an idea? Here's the simple script I run to test. ?php session_start(); echo 'session started'; if (isset($_SESSION['name'])) { echo 'br /' . $_SESSION['name']; session_destroy(); } else { echo 'br /No session found'; $_SESSION['name'] = 'My session'; } phpinfo(); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Are you sure session.cookie_secure is not turned on somewhere? Andrew No, it was not set anywhere. But I did add it in with session.cookie_secure 0 and it solved my issue. Thank you very much Andrew! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Questions from a Newbie - Please Help
-Original Message- From: Steve Staples [mailto:sstap...@mnsi.net] Sent: Tuesday, October 19, 2010 11:51 AM To: php-general Subject: RE: [PHP] Questions from a Newbie - Please Help On Tue, 2010-10-19 at 11:18 -0700, Tommy Pham wrote: -Original Message- From: Steve Staples [mailto:sstap...@mnsi.net] Sent: Tuesday, October 19, 2010 11:07 AM To: Ethan Rosenberg Cc: php-general@lists.php.net Subject: RE: [PHP] Questions from a Newbie - Please Help thread has been trimmed to NOTHING i am pretty sure i read it on here already... but your PHP code looks wrong. ORIGNAL CODE: /* * Create Database test22 */ htmlbody ?php $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date ); echo Create table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) ); $sql= SHOW DATABASES; ? /body/html FIXED CODE: htmlbody ?php /* * Create Database test22 */ $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; echoCreate table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10), Height decimal(4,1), Weight0 decimal(4,1), BMI decimal(3,1) Date0 date );; echoCreate table Visit2 ( Indx Int(7) Primary Key Not null auto_increment, Weight decimal(4,1) not null, StudyDate date not null, RecordNum Int(11) );; $sql= SHOW DATABASES; ? /body/html END FIXX firstly... you are missing your ending ; AFTER the on most of your lines... and i've seen this before, where it wont throw the error. secondly, all this is doing, is echoing out lines to either the console, or the web page... it is not running the queries at all. So, if you're trying to execute this from a shell script, then the line starting with $cxn that created the connection to the database, is irrelevant. If you are trying to just run from the website, and show what you WANT to do, then you have to end your statements with the ; character. You should be able to copy and paste my FIXED code, and it should echo out something... it is helps, before you make the $cnx call, put in error_reporting(E_ALL); lastly, if you want to call the queries from php, then you will have to remove the echo, and make them function calls to the database... here is a VERY quick redo of your code to make the mysqli calls: htmlbody ?php /* * Create Database test22 */ $cxn = mysqli_connect($host,$user,$password); echoCreate database test22; The 2 statements below would fail ;) ACUTALLY... the only reason they fail, is becuase i didn't realize that I kept the other echo above, and it didn't create the database... that should have been: mysqli_query($cxn, Create database test22); and then inside, creating the table Names2 needs to be test22.Names2 and the same for visit2. the other issue, is with the create Names2... where the primary key is default=1000 (should be default 1000), and auto_increment... can't have a default AND auto_increment. other than those, this works fine... providing he has the $user, $host, $password declared as well. I personally dont use this, i use the PEAR:MDB2 classes, so this was just a quick php.net search... WHICH would have helped the OP on this one. http://ca.php.net/manual/en/mysqli.query.php I hate to say it, since i was a noob once, but RTFM, or LRN2GOOGLE and you will find it easier, and then once you can't understand it, ask. but there was so much fail in the OP's code. sorry. I think the scary part, is that you're being forced to learn PHP to develop in, and you can't figure out a simple echo statement? Steve I did point out MySQLi section in the manual but he said it was too much for him to comprehend. And from the codes he provided, he lacked the basic knowledge of PHP. Thus, he shouldn't even consider doing anything else, much less accessing the DB as there are more complications arise other than just PHP syntax error. mysqli_query($cxn, Create table Names2 ( RecordNum Int(11) Primary Key Not null default=1 auto_increment, FirstName varchar(10), LastName varchar(10),
[PHP] simple class constructor
Hi everyone, I've been really good at googling to find my answers, but this time my method isn't working for me. I have created a very simple class and a constructor hoping to get a much better understanding of how to work with them. The code works, but because it's very simple, I'm not sure that the way I'm trying to access it is possible. All I'm trying to do is access the class from outside the function. (is that how to describe it?) For instance I have this simple code: class simpleConstructer { function __construct() { echo running the constructor; } } $test=new simpleConstructer(); 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. The thought of a session crossed my mind, but I'm pretty confident at my level to know I don't need a session. Could someone point me in the right direction or give me some pointers, advice? -- Blessings David M. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple class constructor
Can you paste the index page's code here? If the page is going blank there's probably an error (syntax, bad file path, etc). If you have access you can turn error reporting on so you can actually see the error - or better yet check the php error log file. Settings for both of these are in the php.ini file, though sometimes they can be overridden by apache directives (depending on the setup). http://php.net/manual/en/ini.core.php Chris. On Tue, Oct 19, 2010 at 4:12 PM, David McGlone da...@dmcentral.net wrote: Hi everyone, I've been really good at googling to find my answers, but this time my method isn't working for me. I have created a very simple class and a constructor hoping to get a much better understanding of how to work with them. The code works, but because it's very simple, I'm not sure that the way I'm trying to access it is possible. All I'm trying to do is access the class from outside the function. (is that how to describe it?) For instance I have this simple code: class simpleConstructer { function __construct() { echo running the constructor; } } $test=new simpleConstructer(); 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. The thought of a session crossed my mind, but I'm pretty confident at my level to know I don't need a session. Could someone point me in the right direction or give me some pointers, advice? -- Blessings David M. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple class constructor
Also wanted to point out that you can check the error reporting level and log file location (really all of the php's settings) by calling phpinfo(); in your code. ?php phpinfo(); ? Chris. On Tue, Oct 19, 2010 at 4:54 PM, chris h chris...@gmail.com wrote: Can you paste the index page's code here? If the page is going blank there's probably an error (syntax, bad file path, etc). If you have access you can turn error reporting on so you can actually see the error - or better yet check the php error log file. Settings for both of these are in the php.ini file, though sometimes they can be overridden by apache directives (depending on the setup). http://php.net/manual/en/ini.core.php Chris. On Tue, Oct 19, 2010 at 4:12 PM, David McGlone da...@dmcentral.netwrote: Hi everyone, I've been really good at googling to find my answers, but this time my method isn't working for me. I have created a very simple class and a constructor hoping to get a much better understanding of how to work with them. The code works, but because it's very simple, I'm not sure that the way I'm trying to access it is possible. All I'm trying to do is access the class from outside the function. (is that how to describe it?) For instance I have this simple code: class simpleConstructer { function __construct() { echo running the constructor; } } $test=new simpleConstructer(); 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. The thought of a session crossed my mind, but I'm pretty confident at my level to know I don't need a session. Could someone point me in the right direction or give me some pointers, advice? -- Blessings David M. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple class constructor
On Tue, Oct 19, 2010 at 04:12:51PM -0400, David McGlone wrote: Hi everyone, I've been really good at googling to find my answers, but this time my method isn't working for me. I have created a very simple class and a constructor hoping to get a much better understanding of how to work with them. The code works, but because it's very simple, I'm not sure that the way I'm trying to access it is possible. All I'm trying to do is access the class from outside the function. (is that how to describe it?) For instance I have this simple code: class simpleConstructer { function __construct() { echo running the constructor; } } $test=new simpleConstructer(); 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. The thought of a session crossed my mind, but I'm pretty confident at my level to know I don't need a session. You're right. Using a session would be completely unnecessary, and I'm not even sure how it would assist at all. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[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
RE: [PHP] Formatting an ECHO statement.
From: Cris S Someone needs to hire me now, to keep me busy and stop me from taking this issue apart one piece at a time. Kee-rist. That's not likely to happen soon. You have demonstrated here that you are immature and have very little self-control or self-respect. There is no way you would be hired for any shop that I have ever worked in. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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? -- Blessings David M. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] simple class constructor
-Original Message- From: David McGlone [mailto:da...@dmcentral.net] Sent: Tuesday, October 19, 2010 4:32 PM To: php-general@lists.php.net 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(); Regards, Tommy -- Blessings David M. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple class constructor
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. David
RE: [PHP] simple class constructor
On Tue, 2010-10-19 at 16:53 -0700, Tommy Pham wrote: -Original Message- From: David McGlone [mailto:da...@dmcentral.net] Sent: Tuesday, October 19, 2010 4:32 PM To: php-general@lists.php.net 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple class constructor
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple class constructor
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
RE: [PHP] simple class constructor
-Original Message- From: David McGlone [mailto:da...@dmcentral.net] Sent: Tuesday, October 19, 2010 5:32 PM To: php-general@lists.php.net Subject: RE: [PHP] simple class constructor On Tue, 2010-10-19 at 16:53 -0700, Tommy Pham wrote: -Original Message- From: David McGlone [mailto:da...@dmcentral.net] Sent: Tuesday, October 19, 2010 4:32 PM To: php-general@lists.php.net 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple class constructor
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] simple class constructor
[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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] simple class constructor
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] simple class constructor
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Fiscal Years and Quarters
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:d...@pointmade.net] Sent: Tuesday, October 19, 2010 7:12 PM To: php-general@lists.php.net 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Possible foreach bug; seeking advice to isolate the problem
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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Fiscal Years and Quarters
Is there any way to get rid of, whatever wet behind the ears person whom has this spam return for every post. mytr...@mail.ua 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:d...@pointmade.net] Sent: Tuesday, October 19, 2010 7:12 PM To: php-general@lists.php.net 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php