Re: [PHP] A really wacky design decision
I am well aware of the === operator, but I had an uneasy feeling that there was still a trap. However when I tried it it worked, so I was going to thank you for your suggestion, though I find the concept of having separate 'sort of equal' and 'truly equal' operators decidedly distasteful, but then I discovered that if you have: $a = 2260; $b = 226e1; $c = 2.26e3; $d = 2260.0; $a==$b==$c==$d, and $b===$c===$d Granted $c $d are less likely to be encountered by accident, but if I want to be certain the two strings match I will have to stick to the (string) cast or use strcmp. Perhaps we need a 'really truly equal' operator ! Clancy And then you discover === $i = 0; $j = count ($names); while ($i $j) { if ($names[$i] === $target) { break; } ++$i; } ... regards To: php-general@lists.php.net From: clanc...@cybec.com.au Date: Sat, 3 Oct 2009 21:21:00 +1000 Subject: [PHP] A really wacky design decision Daevid Vincent is surprised that: $num = 123; $num = $num++; print $num; //this prints 123 and not 124 ?!! To me this is relatively logical. As I understand it, the post-increment operator says do something with the variable, and then increment it. The trouble in this case is that we are doing something irrational; we are copying the number back to itself, and to me it is reasonably logical (or at least no less illogical than the alternative) to assume that if we copy it to itself, then increment the original version, the copy will not be incremented. However there is one feature of PHP which, to my mind, is really bad design. How many of you can see anything wrong with the following procedure to search a list of names for a particular name? $i = 0; $j = count ($names); while ($i $j) { if ($names[$i] == $target) { break; } ++$i; } As long as the names are conventional names, this procedure is probably safe to use. However if you allow the names to be general alphanumeric strings, it is not reliable. One of my programs recently broke down in one particular case, and when I eventually isolated the bug I discovered that it was matching '2260' to '226E1'. (The logic of this is: 226E1 = 226*10^1 = 2260). I agree that I was well aware of this trap, and that I should not have used a simple comparison, but it seems to me to be a bizarre design decision to assume that anything which can be converted to an integer, using any of the available notations, is in fact an integer, rather than making the default to simply treat it as a string. It is also a trap that it is very easy to fall into if you start off thinking about simple names, and then extend (or borrow) the procedure to use more general strings. And can anyone tell me whether, in the above case, it is sufficient to write simply: if ((string) $names[$i] == $target), or should I write: if ((string) $names[$i] == (string) $target)? (I decided to play safe and use strcmp ().) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Windows Live: Keep your friends up to date with what you do online. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A really wacky design decision
On Sat, 03 Oct 2009 11:57:36 -0400, f...@thefsb.org (Tom Worster) wrote: On 10/3/09 7:21 AM, clanc...@cybec.com.au clanc...@cybec.com.au wrote: However there is one feature of PHP which, to my mind, is really bad design. How many of you can see anything wrong with the following procedure to search a list of names for a particular name? $i = 0; $j = count ($names); while ($i $j) { if ($names[$i] == $target) { break; } ++$i; } As long as the names are conventional names, this procedure is probably safe to use. However if you allow the names to be general alphanumeric strings, it is not reliable. One of my programs recently broke down in one particular case, and when I eventually isolated the bug I discovered that it was matching '2260' to '226E1'. (The logic of this is: 226E1 = 226*10^1 = 2260). I agree that I was well aware of this trap, and that I should not have used a simple comparison, but it seems to me to be a bizarre design decision to assume that anything which can be converted to an integer, using any of the available notations, is in fact an integer, rather than making the default to simply treat it as a string. this is odd. i might think it ok for (2260 == '226E1') to be true since php would be doing type juggling in a logical left-to-right manner: we start with an integer 2260, next is the juggling comparison operator, then a string, so it might reasonably try to convert the string to an integer and then compare. but with ('2260' == '226E1'), where both lhs and rhs are already of the same time, it seems elliptical, to say the least, that php should search the types to which it can convert the strings looking for one in which they are equal. The order doesn't matter; 2260 == 226e1, and 226e1==2260. It looks as if (for comparisons) PHP's order of preference is Integer Real ?? ?? String. If you use '==' it will try to convert everything to integer, but if you use '===' it will try to render them in some standard format (so that 226e1 === 2.26e3), but will not convert real to integer. Despite which if you print them without specifying a format it will print them all as 2260. All very messy! Clancy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] A really wacky design decision
$a = 2260; $b = 226e1; $c = 2.26e3; $d = 2260.0; $a==$b==$c==$d, and $b===$c===$d $b , $c, and $d are the same indeed ... they represent the floating point 2260.0 in I think every language ... it's like saying that 1.0 is not 1. ... both floating point numbers, so I don't get your problem ... _ Windows Live: Make it easier for your friends to see what you’re up to on Facebook. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009
RE: [PHP] A really wacky design decision
All very messy! there is nothing messy, the logic is well defined and for a loose type language it's absolutely normal behavior. Regards _ Keep your friends updated—even when you’re not signed in. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010
RE: [PHP] Self-Process php forms or not?
Thanks a lot. To all. For the moment, I'm with the redirect solution that others have pointed. But after seen tedd example and watch Manuel videos, I'm starting to understand how the hidden field solution work as well. Well... I'm *starting* to understand I've not fully understand it yet, despite all your great examples. Because the structure of the code with hidden fields, seems quite different from the structure I have right now and I'm unable to make the switch. Here is the actual structure: if (isset($_POST['submit'])) { //declare variables $var = $_POST['var']; etc... //validate //process the form (send e-mail or save to database etc...) //redirect to success page. } else { Echo Sorry, couldn't process the form; } html form I suppose that the echo message telling we couldn't process the form does not appear when the form first loads, because the server side script is not requested on load, it is requested when the form submits to the php code presented on that same page (self). Tom Worster, is this precise? In the future, I will print tedd example, and Manuel scheme, and try to change the code above to accommodate hidden fields, because I still prefer having only one file. Thank you all once again, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] class to generate Javascript Object ??
I wrote a php class to generate flowplayer/html5 media code for my site: http://www.shastaherps.org/xml_MMmediaClass.phps The buildFlashvars() function in it is really ugly and will be a pain to update as I modify the class in the future. What it does is generate a JavaScript object string, as described here: http://flowplayer.org/tools/flashembed.html I'm thinking (hoping) there is already a php class somewhere for generating JavaScript object strings that I can instead of my ugly easily breakable way of doing it. Anyone know of one? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A really wacky design decision
On 10/4/09 6:36 AM, clanc...@cybec.com.au clanc...@cybec.com.au wrote: i might think it ok for (2260 == '226E1') to be true since php would be doing type juggling in a logical left-to-right manner: we start with an integer 2260, next is the juggling comparison operator, then a string, so it might reasonably try to convert the string to an integer and then compare. but with ('2260' == '226E1'), where both lhs and rhs are already of the same time, it seems elliptical, to say the least, that php should search the types to which it can convert the strings looking for one in which they are equal. The order doesn't matter; 2260 == 226e1, and 226e1==2260. in those two cases, all four operands are integer literals. no juggling is involved. and i would have expected the same for ('2260' == '226e1') and ('226e1' == '2260') since all operands are string literals and i'd be wrong. (evidently i'm not alone in making this mistake.) i get confused reading the manual: http://www.php.net/manual/en/language.types.type-juggling.php says that the context determines if the expression is converted. the example being the + operator. by definition, it's operands are numeric contexts so strings are converted. fair enough. now what about the == operator? http://www.php.net/manual/en/language.operators.comparison.php that page contradicts the previous one because it says that, when an operand is a string, the determination to convert an operand depends not on the context but on the specific data _of_ the operand. i think robert captured the essence of this confusion nicely with: On 10/3/09 1:53 PM, Robert Cummings rob...@interjinn.com wrote: Numeric strings are special :) -- 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 10/4/09 9:25 AM, MEM tal...@gmail.com wrote: Thanks a lot. To all. For the moment, I'm with the redirect solution that others have pointed. But after seen tedd example and watch Manuel videos, I'm starting to understand how the hidden field solution work as well. Well... I'm *starting* to understand I've not fully understand it yet, despite all your great examples. Because the structure of the code with hidden fields, seems quite different from the structure I have right now and I'm unable to make the switch. Here is the actual structure: if (isset($_POST['submit'])) { //declare variables $var = $_POST['var']; etc... //validate //process the form (send e-mail or save to database etc...) //redirect to success page. } else { Echo Sorry, couldn't process the form; } html form I suppose that the echo message telling we couldn't process the form does not appear when the form first loads, because the server side script is not requested on load, it is requested when the form submits to the php code presented on that same page (self). Tom Worster, is this precise? i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. in your structure you branch only two ways. i think you need three ways: 1 - the user simply arrived at the form. there is no POST data. the form was not submitted. 2 - there is POST data. the form was submitted. 2a - the POST data is unacceptable. 2b - the POST data is good. in branches 1 and 2a you send the form. in 2b, you send some other page or a redirect. in 1 you send the form blank. in 2a you might fill some form elements with data from POST and add some annotations to the form so the user knows what she or he did wrong. In the future, I will print tedd example, and Manuel scheme, and try to change the code above to accommodate hidden fields, because I still prefer having only one file. one can learn a lot reading other people's code. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class to generate Javascript Object ??
On 10/4/09 9:39 AM, Michael A. Peters mpet...@mac.com wrote: I wrote a php class to generate flowplayer/html5 media code for my site: http://www.shastaherps.org/xml_MMmediaClass.phps The buildFlashvars() function in it is really ugly and will be a pain to update as I modify the class in the future. What it does is generate a JavaScript object string, as described here: http://flowplayer.org/tools/flashembed.html I'm thinking (hoping) there is already a php class somewhere for generating JavaScript object strings that I can instead of my ugly easily breakable way of doing it. Anyone know of one? would json_encode() work for you... ? http://www.php.net/manual/en/function.json-encode.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] class to generate Javascript Object ??
I'm thinking (hoping) there is already a php class somewhere for generating JavaScript object strings that I can instead of my ugly easily breakable way of doing it. Anyone know of one? json_encode http://uk3.php.net/manual/en/function.json-encode.php Regards _ Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009
RE: [PHP] Self-Process php forms or not?
i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. Ok... but please have a look here, I've uploaded and tested that code, and I can assure you that the message doesn't appear when the form first load: http://pastebin.com/m21078fe3 Note: if you use: copy to clipboard option the numbers will gone. Regards, Márcio -- 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:39 PM +0100 10/4/09, MEM wrote: i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. Ok... but please have a look here, I've uploaded and tested that code, and I can assure you that the message doesn't appear when the form first load: http://pastebin.com/m21078fe3 Note: if you use: copy to clipboard option the numbers will gone. Regards, Márcio The problem, as I see it, is that you are not willing to write a simple example and get that to work. Instead, you complicate things beyond your ability to understand. My advice, step back -- write a simple example that does what you want and then expand it. 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
[PHP] a trivial little function (PostToHost)
Hi gang: The following 'trivial little' function I'm trying to get my head around: http://aspn.activestate.com/ASPN/Mail/Message/php-general/1259426 The article states: Either way, just generate your XML string and fire it at the remote machine. You will need to write code to handle the response, obviously. Okay, so how does one handle the response? I understand that one should have the script at host A sending data to host B, but I can't seem to get it to work. Does anyone have an example that works? My confusion here -- is the data sent by the function at host A accessible by host B via a POST, or does it write to a writable file, or what? Any help would be appreciated. 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] Header problem
Andrea Giammarchi wrote on 2009-10-03 13:40: Do you want users download the file or the zip? They can choose between the two. do you send other headers before the download? Header must come first (before you output anything) or you get a parse error, so I'm not sure what you mean here? You can see the source of the class at the testpage I linked to. It's quite a common error to set a default header in PHP at the beginning of whatever application, while header should be used as last exit point and never in the middle, or at the beginning, of a response. I'm not sure what you mean by this? My download.php first checks for the relevant data is there (track_id/version_id, a session with member_id), then if the download is allowed (by access or if it has already been downloaded) then it fetches the relevant files, zip these to the disk and first then... creates the zip header and afterwards uses a readfile on the zipfile just created. Moreover, if you use readfile and then zip what do you expect, multiple downloads in one? This is not how HTTP work ... so please show more php, or explain better what you would like to do. What do you need to see besides the testpage? If I have 4 mp3 files of 5mb each, these will be zipped into one 20mb file, and that is of course only one download. That's the wish from the siteowner: easier download of several mixes of the same artist/track I hope this makes the problem more clear to you :-) I've debugged some more into the problem, this is a header of a zip download where the site works as expected: HTTP/1.x 200 OK Date: Sat, 03 Oct 2009 22:26:45 GMT Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_ssl/2.2.8 OpenSSL/0.9.8g X-Powered-By: PHP/5.2.4-2ubuntu5.6 Accept-Ranges: bytes Content-Length: 7083675 Content-Disposition: attachment; filename=Maxwell - Bad Habits (Remixes) (index.php=get_zip).zip Content-Transfer-Encoding: binary Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: application/zip I call the file like this: index.php?get_zip=test_output.zip index.php does this: $new_zipfile .= $_SESSION['download_title']..zip; /* header(Cache-Control: no-cache); header(Pragma: no-cache); header(Expires: now); */ header('Accept-Ranges: bytes'); header(Content-Type: application/zip); header(Content-Length: .filesize($archiveName)); header(Content-Disposition: attachment; filename=\$new_zipfile\); header(Content-Transfer-Encoding: binary); readfile($archiveName); exit; The outcommented headers was put in because I discovered that the download then was cached after giving the file a strange name, that name never occured in the download :-/ I've ended up by making a workaround by adding nocache=.microtime(). to the get_zip link but then the site freezes againg during the download, arrrghh... And headers from the original zip solution in download.php, headers are set in function.inc, this is the output from Live HTTP headers: HTTP/1.x 200 OK Date: Sat, 03 Oct 2009 21:41:49 GMT Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_ssl/2.2.8 OpenSSL/0.9.8g X-Powered-By: PHP/5.2.4-2ubuntu5.6 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Accept-Ranges: bytes Content-Length: 35756585 Content-Disposition: attachment; filename=Maxwell - Bad Habits (Remixes).zip Content-Transfer-Encoding: binary Keep-Alive: timeout=15, max=98 Connection: Keep-Alive Content-Type: application/zip difference to the returned zip headers in index.php is pragma, cache-control and expires, so I've removed these headers from the function, but they still show up: HTTP/1.x 200 OK Date: Sat, 03 Oct 2009 22:25:36 GMT Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_ssl/2.2.8 OpenSSL/0.9.8g X-Powered-By: PHP/5.2.4-2ubuntu5.6 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Accept-Ranges: bytes Content-Length: 7083675 Content-Disposition: attachment; filename=Maxwell - Bad Habits (Remixes).zip Content-Transfer-Encoding: binary Keep-Alive: timeout=15, max=96 Connection: Keep-Alive Content-Type: application/zip So I think my problem is cache related in some way. Kind regards Kim Date: Sat, 3 Oct 2009 13:30:38 +0200 From: php@emax.dk To: php-general@lists.php.net Subject: [PHP] Header problem Hi PHP people I have a really strange and annoying problem. I've got a site, where members can download music. User clicks index.php (in index.php there's an iframe, that opens another file), if certain check are okay then a popup window opens download.php, where a mp3 file is fetched from the server and renamed in the header, then pushed to the
Re: [PHP] Header problem
Hi kranthi kranthi wrote on 2009-10-03 16:21: Thats a lot of headers to read.. At a first glance I can see that you did not specify a content-length header. this is a must and must be equal to the size of the file in bytes I've noticed that too, but it's impossiple to determine the length of the zipfile, when creating the file in memory. Instead I'm now writing the file to disk and uses filesize on the zipfile to get the length for Content-Length, then I use readfile(zipfile.zip) instead of echo $zip-file(); But the result is still the same :-/ Kind regards Kim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Header problem
On Sun, 2009-10-04 at 18:10 +0200, Kim Madsen wrote: Hi kranthi kranthi wrote on 2009-10-03 16:21: Thats a lot of headers to read.. At a first glance I can see that you did not specify a content-length header. this is a must and must be equal to the size of the file in bytes I've noticed that too, but it's impossiple to determine the length of the zipfile, when creating the file in memory. Instead I'm now writing the file to disk and uses filesize on the zipfile to get the length for Content-Length, then I use readfile(zipfile.zip) instead of echo $zip-file(); But the result is still the same :-/ Kind regards Kim Afaik, the content length header is not necessary, but it will cause problems if it's set and it's wrong. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] Header problem
Header must come first (before you output anything) or you get a parse error I try to better explain ... HTTP works like this: you ask something, you receive something, html and texts are just one option. Your example page mess up html, zip, everything, because when you download a file you still have the rest of the page sent in the output. A download should have ONLY file related info/headers and nothing else in the output ... echo/print in the middle of the code before an header is an error, everything in output before an header is an error, everything after headers that is not related to that header is an error, got my point? To decide how a page should behave, you must be able to do not produce anything except the expected output with expected headers, that's why I have said headers are fundamental for a response, we cannot play with outputs however we want. As summary, once you have created and tried a dedicated page without a single white space or print before, during, or after the dedicated download stuff, I'll try to understand where is the error. Otherwise it could be everything, and I am against magic behaviors ... you need to download? Well, create a file which aims id to download and nothing else, or you gonna constantly find these kind of problems in your applications. Regards _ Keep your friends updated—even when you’re not signed in. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010
RE: [PHP] Header problem
Afaik, the content length header is not necessary, but it will cause problems if it's set and it's wrong. correct, missed Content-Length means the classic download with useless progress bar and undefined estimation time, problematic for preloader as well in case of images, swf, generic data, etc. Content_length should be always present and it should be correct, but obviously if there are print or echo or other outputs non file related, Content-Length can simply mess up the response. _ Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
Re: [PHP] Header problem
Hello Andrea Andrea Giammarchi wrote on 2009-10-04 18:49: Header must come first (before you output anything) or you get a parse error I try to better explain ... HTTP works like this: you ask something, you receive something, html and texts are just one option. Got it so far Your example page mess up html, zip, everything, because when you download a file you still have the rest of the page sent in the output. Nops, not really. index.php: print stuff do stuff open download.php in a _new_ window. print more stuff page end this should be possible, right? Two different headers for two different pages. A download should have ONLY file related info/headers and nothing else in the output ... echo/print in the middle of the code before an header is an error, everything in output before an header is an error, everything after headers that is not related to that header is an error, got my point? Jep! And that's actually what I do. What I could, is to add exit; after the headers have been sent and the file have been pushed. I do an update of the database to tell the system that the files in the zipfile has been downloaded. To decide how a page should behave, you must be able to do not produce anything except the expected output with expected headers, that's why I have said headers are fundamental for a response, we cannot play with outputs however we want. The only output is the headers of the zipfile: header('Accept-Ranges: bytes'); header(Content-Type: application/zip); header(Content-Length: $size); header(Content-disposition: attachment; filename=\.basename($zip_filename).\); header(Content-Transfer-Encoding: binary); readfile($filename); // we need to reload top5 to have a current view unset($_SESSION['top5']); $_SESSION['reload_top5'] = 1; // NOTE second param shall be an array, not a variable when downloading zip files download_completed($member_id, $downloaded_version_ids); Wouldn't you say this is okay? As summary, once you have created and tried a dedicated page without a single white space or print before, during, or after the dedicated download stuff, I'll try to understand where is the error. Otherwise it could be everything, and I am against magic behaviors ... you need to download? Well, create a file which aims id to download and nothing else, or you gonna constantly find these kind of problems in your applications. I believe the testpage does forfill that request? Or do you mean otherwise? Kind regards Kim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Header problem
Unless I am missing something, your page has too many if and it always ends up with print something ... but there is no exit after the download, so the zip will have extra output included without a reason ... which is an error, imho, dunno how else explain if you can't see your print links at the end of the page ... Regards Date: Sun, 4 Oct 2009 19:09:35 +0200 From: php@emax.dk To: php-general@lists.php.net Subject: Re: [PHP] Header problem Hello Andrea Andrea Giammarchi wrote on 2009-10-04 18:49: Header must come first (before you output anything) or you get a parse error I try to better explain ... HTTP works like this: you ask something, you receive something, html and texts are just one option. Got it so far Your example page mess up html, zip, everything, because when you download a file you still have the rest of the page sent in the output. Nops, not really. index.php: print stuff do stuff open download.php in a _new_ window. print more stuff page end this should be possible, right? Two different headers for two different pages. A download should have ONLY file related info/headers and nothing else in the output ... echo/print in the middle of the code before an header is an error, everything in output before an header is an error, everything after headers that is not related to that header is an error, got my point? Jep! And that's actually what I do. What I could, is to add exit; after the headers have been sent and the file have been pushed. I do an update of the database to tell the system that the files in the zipfile has been downloaded. To decide how a page should behave, you must be able to do not produce anything except the expected output with expected headers, that's why I have said headers are fundamental for a response, we cannot play with outputs however we want. The only output is the headers of the zipfile: header('Accept-Ranges: bytes'); header(Content-Type: application/zip); header(Content-Length: $size); header(Content-disposition: attachment; filename=\.basename($zip_filename).\); header(Content-Transfer-Encoding: binary); readfile($filename); // we need to reload top5 to have a current view unset($_SESSION['top5']); $_SESSION['reload_top5'] = 1; // NOTE second param shall be an array, not a variable when downloading zip files download_completed($member_id, $downloaded_version_ids); Wouldn't you say this is okay? As summary, once you have created and tried a dedicated page without a single white space or print before, during, or after the dedicated download stuff, I'll try to understand where is the error. Otherwise it could be everything, and I am against magic behaviors ... you need to download? Well, create a file which aims id to download and nothing else, or you gonna constantly find these kind of problems in your applications. I believe the testpage does forfill that request? Or do you mean otherwise? Kind regards Kim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009
Re: [PHP] Self-Process php forms or not?
On 10/4/09 10:39 AM, MEM tal...@gmail.com wrote: i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. Ok... but please have a look here, I've uploaded and tested that code, and I can assure you that the message doesn't appear when the form first load: http://pastebin.com/m21078fe3 Note: if you use: copy to clipboard option the numbers will gone. this has a different structure from what you showed us in your email earlier today (Sunday, October 4, 2009 9:25 AM). this script has the structure: ?php $erros=array(); if(isset($_POST['submit'])) { ... if (!$erros) { ... // all done, now redirect: Redireciona(gracias.html); } else { echo (Sorry. The form couldn't be processed.); } } ? as i said before, a script will execute regardless. but this new script fragment does nothing except initialize $erros if $_POST['submit'] is not set (e.g. if the user requests the page without POSTing the form). i don't see a problem. this script also has the three cases i described clearly separated. now, what was your question? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class to generate Javascript Object ??
Tom Worster wrote: On 10/4/09 9:39 AM, Michael A. Peters mpet...@mac.com wrote: I wrote a php class to generate flowplayer/html5 media code for my site: http://www.shastaherps.org/xml_MMmediaClass.phps The buildFlashvars() function in it is really ugly and will be a pain to update as I modify the class in the future. What it does is generate a JavaScript object string, as described here: http://flowplayer.org/tools/flashembed.html I'm thinking (hoping) there is already a php class somewhere for generating JavaScript object strings that I can instead of my ugly easily breakable way of doing it. Anyone know of one? would json_encode() work for you... ? http://www.php.net/manual/en/function.json-encode.php Yes - it worked beautifully :) Thank you. -- 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 10/4/09 10:55 AM, tedd tedd.sperl...@gmail.com wrote: At 3:39 PM +0100 10/4/09, MEM wrote: i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. Ok... but please have a look here, I've uploaded and tested that code, and I can assure you that the message doesn't appear when the form first load: http://pastebin.com/m21078fe3 Note: if you use: copy to clipboard option the numbers will gone. Regards, Márcio The problem, as I see it, is that you are not willing to write a simple example and get that to work. Instead, you complicate things beyond your ability to understand. My advice, step back -- write a simple example that does what you want and then expand it. i agree that it does seem a bit as though Márcio is in such a hurry to make something work that the tasks of learning and understanding the fundamentals are being left aside. while that's maybe understandable, it's a bit frustrating when we're trying to explain the fundamentals. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [SOLVED] class to generate Javascript Object ??
Andrea Giammarchi wrote: I'm thinking (hoping) there is already a php class somewhere for generating JavaScript object strings that I can instead of my ugly easily breakable way of doing it. Anyone know of one? json_encode http://uk3.php.net/manual/en/function.json-encode.php Thank you, worked beautifully. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strtotime strangeness
For some reason the strtotime is no longer returning the year portion. For example, strtotime(10/04/2009) will result in a date of -10-04. This started happening recently and I haven't done any updates other than the normal OS updates. I am running Mac OS X 10.5.8. Does anyone have any ideas or do I just need to install the latest version of PHP? Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] [SOLVED] class to generate Javascript Object ??
Thank you, worked beautifully. just don't ignore this: PHP 5 = 5.2.0 if you are trying to create something portable, you should consider a Pear fallback ... if(!function_exists('json_encode')){ require_once 'JSON.phps'; // http://mike.teczno.com/JSON/JSON.phps function json_encode($o){ $json = new Services_JSON; return $json-encode($o); } } Regards _ Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009
RE: [PHP] strtotime strangeness
Did the OS update changed the default locale settings or the default date format? From: fres...@adex-intl.com To: php-general@lists.php.net Date: Sun, 4 Oct 2009 14:05:05 -0400 Subject: [PHP] strtotime strangeness For some reason the strtotime is no longer returning the year portion. For example, strtotime(10/04/2009) will result in a date of -10-04. This started happening recently and I haven't done any updates other than the normal OS updates. I am running Mac OS X 10.5.8. Does anyone have any ideas or do I just need to install the latest version of PHP? Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Windows Live: Make it easier for your friends to see what you’re up to on Facebook. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009
Re: [PHP] Header problem
Original Message From: Kim Madsen php@emax.dk To: php-general@lists.php.net Sent: Sun, October 4, 2009 9:10:36 AM Subject: Re: [PHP] Header problem Hi kranthi kranthi wrote on 2009-10-03 16:21: Thats a lot of headers to read.. At a first glance I can see that you did not specify a content-length header. this is a must and must be equal to the size of the file in bytes I've noticed that too, but it's impossiple to determine the length of the zipfile, when creating the file in memory. Instead I'm now writing the file to disk and uses filesize on the zipfile to get the length for Content-Length, then I use readfile(zipfile.zip) instead of echo $zip-file(); But the result is still the same :-/ Kind regards Kim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php If you want to take advantage of chunked-transfer encoding, you can not specify 'content-length'. -- 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 agree that it does seem a bit as though Márcio is in such a hurry to make something work that the tasks of learning and understanding the fundamentals are being left aside. while that's maybe understandable, it's a bit frustrating when we're trying to explain the fundamentals. Thanks a lot. Tedd, Tom, I perfectly understand. I can only apologize. Unfortunately, I'm really REALLY on a rush. But as an additional information, I'm marking all this e-mails for latter reference and study. as i said before, a script will execute regardless. but this new script fragment does nothing except initialize $erros if $_POST['submit'] is not set (e.g. if the user requests the page without POSTing the form). i don't see a problem. this script also has the three cases i described clearly separated. now, what was your question? None. I've not properly see the structure that I was in, and according to that mistake, I've taking wrong conclusions. But thanks for pointing it out. Regards and, once again, thanks for your feedback, and I'm really sorry for not been able to properly learn with your advices. :s Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] a trivial little function (PostToHost)
tedd tedd.sperl...@gmail.com wrote on 10/04/2009 08:51:13 AM: [PHP] a trivial little function (PostToHost) tedd to: php-general 10/04/2009 09:05 AM Hi gang: The following 'trivial little' function I'm trying to get my head around: http://aspn.activestate.com/ASPN/Mail/Message/php-general/1259426 The article states: Either way, just generate your XML string and fire it at the remote machine. You will need to write code to handle the response, obviously. Okay, so how does one handle the response? I understand that one should have the script at host A sending data to host B, but I can't seem to get it to work. Does anyone have an example that works? My confusion here -- is the data sent by the function at host A accessible by host B via a POST, or does it write to a writable file, or what? Any help would be appreciated. Cheers, tedd Yes, this is just a standard HTTP POST, just like what a browser does when you click a submit button. So, there needs to be a script that handles a standard POST on server B. It will send whatever response it is designed to. Just think of server A as a browser submitting a form and server B is you writing a PHP script to handle the form submission :) Typically, I write the fgets line a little differently. Instead of: while(!feof($fp)) { echo fgets($fp, 128); } I use: $response = ''; while(!feof($fp)) { $response .= fgets($fp, 128); } // parse the response and do something Kirk
Re: [PHP] strtotime strangeness
I couldn't find anything in the php.ini file to account for this. I am running PHP 5.2.10. I've never actually updated it myself so the software updater updated it at some point. I did a little test and found out that date(:Y,$timestamp) returns . However, date(y, $timestamp) returns the two digit year properly. So it seems there is an issue with the four digit year. Thanks! Floyd On Oct 4, 2009, at 2:14 PM, Andrea Giammarchi wrote: Did the OS update changed the default locale settings or the default date format? From: fres...@adex-intl.com To: php-general@lists.php.net Date: Sun, 4 Oct 2009 14:05:05 -0400 Subject: [PHP] strtotime strangeness For some reason the strtotime is no longer returning the year portion. For example, strtotime(10/04/2009) will result in a date of -10-04. This started happening recently and I haven't done any updates other than the normal OS updates. I am running Mac OS X 10.5.8. Does anyone have any ideas or do I just need to install the latest version of PHP? Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Windows Live: Make it easier for your friends to see what you’re up to on Facebook.
Re: [PHP] [SOLVED] class to generate Javascript Object ??
Andrea Giammarchi wrote: Thank you, worked beautifully. just don't ignore this: PHP 5 = 5.2.0 if you are trying to create something portable, you should consider a Pear fallback ... I make heavy use of DOMDocument so I need 5.2.x anyway. But thanks for the warning. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strtotime strangeness
- Original Message From: Floyd Resler fres...@adex-intl.com To: Andrea Giammarchi an_...@hotmail.com Cc: php-general@lists.php.net Sent: Sun, October 4, 2009 12:01:30 PM Subject: Re: [PHP] strtotime strangeness I couldn't find anything in the php.ini file to account for this. I am running PHP 5.2.10. I've never actually updated it myself so the software updater updated it at some point. I did a little test and found out that date(:Y,$timestamp) returns . However, date(y,$timestamp) returns the two digit year properly. So it seems there is an issue with the four digit year. Thanks! Floyd snip i hope :Y is a typo in the email and not in your code. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with mod_php
Original Message From: JC jcflo...@cablenet.com.pe To: php-general@lists.php.net Sent: Sat, October 3, 2009 12:22:21 PM Subject: [PHP] problem with mod_php I'm trying to install a webmail in a new server with the following items: Debian 2.6.26-2-amd64 horde 3.2.2 imp 4.2.4 apache 2.2.9 php 5.2.6 when I try to install for the first time to configure it by web, it show the following: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. And the log (apache2 error.log) shows the following: [Wed Sep 30 12:31:26 2009] [error] [client 200.60.166.10] (13)Permission denied: exec of '/var/www/horde3/login.php' failed [Wed Sep 30 12:31:26 2009] [error] [client 200.60.166.10] Premature end of script headers: login.php These are the permissions -r--r--r-- 1 www-data www-data 8740 ene 29 2009 login.php smtp:/var/www# ls -l lrwxrwxrwx 1 root root 18 sep 27 22:31 horde3 - /usr/share/horde3/ smtp:/usr/share# ls -l drwxr-xr-x 18 www-data www-data 4096 sep 27 17:09 horde3 I hope you can help to resolve this problem What's the file permission for /var/www/horde3/login.php since PHP has error reading/executing the file? When you changed the permission for /usr/share/horde3, did you use '-R' ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strtotime strangeness
Yeah, the ;Y was a typo in my email. That's what happens while trying to type while watching my Colts play! Thanks! Floyd On Oct 4, 2009, at 3:06 PM, Tommy Pham wrote: - Original Message From: Floyd Resler fres...@adex-intl.com To: Andrea Giammarchi an_...@hotmail.com Cc: php-general@lists.php.net Sent: Sun, October 4, 2009 12:01:30 PM Subject: Re: [PHP] strtotime strangeness I couldn't find anything in the php.ini file to account for this. I am running PHP 5.2.10. I've never actually updated it myself so the software updater updated it at some point. I did a little test and found out that date(:Y,$timestamp) returns . However, date(y,$timestamp) returns the two digit year properly. So it seems there is an issue with the four digit year. Thanks! Floyd snip i hope :Y is a typo in the email and not in your code. -- 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
Re: [PHP] strtotime strangeness
On Sun, Oct 4, 2009 at 3:22 PM, Floyd Resler fres...@adex-intl.com wrote: Yeah, the ;Y was a typo in my email. That's what happens while trying to type while watching my Colts play! Thanks! Floyd Go Colts! At least you get to watch it, I have to follow along on sports sites! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strtotime strangeness
Sorry to hear that! I live in Cincinnati so I normally don't get to watch the Colts play when they are on at the same time as the Bengals. But this week I did and, best of all, they won! On Oct 4, 2009, at 3:24 PM, Eddie Drapkin wrote: On Sun, Oct 4, 2009 at 3:22 PM, Floyd Resler fres...@adex-intl.com wrote: Yeah, the ;Y was a typo in my email. That's what happens while trying to type while watching my Colts play! Thanks! Floyd Go Colts! At least you get to watch it, I have to follow along on sports sites! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php