[PHP] Need help on increment date
HI all I need help to increment date in php. I found this code helpful $date = strtotime(+1 day, strtotime(2007-02-28)); echo date(Y-m-d, $date); But when My date is 2008-02-28 this code give output 2012-03-01. But it should be 2008-02-29. Where I am getting wrong. -- Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck 2048R/89C932E1 http://goo.gl/TkP5U Volunteer, FOSS Bangladesh http://fossbd.org/ Mozilla Repshttp://reps.mozilla.org 01199151550
Re: [PHP] Need help on increment date
On 24 May 2012, at 08:18, Md Ashickur Rahman Noor wrote: I need help to increment date in php. I found this code helpful $date = strtotime(+1 day, strtotime(2007-02-28)); echo date(Y-m-d, $date); But when My date is 2008-02-28 this code give output 2012-03-01. But it should be 2008-02-29. Where I am getting wrong. Works fine for me: http://dev.stut.net/php/increment_date.php Have you extracted the above from other code, or are you seeing this behaviour with just those two lines? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need help on increment date
Get this from herehttp://stackoverflow.com/questions/660501/simplest-way-to-increment-a-date-in-php -- Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck 2048R/89C932E1 http://goo.gl/TkP5U Volunteer, FOSS Bangladesh http://fossbd.org/ Mozilla Repshttp://reps.mozilla.org 01199151550 Have you extracted the above from other code, or are you seeing this behaviour with just those two lines? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] Need help on increment date
It works for me too. I tell you two things, a) make sure there is a space after +1 day. So it should look like +1 day . This ensures that the unix time is not concatenated with day. b) calling strtotime 2 times is not a great solution. You can all it once only. Like this, $date = strtotime http://www.php.net/strtotime(+1 day 2008-02-28); // better to call this, as the order is quite logical $date = strtotime http://www.php.net/strtotime(2008-02-28 +1 day); -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation distinguishes between follower and leader
Re: [PHP] Need help on increment date
It works. Thanks you two. Thanks Shiplu bro for the advice. -- Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck 2048R/89C932E1 http://goo.gl/TkP5U Volunteer, FOSS Bangladesh http://fossbd.org/ Mozilla Repshttp://reps.mozilla.org 01199151550 On 24 May 2012 15:08, shiplu shiplu@gmail.com wrote: $date = strtotime http://www.php.net/strtotime(2008-02-28 +1 day);
[PHP] Cookie use management
Not directly a PHP problem, but since PHP tends to automatically create a session cookie I thought it appropriate to ask here first. The European rules on asking permission to use cookies have been around for a year now, and very few sites seem to be worrying about it until now, but press coverage is flagging that the ICO in the UK will start 'prosecuting' next week. Not exactly what the ICO are saying themselves, as they would prefer that the BROWSERS defaulted to cookies being blocked generally, so every cookie action requires approval locally anyway. Session cookies could be claimed to be exempt, but with the increasing hidden use of Google Analytics or in my case Piwik, WE become responsible or all that activity and so a few 'commercial' sites are appearing offering chargeable services to manage this for you. I've been trying to dig down through the google results to find anything open source that provides something easily bolted on to existing PHP sites to intercept cookie use before it actually happens. My reading of the rules would suggest that simply adding a session cookie is acceptable as long as the site identifies they are being used, but until there is some 'case law', actually practice is very grey? Pop-up is obviously out of the question since that can be blocked, and even javascript could be blocked so what can be relied on to 'Obtain permission before using a cookie'? -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cookie use management
Lester Caine les...@lsces.co.uk writes: Not directly a PHP problem, but since PHP tends to automatically create a session cookie I thought it appropriate to ask here first. I don't know about the rest of your post, but you can easily turn off this behavior if it's present (unless you are using a rather poor host), see http://www.php.net/manual/en/session.configuration.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] w.r.t. mail() function
On Wed, May 23, 2012 at 10:25 PM, Jim Lucas li...@cmsws.com wrote: On 05/22/2012 09:12 PM, Ashwani Kesharwani wrote: Hi , I have a query w.r.t. mail() function in php. I have hosted my site and i have created an email account as well. when i am sending mail to different recipient from my php script using above function it is getting delivered to respective recipients as expected. However if I want to see those mail in the sent folder of my email account , i can not see those mails there. How can I achieve this. Any suggestions. Regards Ashwani Why not BCC it to your self, and then setup a filter in your email client to move it where ever you want it to be. Maybe because not everyone uses mail clients that have a filter functionality? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function size
On Wed, May 23, 2012 at 10:14 PM, shiplu shiplu@gmail.com wrote: On Thu, May 24, 2012 at 1:56 AM, Matijn Woudt tijn...@gmail.com wrote: I agree that large switch block are not always easy and useful to split, however, writing too much code inside a switch block isn't considered good practice too IMO. Though, it is unavoidable in some cases I think. I do have some of these functions in my code too, I have one switch block of more than 500 lines, but that's just because I have more than 400 individual case statements, and I don't think there's a better way to do it. Doesn't mean I like it btw. I never encounter such big switch statement in PHP yet. However I saw huge switch and had to optimize it while working with a custom programming language interpreter written in C. When I see the language is OO, I try to apply polymorphic behavior and eliminate any switch statements. Here is a video that demonstrated the concept http://www.youtube.com/watch?v=4F72VULWFvc This is interesting. You do realize that if I would take this switch down to OO, I would have to create 400 different classes to replace this switch statement? Luckily in PHP we can have more classes in a single file, thinking about Java for example would mean I have to create 400 new files... I like the concept, but I don't see how it works for such switch statements. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] problem sending email
hi all,i'm having this problem in sending email using pear. it just wont send :( here's the code .. ?php require_once 'Mail.php'; $from_name = My Self; $to_name = My Friend; $subject = Sending Trial; $mailmsg = GOD please make it work; $From = From: .$from_name. mym...@gmail.com; $To = To: .$to_name. some...@yahoo.com; $recipients = some...@yahoo.com; $headers[From] = $From; $headers[To] = $To; $headers[Subject] = $subject; $headers[Content-Type] = text/plain; charset=iso-8859-1; $smtpinfo[host] = smtp.gmail.com; $smtpinfo[port] = 465; $smtpinfo[auth] = true; $smtpinfo[username] = mym...@gmail.com; $smtpinfo[password] = mypassword; $mail_object = Mail::factory(smtp, $smtpinfo); $mail_object-send($recipients, $headers, $mailmsg); if (PEAR::isError($mail_object)) echo $mail_object-getMessage(); ?
Re: [PHP] problem sending email
On Thu, May 24, 2012 at 2:00 PM, As'ad Djamalilleil asad@gmail.com wrote: hi all,i'm having this problem in sending email using pear. it just wont send :( here's the code .. ?php require_once 'Mail.php'; $from_name = My Self; $to_name = My Friend; $subject = Sending Trial; $mailmsg = GOD please make it work; $From = From: .$from_name. mym...@gmail.com; $To = To: .$to_name. some...@yahoo.com; Don't prefix with From: and To: here. $recipients = some...@yahoo.com; $headers[From] = $From; $headers[To] = $To; $headers[Subject] = $subject; $headers[Content-Type] = text/plain; charset=iso-8859-1; $smtpinfo[host] = smtp.gmail.com; $smtpinfo[port] = 465; $smtpinfo[auth] = true; $smtpinfo[username] = mym...@gmail.com; $smtpinfo[password] = mypassword; $mail_object = Mail::factory(smtp, $smtpinfo); $mail_object-send($recipients, $headers, $mailmsg); if (PEAR::isError($mail_object)) echo $mail_object-getMessage(); ? Also, Gmail SMTP supports only SSL connections. I don't know this PEAR module, but I think you need to host set to something like ssl://smtp.gmail.com, to enforce SSL connection. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Function size
My monitor can also display about 55 lines of code, my functions are, on average, just a few lines of code though -- a maximum of about 20, with an average of around 5 or so. This is because the rule of thumb I follow is that a function should do one thing, and should be named well. The biggest downside to the type of style I have is that if not done correctly, people can feel like they're swimming in a sea of chasing down functions to find out wtf is going on. When done correctly, it leads to pretty clear code, IMO. -- Tedd, I think the length of code depends on a few different factors, what if you have your docblocks, and comment lines, as well as your bracing style? Where do you consider your function to start? Personally, I use this bracing style: # decide if we should work, or sleep if($do == $something) { # do something here $work = 'done'; } else { # something isn't being done now $work = 'sleep'; } In this (really crude) example, there are 11 lines of code. Granted, the way you do your bracing you can lose a few lines, and within this example, it could be written as: # decide if we should work, or sleep # default action for if something isn't being done $work = 'sleep'; if($do == $something) { # do something here $work = 'done'; } So, with that craptastic example, we've taken 11 lines, and compressed it to 7. Anyways, I get the rule of thumb to be able to fit a function on a screen, or to make it as small as possible, but sometimes comments can get in the way, and if you like your bracing style, you end up with a lot of extra lines of code too (also if you like to have blank lines between actions). Anyways, my IDE that I use, shows 47 lines on the screen, at 145 characters across, using Courier New 9pt, and I try to keep it to 80 characters wide, but that doesn't always happen :P Steve. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cookie use management
( Forgot email address :) ) Jeremiah Dodds wrote: Lester Caineles...@lsces.co.uk writes: Not directly a PHP problem, but since PHP tends to automatically create a session cookie I thought it appropriate to ask here first. I don't know about the rest of your post, but you can easily turn off this behavior if it's present (unless you are using a rather poor host), see http://www.php.net/manual/en/session.configuration.php That would probably fall under the ICO acceptance that they don't want people to feel that they simply have to switch site functionality off ;) I'm doing the hosting, but many of the sites that I need to support we have not written the code which as a range of 'frameworks', so I'm trying to find something that can be added in easily - like the Piwik tracking - without having to rewrite the sites ... I'm thinking I need to write my own module, but I can't believe that no-one has done it yet. Or perhaps they are all charging for the service :) -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] openssl_sign() openssl_verify() discrepancy
On 05/23/2012 02:00 PM, Matijn Woudt wrote: On Wed, May 23, 2012 at 9:42 PM, Jason Gerfenjason.ger...@utah.edu wrote: On 05/23/2012 01:26 PM, Matijn Woudt wrote: On Wed, May 23, 2012 at 9:12 PM, Jason Gerfenjason.ger...@utah.edu wrote: On 05/23/2012 01:05 PM, Matijn Woudt wrote: On Wed, May 23, 2012 at 8:29 PM, jasjason.ger...@utah.edu wrote: I have run into a problem that I am altogether unfamiliar with. A scenario. I retrieve a users private key from a database. I then use the openssl_pkey_get_private() function to load it as a resource object and proceed to call the openssl_sign() function to obtain a digital signature of a string. No problem, I get a valid signature which I then base64 encode and store in a database. Now lets say a couple of days from now I load up the public key which corresponds to the private key which was used to originally sign the data to verify it and it does not work. The kicker is if I perform the very same routine without saving the signature and attempting to verify it it works without problems. Have you checked what $signed looks like after running the script? Compare it to $signature. Most likely you corrupted your date elsewhere, maybe when inserting it into the database. - Matijn The example that accompanies the post shows two examples, one worksone does not. Neither however use any type of database, as both simply assign or use the valid signature stored within either the $signature or $signed variables. I wish I could say that is the problem, I took care to properly encode/decode when saving or retrieving the information and as well in the original post I removed this as a possible cause by simply defining the $signature variable and assigning a valid signature to it for testing. First of all, it seems $signature is in base64 format, so I think you should base64_decode that one first. Then it appears to me that $signature is not the same as $signed, on my system. If I base64_encode $signed, save it by copying it from my browser, and then enter it as $signature, and then use base64_decode on $signature it works fine. - Matijn Those are the same steps I just mentioned. The base64_decoding is a typo on the second example. It should read openssl_verify($unsigned, base64_decode($signature), $id); Well, then maybe you should explain the problem further, because with this it works fine, and it appears to me the problem is not here but it comes when you try to store/retrieve the data. - Matijn Well without you saying should explain the problem further I wouldn't have conducted the series of tests to verify each component being used within the sign/save retrieve/verify processes. I was passing the wrong argument in during my retrieve/verify flow. Thanks again! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function size
Steven Staples sstap...@mnsi.net writes: My monitor can also display about 55 lines of code, my functions are, on average, just a few lines of code though -- a maximum of about 20, with an average of around 5 or so. This is because the rule of thumb I follow is that a function should do one thing, and should be named well. The biggest downside to the type of style I have is that if not done correctly, people can feel like they're swimming in a sea of chasing down functions to find out wtf is going on. When done correctly, it leads to pretty clear code, IMO. -- Tedd, I think the length of code depends on a few different factors, what if you have your docblocks, and comment lines, as well as your bracing style? Where do you consider your function to start? I, and I'm fairly sure many others, do not count docblocks, comment lines, or lines containing only braces in the count for LOC in a function. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function size
On May 23, 2012, at 3:49 PM, Ashley Sheridan wrote: I'm of the same mind. Generally I'll split a function if I'm reusing more than a couple of lines of code. I only split a large function if it's actually doing several things, if it happens to need 200 lines to perform one 'step' then I'll leave it as is. While I do prefer my functions to fit into a single 'screen', it rarely happens quite like that, because I move from screen to screen with different resolutions, so there's no constant limit for me. As a rough example, on a random selection of 27 functions taken from a controller on a site I worked on I get these general statistics: Functions: 27 Mean lines: 22.5 Mode lines: 3 Max lines: 218 The function with 218 lines is a large switch, and it doesn't make sense to do it any other way, because it would actually end up less readable. I see you and I are like minds in many ways. I had one large switch block that had 255 different cases. Oddly enough I was parsing a Tiger data file (USGS survey data) that contained 255 different record types. Each record type required a different function to parse the data and render it's portion of the overall map. That lead to me create a linked-list that held the memory addresses of both data and function. That way simply accessing the linked list coupled data to function and drew the map. It was neat. I find it also neat, while I'm not an expert on the subject, eliminating the need for 'switch' and 'if' statements via extending classes in OO. Shiplu provided a link, which I found interesting: http://www.youtube.com/watch?v=4F72VULWFvc It showed how one can eliminate such conditionals, but at the same time it massively increased the code to preform 1 + 2 * 3. :-) And to others, I don't need comment on how I missed the point -- I didn't. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function size
On May 24, 2012, at 8:37 AM, Steven Staples wrote: Tedd, I think the length of code depends on a few different factors, what if you have your docblocks, and comment lines, as well as your bracing style? Where do you consider your function to start? It starts where it starts. It doesn't make any difference how you do it, it's what you see in one view that counts. If you are very verbose with spaces, brace styles, comments, and such, then your functions have less actual statement lines than others with more cryptic coding styles, but I would bet the line limit of total number of lines remain in place regardless. This is more a condition of physical/mental limits on humans than it is on coding style. So, there's no better or worse' point here -- it is more an observation. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] w.r.t. mail() function
On 05/24/2012 04:39 AM, Matijn Woudt wrote: On Wed, May 23, 2012 at 10:25 PM, Jim Lucasli...@cmsws.com wrote: On 05/22/2012 09:12 PM, Ashwani Kesharwani wrote: Hi , I have a query w.r.t. mail() function in php. I have hosted my site and i have created an email account as well. when i am sending mail to different recipient from my php script using above function it is getting delivered to respective recipients as expected. However if I want to see those mail in the sent folder of my email account , i can not see those mails there. How can I achieve this. Any suggestions. Regards Ashwani Why not BCC it to your self, and then setup a filter in your email client to move it where ever you want it to be. Maybe because not everyone uses mail clients that have a filter functionality? well, if he is wanting the message to be placed in the outbox or sent folder of his email client, and this client is on his workstation and the sent folder is accessed via IMAP, nor is it via a web client, then his only option is to have his email client filter a message to the sent folder. POP3 picks up new messages from your inbox. IMAP allows you to have folders on/in the mail server file structure, but the mail server would then need a filter (ie: procmail) to move the new message over to the correct folder. So, no matter what type of solution he comes up with, something, either his client or the mail server will need to have a filter created to move the message to the correct folder. Now, I guess you could completely sidestep all security and with proper setting have php write the email to the correct folder in the persons sent box. And he could then access it via IMAP and/or a web based email client. But, this would require that php process have file level access to the folder which his mail directory resides. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Function size
On May 23, 2012 9:14 AM, Tedd Sperling t...@sperling.com wrote: Hi gang: On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote: A rule of thumb is no more than 50 lines per function, most much less. Back in the day when we didn't have nifty gui screens and an 24 line terminals (yay green on black!), if a function exceeded one printed page, it was deemed too long and marked for refactoring. You hit upon a theory of mine -- and that is our functions grow in size up to our ability to view them in their totality. When our functions get beyond that limit, we tend to refactor and reduce. I know from the last several decades of programming, my functions have increased in number of lines. But, they have reached a limit that limit is generally about the number of lines I can read in half of my monitor's height. This of course, is dependent on monitor resolution, font-size, and how far I am sitting from the monitor. But I think this is a natural and physical limit that we don't normally recognize. I can cite studies that support my theory. It would be an interesting survey to ask programmers to review their code and provide the average number of lines in their functions AND how many lines of code their monitor's can display. In other words, look at your editor; count the number of lines your monitor can display; estimate the number of lines in your average function; and report the findings. For example, mine is about half -- my monitor can display 55 lines of code and my average function is around 25 lines. YMMV. Interesting, yes? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com Yes, I think that is *exactly* the criterion-- not a mystery or an emergent thing, really, was a pretty expicit reasoning--being able to see/scan the entire function on one page (or now in one screenful) makes it much easier to see what happens in the function, where blocks open/close, and it forces one to break up code into logical units.
Re: [PHP] Re: Function size
On Thu, 2012-05-24 at 15:48 -0500, tamouse mailing lists wrote: On May 23, 2012 9:14 AM, Tedd Sperling t...@sperling.com wrote: Hi gang: On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote: A rule of thumb is no more than 50 lines per function, most much less. Back in the day when we didn't have nifty gui screens and an 24 line terminals (yay green on black!), if a function exceeded one printed page, it was deemed too long and marked for refactoring. You hit upon a theory of mine -- and that is our functions grow in size up to our ability to view them in their totality. When our functions get beyond that limit, we tend to refactor and reduce. I know from the last several decades of programming, my functions have increased in number of lines. But, they have reached a limit that limit is generally about the number of lines I can read in half of my monitor's height. This of course, is dependent on monitor resolution, font-size, and how far I am sitting from the monitor. But I think this is a natural and physical limit that we don't normally recognize. I can cite studies that support my theory. It would be an interesting survey to ask programmers to review their code and provide the average number of lines in their functions AND how many lines of code their monitor's can display. In other words, look at your editor; count the number of lines your monitor can display; estimate the number of lines in your average function; and report the findings. For example, mine is about half -- my monitor can display 55 lines of code and my average function is around 25 lines. YMMV. Interesting, yes? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com Yes, I think that is *exactly* the criterion-- not a mystery or an emergent thing, really, was a pretty expicit reasoning--being able to see/scan the entire function on one page (or now in one screenful) makes it much easier to see what happens in the function, where blocks open/close, and it forces one to break up code into logical units. With the odd exception being where code is more readable in a longer format, as seen with my and several others examples of long functions that rely heavily on switches. -- Thanks, Ash http://www.ashleysheridan.co.uk