php-general Digest 2 Oct 2009 12:38:04 -0000 Issue 6369
php-general Digest 2 Oct 2009 12:38:04 - Issue 6369 Topics (messages 298455 through 298476): Re: Self-Process php forms or not? 298455 by: MEM 298458 by: Manuel Lemos 298463 by: kranthi 298466 by: Manuel Lemos 298467 by: Manuel Lemos 298469 by: kranthi 298470 by: kranthi 298472 by: Ashley Sheridan 298473 by: kranthi Re: Parse Question Using list() 298456 by: cool.hosting4days.com 298459 by: Jim Lucas Re: Curl output 298457 by: Paul M Foster 298460 by: Jim Lucas 298462 by: kranthi 298471 by: Ashley Sheridan 298474 by: kranthi 298475 by: Ashley Sheridan 298476 by: kranthi iconv - bad encoding 298461 by: Jarosek Re: Incorrect _SERVER['SERVER_PORT'] returned?? 298464 by: kranthi Re: PHP/MySQL Superstars 298465 by: Jerome Botbol Re: WYSIWYG editor to change textarea 298468 by: kranthi 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--- Thanks a lot to all, I will see what best fits my limited knowledge, and choose the possible option. Regards, Márcio -Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: quinta-feira, 1 de Outubro de 2009 20:11 To: tedd; 'PHP-General List' Subject: Re: [PHP] Self-Process php forms or not? On 10/1/09 10:13 AM, tedd tedd.sperl...@gmail.com wrote: At 1:00 PM +0100 10/1/09, MEM wrote: One last question about this: I've done a self submit form, after hearing all the advantages expressed here. But how could we relate, without using javascript, a self submit form with a success page or a confirmation page that doesn't show the form? Can please someone throw me some infos about this please? MEM: Here's what I do -- it's pretty simple. I use a hidden input variable I call step and monitor it as the user clicks whatever form submit they are on -- it works like so: $step = isset($_POST['step']) ? $_POST['step'] : 0; switch ($step) { case 0: // present the first form to the user // collect data // you can enhance the user experience by using javascript here. // input type=hidden name=step value=1 break; case 1: // present second form to the user // clean data // if data OK then record data in db input type=hidden name=step value=2 // if data not OK then send user back input type=hidden name=step value=0 break; case 2: //present the third form to the user // success, or confirmation, or thank you page break; } Now, to make things easier for the user, be sure to set session variables for all the data collected in the first form so that IF you send the user back to the first form, the user doesn't have to reenter everything. i do pretty much the same thing. each form in my html template files has a form name tucked away in a hidden input element. the only difference from your method is that the names are unique across the application. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- ---BeginMessage--- Hello, on 10/01/2009 09:00 AM MEM said the following: One last question about this: I've done a self submit form, after hearing all the advantages expressed here. But how could we relate, without using javascript, a self submit form with a success page or a confirmation page that doesn't show the form? Can please someone throw me some infos about this please? Ps- I've googled: php redirect success page on self submit form and similar... All you need to do is to include an hidden field in the form. Then check the respective $_POST or $_GET variable is set. If it is not set, show the form for the first time. If it is set, validate the form and process it. If the form is not valid, show the form again with previously submitted values. This tutorial video explains this workflow: http://www.phpclasses.org/browse/video/1/package/1/section/usage.html This example script demonstrates how to setup your code. It uses a function of a forms class name WasSubmiteed() to check if the form is being presented for the first time or is being submitted: http://www.meta-language.net/forms-examples.html?example=test_formcode=1 -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ ---End Message--- ---BeginMessage--- I try to avoid the use of hidden form elements as much as possible, especially for tracking whether a user has submitted
php-general Digest 3 Oct 2009 02:00:29 -0000 Issue 6370
php-general Digest 3 Oct 2009 02:00:29 - Issue 6370 Topics (messages 298477 through 298504): Re: Parse Question Using list() 298477 by: Gerardo Benitez Re: Self-Process php forms or not? 298478 by: MEM 298480 by: tedd 298481 by: tedd 298483 by: MEM 298484 by: tedd 298485 by: Ben Dunlap 298495 by: Manuel Lemos 298496 by: Manuel Lemos 298499 by: Manuel Lemos Re: Curl output 298479 by: Ashley Sheridan Re: PHP/MySQL Superstars 298482 by: tedd Whacky increment/assignment logic with $foo++ vs ++$foo 298486 by: Daevid Vincent 298487 by: Ben Dunlap 298488 by: Robert Cummings 298489 by: Tommy Pham 298490 by: Daevid Vincent 298491 by: Ben Dunlap 298492 by: Daniel Brown 298493 by: Daniel Brown 298494 by: Ben Dunlap 298497 by: Ben Dunlap 298498 by: Ben Dunlap 298500 by: Daevid Vincent 298501 by: Mari Masuda 298502 by: Ben Dunlap 298503 by: Joost Finding out DST with PHP 298504 by: Rohit Sodhia 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--- Use the tool that PHP provides for such problems. http://php.net/fgetcsv fgetcsv is very useful, here a example: ?php $row = 1; /* load file*/ $handle = fopen(log.csv, r); /* read line by line */ while (($data = fgetcsv($handle, 1000, ,)) !== FALSE) { $num = count($data); echo p $num fields in line $row: br //p\n; $row++; for ($c=0; $c $num; $c++) { echo $data[$c] . br /\n; } } fclose($handle); ? -- Gerardo Benitez ---End Message--- ---BeginMessage--- I want to apologize to you all. I have mentioned two things on the same basket, but it was not appropriate. Since a confirmation page is not the same thing as a success page. Let's forget about the confirmation page, since it's not required. I'm now understanding that even if the form is submitted to self, we can still use a redirect to a success_message_page.php. However, we must do this redirect, AFTER the form has submitted to himself. It's the only thing that we have to pay attention here, correct? Since we are not dealing with a confirmation page, or a multi-step form, the hidden field isn't necessary. It's this correct assumptions? Please advice, Regards, Márcio -Original Message- From: kranthi [mailto:kranthi...@gmail.com] Sent: sexta-feira, 2 de Outubro de 2009 11:12 To: a...@ashleysheridan.co.uk Cc: Manuel Lemos; php-gene...@lists.php.net; MEM; Bob McConnell Subject: Re: [PHP] Self-Process php forms or not? You say you don't use hidden fields because they can be modified too easily, yet you say you check for the submit button? Which out of the two do you do, as last time I checked, modifying one form field is as easy as changing any other! I completely agree with you. changing submit text is as easy as changing hidden fields, but its less likely for a user to modify a submit button as compared to a hidden field. moreover it just reduces my typing load. (This is just my practice) Also worth noting, you can only successfully check for the name=submit value if there is only one submit button in your form, as that is then the default (and only) submit that the form can use, so it uses that. If you have more than one submit button (and this includes image input elements) then using the keyboard will use the first submit field it finds I believe. Cant agree with you on this though. as far as i know using name= (names of the two buttons may/may not be unique) is the only way to track form submission for forms with multiple submit buttons. Please point out if you think otherwise -- Kranthi. ---End Message--- ---BeginMessage--- At 1:55 PM +0530 10/2/09, kranthi wrote: and yes i forgot to mention... i avoid hidden form elements because they can be modified very easily and hence pose a security threat. That depends upon how sloppy you are in coding. NONE of my hidden variables pose any security problems whatsoever. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com ---End Message--- ---BeginMessage--- At 3:06 PM +0100 10/2/09, MEM wrote: I want to apologize to you all. I have mentioned two things on the same basket, but it was not appropriate. Since a confirmation page is not the same thing as a success page. Let's forget about the confirmation page, since it's not required. I'm now understanding that even if the form is submitted to self, we can still use a redirect to a success_message_page.php. However, we must do this redirect, AFTER the
[PHP] iconv - bad encoding
Hello I noticed a problem using iconv, but investigation showed, that this is not exectly the iconv itself, but something like php encoding. From the beginning: a hava an incoming variable $text; it has some Polish diactics 'strona główna'. I expect to remove diactics : 'strona glowna'. So I use iconv: iconv('utf-8', 'us-ascii//TRANSLIT', $text) and unfortunetly i get: 'strona g??wna' ... But only under apache, in browser The same file, command, etc run from bash gives: 'strona glowna' ... OK So i think : bad config, but double checked and configs are identical... (cli and apache2) Best part: for 2 or 3 times after starting computer (debian), it didn't worker until I did: (apache start apache stop - not apache restart), then it worked. Now it doesn't work any more. No other config (except php was changed). Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Curl output
using the base tag is a solution to your problem if the links are relative.. http://www.w3schools.com/TAGS/tag_base.asp but I am not sure if base tag works outside html/html try... base href=URL/base before curl_init() where URL is parsed using PHP's parse_url() function on http://example.com in either case if there are any external js/css files cURL wont fetch external files(and if they are internal/inline your browser should display them already).. your browser will have to fetch them for you, net console of firebug will be helpful in that case. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
I try to avoid the use of hidden form elements as much as possible, especially for tracking whether a user has submitted a form or not... I use name=submit for the submit button instead, that will pass the value of the submit button to the action script. above all i use a template engine, smarty to take care of the presentation for me(like deciding whether to show the form and/or a success/failure message) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Incorrect _SERVER['SERVER_PORT'] returned??
i dont have any idea about your problem, but just an idea have you used https://localhost in the browser while trying to check _SERVER['SERVER_PORT'] ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: PHP/MySQL Superstars
Thanks Manuel your input is greatly appreciated. Jerome -Original Message- From: Manuel Lemos [mailto:mle...@acm.org] Sent: 01 October 2009 20:46 To: Jerome Botbol Cc: php-general@lists.php.net Subject: Re: PHP/MySQL Superstars Hello, on 10/01/2009 10:09 AM Jerome Botbol said the following: Hi All, We require a PHP / MySQL superstar to work in-house at our offices near Edgware, London for 3 months on a ground breaking new web 2.0 project which involves a variety of exciting new technologies. You will need at least 2 years proven experience on commercial projects. Relevant experience on the CI framework is a must. You will be working with an actionscript and front-end XHTML developer, a framework developer who is providing a database design and class system and a design team. Please email your CV to j...@cyber-duck.co.uk (reference PG-tech-01) or feel free to contact me directly. Please let me know if this is of interest to you. You may want to submit your job post in the PHPClasses job board. There are many thousands of PHP developers registered to get notifications about jobs that match their skills. http://www.phpclasses.org/jobs/ If you prefer to tune your search by country and skill, you may want to browse the PHP professionals directory and check the skills in the search form as you wish: http://www.phpclasses.org/professionals/ -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
Hello, on 10/02/2009 04:41 AM kranthi said the following: I try to avoid the use of hidden form elements as much as possible, especially for tracking whether a user has submitted a form or not... I use name=submit for the submit button instead, that will pass the value of the submit button to the action script. above all i use a template engine, smarty to take care of the presentation for me(like deciding whether to show the form and/or a success/failure message) That only works if the user clicks on that submit button. If the user hits the enter key in a text input, the form is submitted but the submit input variable is not set. That is why an hidden input is a safer solution. -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: WYSIWYG editor to change textarea
I would recommend using an open framework like yui/dojo/jquery for ALL your javascript needs..(i personally prefer jquery) each of the above mentioned frameworks have wysiwyg editors of their own. try using http://code.google.com/p/jwysiwyg/ i doubt it will conflict with your javascript with compatibility mode ON http://docs.jquery.com/Using_jQuery_with_Other_Libraries TinyMCE as such is a very good plugin (i use that in nearly all of my projects and never faced a problem with it). may be you should try to debug your code that is conflicting with tinyMCE -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
That only works if the user clicks on that submit button. If the user hits the enter key in a text input, the form is submitted but the submit input variable is not set. That is why an hidden input is a safer solution. i doubt that, because i use the above mentioned method in nearly all of my projects, and all of them are working fine. P.S: i prefer keyboard to mouse as a input device -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
and yes i forgot to mention... i avoid hidden form elements because they can be modified very easily and hence pose a security threat. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Curl output
On Fri, 2009-10-02 at 12:51 +0530, kranthi wrote: using the base tag is a solution to your problem if the links are relative.. http://www.w3schools.com/TAGS/tag_base.asp but I am not sure if base tag works outside html/html try... base href=URL/base before curl_init() where URL is parsed using PHP's parse_url() function on http://example.com in either case if there are any external js/css files cURL wont fetch external files(and if they are internal/inline your browser should display them already).. your browser will have to fetch them for you, net console of firebug will be helpful in that case. Some browser security settings may not allow you to run Javascript code that exists on another server though. The base tag can be used to reference the external CSS and Javascript, but watch out for security settings on client agents. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
On Fri, 2009-10-02 at 13:55 +0530, kranthi wrote: and yes i forgot to mention... i avoid hidden form elements because they can be modified very easily and hence pose a security threat. You say you don't use hidden fields because they can be modified too easily, yet you say you check for the submit button? Which out of the two do you do, as last time I checked, modifying one form field is as easy as changing any other! Also worth noting, you can only successfully check for the name=submit value if there is only one submit button in your form, as that is then the default (and only) submit that the form can use, so it uses that. If you have more than one submit button (and this includes image input elements) then using the keyboard will use the first submit field it finds I believe. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
You say you don't use hidden fields because they can be modified too easily, yet you say you check for the submit button? Which out of the two do you do, as last time I checked, modifying one form field is as easy as changing any other! I completely agree with you. changing submit text is as easy as changing hidden fields, but its less likely for a user to modify a submit button as compared to a hidden field. moreover it just reduces my typing load. (This is just my practice) Also worth noting, you can only successfully check for the name=submit value if there is only one submit button in your form, as that is then the default (and only) submit that the form can use, so it uses that. If you have more than one submit button (and this includes image input elements) then using the keyboard will use the first submit field it finds I believe. Cant agree with you on this though. as far as i know using name= (names of the two buttons may/may not be unique) is the only way to track form submission for forms with multiple submit buttons. Please point out if you think otherwise -- Kranthi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Curl output
Some browser security settings may not allow you to run Javascript code that exists on another server though not many users use those kind of browsers, because if they do most of the websites which use CDNs will not work. Firstly, it is not a good idea to fetch an entire web page and snow it to an user. (use iframes if this is a must) Secondly, this idea may not be feasible if the web page in question uses AJAX, because none of the browsers allow cross domain AJAX requests As a side note, use str_replace(head, headbase/base, $text) if base tag doesnot work On 02/10/2009, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2009-10-02 at 12:51 +0530, kranthi wrote: using the base tag is a solution to your problem if the links are relative.. http://www.w3schools.com/TAGS/tag_base.asp but I am not sure if base tag works outside html/html try... base href=URL/base before curl_init() where URL is parsed using PHP's parse_url() function on http://example.com in either case if there are any external js/css files cURL wont fetch external files(and if they are internal/inline your browser should display them already).. your browser will have to fetch them for you, net console of firebug will be helpful in that case. Some browser security settings may not allow you to run Javascript code that exists on another server though. The base tag can be used to reference the external CSS and Javascript, but watch out for security settings on client agents. Thanks, Ash http://www.ashleysheridan.co.uk -- Kranthi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Curl output
On Fri, 2009-10-02 at 15:59 +0530, kranthi wrote: not many users use those kind of browsers, because if they do most of the websites which use CDNs will not work. I've read that the upcoming Firefox 4 may have some features built in for this sort of thing, and there are plugins out there for most browsers that can do this as an added layer of security. On this front though, has anyone else read about Microsofts Gazelle browser/os? I'm not trying to plug it here or anything (I'm an anti Windows person myself!) but the concept looks interesting. It goes further than Chrome where each tab has it's own process by giving each domain specific object its own process/sandbox. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Curl output
I've read that the upcoming Firefox 4 may have some features built in for this sort of thing, and there are plugins out there for most browsers that can do this as an added layer of security. Sorry but I could not understand what you meant by this coming back to original problem... you should keep in mind that if base tag is used, the links (a href=...) in that page will become absolute links instead of relative links -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parse Question Using list()
Use the tool that PHP provides for such problems. http://php.net/fgetcsv fgetcsv is very useful, here a example: ?php $row = 1; /* load file*/ $handle = fopen(log.csv, r); /* read line by line */ while (($data = fgetcsv($handle, 1000, ,)) !== FALSE) { $num = count($data); echo p $num fields in line $row: br //p\n; $row++; for ($c=0; $c $num; $c++) { echo $data[$c] . br /\n; } } fclose($handle); ? -- Gerardo Benitez
RE: [PHP] Self-Process php forms or not?
I want to apologize to you all. I have mentioned two things on the same basket, but it was not appropriate. Since a confirmation page is not the same thing as a success page. Let's forget about the confirmation page, since it's not required. I'm now understanding that even if the form is submitted to self, we can still use a redirect to a success_message_page.php. However, we must do this redirect, AFTER the form has submitted to himself. It's the only thing that we have to pay attention here, correct? Since we are not dealing with a confirmation page, or a multi-step form, the hidden field isn't necessary. It's this correct assumptions? Please advice, Regards, Márcio -Original Message- From: kranthi [mailto:kranthi...@gmail.com] Sent: sexta-feira, 2 de Outubro de 2009 11:12 To: a...@ashleysheridan.co.uk Cc: Manuel Lemos; php-general@lists.php.net; MEM; Bob McConnell Subject: Re: [PHP] Self-Process php forms or not? You say you don't use hidden fields because they can be modified too easily, yet you say you check for the submit button? Which out of the two do you do, as last time I checked, modifying one form field is as easy as changing any other! I completely agree with you. changing submit text is as easy as changing hidden fields, but its less likely for a user to modify a submit button as compared to a hidden field. moreover it just reduces my typing load. (This is just my practice) Also worth noting, you can only successfully check for the name=submit value if there is only one submit button in your form, as that is then the default (and only) submit that the form can use, so it uses that. If you have more than one submit button (and this includes image input elements) then using the keyboard will use the first submit field it finds I believe. Cant agree with you on this though. as far as i know using name= (names of the two buttons may/may not be unique) is the only way to track form submission for forms with multiple submit buttons. Please point out if you think otherwise -- Kranthi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Curl output
On Fri, 2009-10-02 at 18:07 +0530, kranthi wrote: I've read that the upcoming Firefox 4 may have some features built in for this sort of thing, and there are plugins out there for most browsers that can do this as an added layer of security. Sorry but I could not understand what you meant by this coming back to original problem... you should keep in mind that if base tag is used, the links (a href=...) in that page will become absolute links instead of relative links this is this: Some browser security settings may not allow you to run Javascript code that exists on another server though Also, you won't have to worry about the links, unless you wanted the links that were relative to the remote site to be relative to your own. This would only work out in such a way if you'd scraped their whole site for content, which would beg the question, why would someone honestly need to scrape an entire site? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
At 1:55 PM +0530 10/2/09, kranthi wrote: and yes i forgot to mention... i avoid hidden form elements because they can be modified very easily and hence pose a security threat. That depends upon how sloppy you are in coding. NONE of my hidden variables pose any security problems whatsoever. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
At 3:06 PM +0100 10/2/09, MEM wrote: I want to apologize to you all. I have mentioned two things on the same basket, but it was not appropriate. Since a confirmation page is not the same thing as a success page. Let's forget about the confirmation page, since it's not required. I'm now understanding that even if the form is submitted to self, we can still use a redirect to a success_message_page.php. However, we must do this redirect, AFTER the form has submitted to himself. It's the only thing that we have to pay attention here, correct? Since we are not dealing with a confirmation page, or a multi-step form, the hidden field isn't necessary. It's this correct assumptions? Please advice, Regards, Márcio You can set it up any number of ways. There is no absolute need for a redirect. Everything can be done in one form, or not -- your choice. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/MySQL Superstars
At 4:29 PM -0400 10/1/09, Robert Cummings wrote: I'm a superstar... send me a check for $500,000 and I'll fly on over. Or did you completely misuse the word superstar? Cheers, Rob. Rob: Well, in my book you are a superstar. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
You can set it up any number of ways. There is no absolute need for a redirect. Everything can be done in one form, or not -- your choice. Cheers, tedd Yes. But since I don't want to display a success information + form fields, but only the success information, I believe the only way we have to do this is by either use javascript and update a div or similar, or using only php, by redirecting to another page. Is this correct? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
At 3:35 PM +0100 10/2/09, MEM wrote: You can set it up any number of ways. There is no absolute need for a redirect. Everything can be done in one form, or not -- your choice. Cheers, tedd Yes. But since I don't want to display a success information + form fields, but only the success information, I believe the only way we have to do this is by either use javascript and update a div or similar, or using only php, by redirecting to another page. Is this correct? No -- and you are not listening. I gave you the way to do it, but you are taking another path. As always, it's your choice. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
Yes. But since I don't want to display a success information + form fields, but only the success information, I believe the only way we have to do this is by either use javascript and update a div or similar, or using only php, by redirecting to another page. Is this correct? Whether or not it's the only way, redirecting to a success page is probably the best way, from a user-experience perspective. It keeps the browser history sane and avoids possible trouble with page-refreshes. Google for post redirect get and you'll find all sorts of discussions of this pattern. Here's one of the clearer articles that came up on the first page of results, when I ran that search: http://www.andypemberton.com/engineering/the-post-redirect-get-pattern/ Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
?PHP $num = 123; $num = $num++; print $num; //this prints 123 and not 124 ?!! $num = 123; $num = ++$num; print $num; //this prints 124 as expected $num = 123; $num++; print $num; //this prints 124 as expected $num = 123; print $num++; //this prints 123 and not 124 ?!! print $num++; //this NOW prints 124 ? So then I read the manual because I think I'm loosing my mind and perhaps it's backwards day and nobody told me: http://us3.php.net/manual/en/language.operators.increment.php I'm baffled as to the reasoning behind: $a++ :: Post-increment :: Returns $a, then increments $a by one. Why would you EVER want $num = $num++; to give you back the value you already had? Even if we did $foo = $bar++; I would still logically (and common sensely) expect $foo to be the increment of $bar! It also seems counter-intuitive, as I was always lead to believe everything is processed on the right of an equals sign and then assigned back to the left side of the equals sign. In this case, it does a mixture of both. Can someone PLEASE explain why the developers of PHP chose this seemingly whacky logic? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
Can someone PLEASE explain why the developers of PHP chose this seemingly whacky logic? It mimicks C. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
Daevid Vincent wrote: ?PHP $num = 123; $num = $num++; print $num; //this prints 123 and not 124 ?!! $num = 123; $num = ++$num; print $num; //this prints 124 as expected $num = 123; $num++; print $num; //this prints 124 as expected $num = 123; print $num++; //this prints 123 and not 124 ?!! print $num++; //this NOW prints 124 ? So then I read the manual because I think I'm loosing my mind and perhaps it's backwards day and nobody told me: http://us3.php.net/manual/en/language.operators.increment.php I'm baffled as to the reasoning behind: $a++ :: Post-increment :: Returns $a, then increments $a by one. Why would you EVER want $num = $num++; to give you back the value you already had? Even if we did $foo = $bar++; I would still logically (and common sensely) expect $foo to be the increment of $bar! It also seems counter-intuitive, as I was always lead to believe everything is processed on the right of an equals sign and then assigned back to the left side of the equals sign. In this case, it does a mixture of both. Can someone PLEASE explain why the developers of PHP chose this seemingly whacky logic? This logic is almost universal in modern programming languages. Some people do the following: ?php $index = 1; foreach( @items as @item ) { echo 'tr' .'td'.($index++).'/td' .'td'.$item.'/td' .'/tr'; } ? Some people consider it weird to start at 0 for the above index, because the index is only used when it is 1 or more. But the equivalent of the above is the following: ?php $index = 0; foreach( @items as @item ) { echo 'tr' .'td'.(++$index).'/td' .'td'.$item.'/td' .'/tr'; } ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
- Original Message From: Ben Dunlap bdun...@agentintellect.com To: Daevid Vincent dae...@daevid.com Cc: php-general@lists.php.net Sent: Fri, October 2, 2009 2:06:47 PM Subject: Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo Can someone PLEASE explain why the developers of PHP chose this seemingly whacky logic? It mimicks C. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Any language based on C has it, such as C++, Java and C#. It gives programmers/developers flexibility when to increment and use its value. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
-Original Message- From: Robert Cummings [mailto:rob...@interjinn.com] Sent: Friday, October 02, 2009 2:12 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo Daevid Vincent wrote: ?PHP $num = 123; $num = $num++; print $num; //this prints 123 and not 124 ?!! $num = 123; $num = ++$num; print $num; //this prints 124 as expected $num = 123; $num++; print $num; //this prints 124 as expected $num = 123; print $num++; //this prints 123 and not 124 ?!! print $num++; //this NOW prints 124 ? So then I read the manual because I think I'm loosing my mind and perhaps it's backwards day and nobody told me: http://us3.php.net/manual/en/language.operators.increment.php I'm baffled as to the reasoning behind: $a++ :: Post-increment :: Returns $a, then increments $a by one. Why would you EVER want $num = $num++; to give you back the value you already had? Even if we did $foo = $bar++; I would still logically (and common sensely) expect $foo to be the increment of $bar! It also seems counter-intuitive, as I was always lead to believe everything is processed on the right of an equals sign and then assigned back to the left side of the equals sign. In this case, it does a mixture of both. Can someone PLEASE explain why the developers of PHP chose this seemingly whacky logic? This logic is almost universal in modern programming languages. Some people do the following: ?php $index = 1; foreach( @items as @item ) { echo 'tr' .'td'.($index++).'/td' .'td'.$item.'/td' .'/tr'; } ? Some people consider it weird to start at 0 for the above index, because the index is only used when it is 1 or more. But the equivalent of the above is the following: ?php $index = 0; foreach( @items as @item ) { echo 'tr' .'td'.(++$index).'/td' .'td'.$item.'/td' .'/tr'; } ? My problem isn't with $foo++ vs ++$foo per say. I use pre/post all the time. My issue is that I see no reason to do the ASSIGNMENT FIRST and THEN INCREMENT. That's just counter intuitive. In the case of $foo = $num++, everything to the right of the = should be computed FIRST and THEN handed off to the left side. This particular expression (and I'm unaware of any other PHP expression that works this way) chooses to do some FM (f'n magic) and do an assignment FIRST and THEN increment. All of this is just an academic discussion at this point, as I'm sure there is WAY too much code out there to even consider changing this behaviour to a more sane one. And I'm told it mimics other languages (wright or wrong, it is what it is). Personally I've never (in almost 20 years) done an assignment like $foo = $foo++ as I always use just $foo++ or $foo += 1 or something, hence the reason today is the day a co-worker stumbled upon this and was as confused as I was until I figured it out. D. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
My issue is that I see no reason to do the ASSIGNMENT FIRST and THEN INCREMENT. That's just counter intuitive. In the case of $foo = $num++, everything to the right of the = should be computed FIRST and THEN handed off to the left side. This particular expression (and I'm unaware of any other PHP expression that works this way) chooses to do some FM (f'n magic) and do an assignment FIRST and THEN increment. It's not the expression that works that way -- it's the operator. The post-increment operator /always/ does its work after the expression that it's in has been evaluated. Are you thinking it would be more intuitive if that operator departed from its normal behavior in this one special case? Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
On Fri, Oct 2, 2009 at 17:28, Daevid Vincent dae...@daevid.com wrote: Personally I've never (in almost 20 years) done an assignment like $foo = $foo++ as I always use just $foo++ or $foo += 1 or something, hence the reason today is the day a co-worker stumbled upon this and was as confused as I was until I figured it out. And that's exactly the point: why would you assign this variable to another in the first place? It's just using up resources and creating more overhead in the application. The reason it exists is for processing, really, not assigning; and the ability to do it before or after is appropriate for certain conditions. However, keep in mind that you don't even need to do anything with the variable to increment it: ?php $n = 1; $n++; echo $n.\n; // 2 ? The $var++ vs. ++$var (or, conversely, $var-- vs. --$var) comparison isn't best described by the most commonly-used incrementing scenario: ?php $a = array('foo' = 'bar', 'apple' = 'red', 'lime' = 'green', 'wife' = 'pain in ass', 'lemon' = 'yellow'); for($i=0;$icount($a);$i++) { // } ? but rather by something just slightly more advanced: ?php $num = file_get_contents('visitcount.txt'); if(isset($_GET['countme'])) { echo You are visitor #.++$num.br /\n; file_put_contents($num); } ? If you were to use $num++, it would echo out the current number, THEN increment the value. In this example, it increments the value, THEN echoes it out. The placement of the signs (plus or minus) is the giveaway: if it's before the variable, it's modified before being processed. If it's after, then it's evaluated immediately after the variable is processed. -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Check out our great hosting and dedicated server deals at http://twitter.com/pilotpig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
On Fri, Oct 2, 2009 at 17:42, Daniel Brown danbr...@php.net wrote: but rather by something just slightly more advanced: ?php $num = file_get_contents('visitcount.txt'); if(isset($_GET['countme'])) { echo You are visitor #.++$num.br /\n; file_put_contents($num); } ? Converse example (sorry, forgot to add it): ?php $num = file_get_contents('visitcount.txt'); if(isset($_GET['countme'])) { echo There were .$num++. people here before you.br /\n; file_put_contents($num); } ? -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Check out our great hosting and dedicated server deals at http://twitter.com/pilotpig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
On Fri, Oct 2, 2009 at 2:37 PM, Ben Dunlap bdun...@agentintellect.com wrote: My issue is that I see no reason to do the ASSIGNMENT FIRST and THEN INCREMENT. That's just counter intuitive. In the case of $foo = $num++, everything to the right of the = should be computed FIRST and THEN handed off to the left side. This particular expression (and I'm unaware of any other PHP expression that works this way) chooses to do some FM (f'n magic) and do an assignment FIRST and THEN increment. It's not the expression that works that way -- it's the operator. The post-increment operator /always/ does its work after the expression that it's in has been evaluated. Are you thinking it would be more intuitive if that operator departed from its normal behavior in this one special case? On further thought I do see why this one special case is a little mind-blowing. What the heck /is/ supposed to happen when you do this: $a = 2; $a = $a++; echo $a; Seems like any way you slice it the output should be 3. I guess what's revealed here is that, as far as PHP is concerned, the $a on the right side of the assignment expression is something like a temporary copy of the variable in the current scope. So the assignment gets evaluated, and then ++ operates on that copy and the result is discarded. Honestly I think the only reason anyone would write an expression like that is either to fake out the compiler or because they don't properly understand the use of a unary operator. Or rather, of the increment/decrement operators, because no other unary operator actually changes the thing it operates on (AFAIK), which makes ++ and -- doubly weird. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
Hello, on 10/02/2009 05:23 AM kranthi said the following: That only works if the user clicks on that submit button. If the user hits the enter key in a text input, the form is submitted but the submit input variable is not set. That is why an hidden input is a safer solution. i doubt that, because i use the above mentioned method in nearly all of my projects, and all of them are working fine. P.S: i prefer keyboard to mouse as a input device Sorry, what I meant is that if you have multiple submit buttons in your form, say Preview, Save and Cancel, if you hit enter in a text input it will not set the variables for all buttons. At most only one button variable is set, which usually is the first button in the HTML, but you have no way to change which will be set. If you use an hidden field is easier to determine whether the form was submitted or not, as you do not have to check variables for all buttons. -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
Hello, on 10/02/2009 07:11 AM kranthi said the following: You say you don't use hidden fields because they can be modified too easily, yet you say you check for the submit button? Which out of the two do you do, as last time I checked, modifying one form field is as easy as changing any other! I completely agree with you. changing submit text is as easy as changing hidden fields, but its less likely for a user to modify a submit button as compared to a hidden field. moreover it just reduces my typing load. (This is just my practice) How come an user can modify a hidden field is more likely to change submit button? I don't think an average user will modify anything at all. Also worth noting, you can only successfully check for the name=submit value if there is only one submit button in your form, as that is then the default (and only) submit that the form can use, so it uses that. If you have more than one submit button (and this includes image input elements) then using the keyboard will use the first submit field it finds I believe. Cant agree with you on this though. as far as i know using name= (names of the two buttons may/may not be unique) is the only way to track form submission for forms with multiple submit buttons. Please point out if you think otherwise As everbody has been telling you, if you check an hidden field it will work regardless whether the user clicked on a button or hit enter on a text input. With multiple buttons there is no way (except for using some Javascript) to tell whether it was clicked a button or the user hit enter in a text input. -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
-Original Message- From: Ben Dunlap [mailto:bdun...@agentintellect.com] Sent: Friday, October 02, 2009 2:58 PM To: php-general@lists.php.net; Daevid Vincent Subject: Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo mind-blowing. What the heck /is/ supposed to happen when you do this: $a = 2; $a = $a++; echo $a; Seems like any way you slice it the output should be 3. I guess what's ... and, in fact, that /is/ how C behaves. The following code: int a = 2; a = a++; printf(a = [%d]\n, a); Will output a = [3]. At least on Ubuntu 9 using gcc 4.3.3. So I retract my initial terse reply and apologize for misunderstanding your question. Ben EXACTLY! :) God (or diety of your choice) bless you for getting what I'm saying and proving that it's not C like either. That just adds credence to my/our argument. d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
On Oct 2, 2009, at 15:22, Daevid Vincent wrote: -Original Message- From: Ben Dunlap [mailto:bdun...@agentintellect.com] Sent: Friday, October 02, 2009 2:58 PM To: php-general@lists.php.net; Daevid Vincent Subject: Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo mind-blowing. What the heck /is/ supposed to happen when you do this: $a = 2; $a = $a++; echo $a; Seems like any way you slice it the output should be 3. I guess what's ... and, in fact, that /is/ how C behaves. The following code: int a = 2; a = a++; printf(a = [%d]\n, a); Will output a = [3]. At least on Ubuntu 9 using gcc 4.3.3. So I retract my initial terse reply and apologize for misunderstanding your question. Ben EXACTLY! :) God (or diety of your choice) bless you for getting what I'm saying and proving that it's not C like either. That just adds credence to my/our argument. d I think if you rewrote the above example as int a = 2; b = a++; printf(b = [%d]\n, b); b would be 2 when printed. However, after the second line (b = a+ +;) finished executing, a would then be 3. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
int a = 2; b = a++; printf(b = [%d]\n, b); b would be 2 when printed. However, after the second line (b = a++;) finished executing, a would then be 3. Sure, but that code is perfectly clear. It's the odd special case where you assign the variable to itself, that's ambiguous. Like Daevid said, academic at this point -- but it might shed light on some compiler-design decisions that I don't have the vocabulary for. OTOH it could just a be a unique case with unpredictable results. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
Daevid Vincent wrote: -Original Message- From: Ben Dunlap [mailto:bdun...@agentintellect.com] Sent: Friday, October 02, 2009 2:58 PM To: php-general@lists.php.net; Daevid Vincent Subject: Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo mind-blowing. What the heck /is/ supposed to happen when you do this: $a = 2; $a = $a++; echo $a; Seems like any way you slice it the output should be 3. I guess what's ... and, in fact, that /is/ how C behaves. The following code: int a = 2; a = a++; printf(a = [%d]\n, a); Will output a = [3]. At least on Ubuntu 9 using gcc 4.3.3. So I retract my initial terse reply and apologize for misunderstanding your question. Ben EXACTLY! :) God (or diety of your choice) bless you for getting what I'm saying and proving that it's not C like either. That just adds credence to my/our argument. d Well, Daevid, I still do appreciate the difference between $a = 1; $b = $a++; // $b should be 1 and $a = $a++; $b = $a; // $b should be 2 unless PHP manages to exhibit some overlay problem (read: bug) for $a in the 2nd case. True? joost. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Finding out DST with PHP
I was hoping someone might be able to help me with something. In a recent effort to learn PHP/mySQL, I decided to design a mock forum. Many forums (such as phpBB) allow a user to pick their timezone and to select if DST should be applied. I'm trying to figure out how its done. Currently, I'm saving all times as GMT, having set the default timezone to 'Europe/London'. I then found this list of timezones: http://unicode.org/repos/cldr/trunk/docs/design/formatting/zone_log.html#windows_ids The issue I'm having trouble with now is DST. I just learned that not all timezones start DST on the same day, nor do they all add one hour. According to http://www.php.net/manual/en/datetime.getoffset.php DateTime::getOffset should give me back the DST offset, but when I have use DateTime::setTimezone to change the timezone and get the local users time, it automatically applies DST if applicable, and setTimezone gives me back -14400 (I'm testing with EST). This is -4 hours, which is the offset from GMT to EST right now. Unless I'm using the funciton wrong, it seems to give the offset from GMT. Can anyone lend me a thought? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php