Re: [PHP] Re: Setting headers for file download
I was working on a script that was supposed to generate PDF files on the fly and ran into the same problem as you described. MS IE has always been and will always be (?) a P.I.T.A. when it comes to following standards (I am not really sure if the header application/x- octet-steam is a standrad in order to force a download). I came up with this little helper: ?php $filename = example.pdf; $len = filesize ($filename ); if ( ( preg_match('|MSIE ([0-9.]+)|', $agent, $version ) ) || ( preg_match( '|Internet Explorer/([0-9.]+)|', $agent, $version ) ) ) { header( 'Content-Type: application/x-msdownload' ); header( 'Content-Length: ' . $len ); if ( $version == '5.5' ) { header( 'Content-Disposition: filename=' . $filename . '' ); } else { header( 'Content-Disposition: attachment; filename=' . $filename . '' ); } } else { header( 'Content-Type: application/pdf' ); header( 'Content-Length: ' . $len ); header( 'Content-disposition: attachment; filename=' . $filename ); } echo file_get_contents($filename); ? All browsers I have tested with do show the download frame (Opera, Safari, IE, Firefox, Mozilla browsers). But, as Richard already mentioned, I had to fake the download URL, like http:// www.site.com/downloads/example.pdf. In the folder downloads I put a .htaccess file with the line ErrorDocument 404 /link/to/my/php/ script.php. /frank 14 jun 2006 kl. 02.19 skrev Peter Lauri: I will try that after golf... -Original Message- From: Rafael [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 14, 2006 6:28 AM To: php-general@lists.php.net Subject: [PHP] Re: Setting headers for file download I use something like this... $file_len = filesize($file_name); $file_ts = filemtime($file_name); header('Content-Type: application/x-octet-stream'); // none known header('Cache-Control: must-revalidate, post-check=0, pre- check=0'); header('Last-Modified: '. gmdate('D, d M Y H:i:s', $file_ts) .' GMT'); header('Content-Disposition: attachment; filename='. basename($file_name) .''); header(Content-Length: $file_len); readfile($file_name); Peter Lauri wrote: Best group member, This is how I try to push files to download using headers: header(Content-type: $file_type); header(Content-Disposition: attachment; filename=$filename); print $file; It works fine in FireFox, but not that good in IE. I have been googled to find the fix for IE, but I can not find it. Anyone with experience of this? Best regards, Peter Lauri -- Atentamente / Sincerely, J. Rafael Salazar Magaña -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP6 build help
Only if (s)he''s on a debian based linux distro. I see from his configure output, that he's on Linux, but what makes you think he's on Debian ( or on a system with apt-rpm ) ? Run this command: sudo apt-get build-dep php5 This will get you all the packages needed to build php5, which should be most of what is needed for php6. Rabin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetText string not found
Is strange that there is not a really good solution for this problem, i think its not very strange. Maybe i ll request this feature, I think is interesting, useful and not so hard to add. Anyway, I cannot use ob_ functions, i ll have problems with some functions. So, the solution seems to extend _ function, that provides me the posibility to report strings not found. The bad think is that I ll have to make thousands of modifications in order to implement this feature in the webpage :( Thanks to everybody! Richard Lynch wrote: On Tue, June 13, 2006 6:30 am, Ruben Rubio Rey wrote: I am using gettext to get a web page in several languages. When gettext does not found an string, it shows the string. Is it possible to detect when a string is not found, in order to advis me ? My experience, if you call it that, with gettext consists of reading the manual and saying Neat!, so take this with a HUGE grain of salt... One option that MIGHT work would be: function ___ ($string) { //check for existince of the language file/string by hand :-( } Another option, perhaps, would be to have your default language be something really... weird, and then the output itself would be icky... I suppose you could do something hacky like: ?php ob_start(); __'GETTEXT_START_MARKER This is the actual message GETTEXT_END_MARKER'; ? All code/html here. ?php $output = ob_get_contents(); preg_match_all('/GETTEXT_START_MARKER (.*) GETEXT_END_MARKER/U', $output, $gettexts); foreach($gettexts[1] as $unknown){ error_log($unknown); } $output = str_replace(array('GETTEXT_START_MARKER ', ' GETTEXT_END_MARKER'), '', $output); echo $output; ? Ugh. Maybe a Feature Request at GetText and/or bugs.php.net would be in order... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP6 build help
Rabin Vincent wrote: On 6/14/06, Ligaya Turmelle [EMAIL PROTECTED] wrote: Richard Lynch wrote: You realize that compiling PHP6 from CVS is, errr, not really for newbies... :-) Yeah - I know. but I am helping out the php qa team by writing some phpt tests... and they prefer (though don't require) the tests also include the unicode support. which means PHP6. As I told them - guess that means it is time for me to learn something new. You do not seem to have the 'lex' command, which means you probably didn't install 'lex' you can Google for the error message (the last line or two) and find links to how to get it and install 'lex' D'uh. I have never heard of the lex command before... Will search and hopefully install it. Will let you know how it goes. Run this command: sudo apt-get build-dep php5 This will get you all the packages needed to build php5, which should be most of what is needed for php6. Rabin Didn't know I could even do that - thanks. -- life is a game... so have fun. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dettach problem
Hello, Jochem Maas skrev: pure guess work coming up... grape wrote: Hi all, I would like run a php-script via CLI which outputs some information to stdout, and then go into background. I use code similar to this to fork and to dettach the child I/O from the TTY (some error handling removed to improve readability) ? echo Hello from parent\n; if(pcntl_fork()) { exit; } posix_setsid(); fclose( STDIN ); fclose( STDOUT ); fclose( STDERR ); if(pcntl_fork()) { exit; } what happens if you move the fclose() statements after this if() statement? I get the same result. In fact, I tried a *lot* of variations of this code without success. is STDIN et al actually defined? they should be - but we all theory and practice often live on different planets :-) That is very true :-) Yup, the're resource(1) of type (stream) alright. are you using the same sapi in both version (i.e. are you maybe using CGI now iso CLI?) I'm using CLI in both environments. echo This message should NOT go to stdout of parent process\n; ? It works fine using PHP version 5.0.4, but when using PHP version 5.1.2 the output of the child (This message) goes to stdout of the parent process. So if I do: php test.php output Using PHP 5.1.2, the file contains: --- Hello from parent This message should NOT go to stdout of parent process --- Can anybody explain this? I run FreeBSD 6.0-RELEASE... Regards, Grape /Grape -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dettach problem
grape wrote: Hello, ... I get the same result. In fact, I tried a *lot* of variations of this code without success. good man, sorry to hear your not finding the problem - seems to look more like a bug - maybe post some more detailed code? (or does the problem occur with the actual code you sent previously?) is STDIN et al actually defined? they should be - but we all theory and practice often live on different planets :-) That is very true :-) Yup, the're resource(1) of type (stream) alright. are you using the same sapi in both version (i.e. are you maybe using CGI now iso CLI?) I'm using CLI in both environments. sorry I couldn't be of any help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dettach problem
Hello Richard, Richard Lynch skrev: This seems to me like a cogent bug report... http://bugs.php.net/ Yup, I'll report it if we cannot find a explaination in a couple of days. But what does the posix_setsid() bit do? Seems like you could take that out too, no?... Or does that promote the process to be the parent somehow?... Thereby confusing fork into thinking that it's not the child process in some twisted weird way? I read the docs ; But comprehension is not implied. :-) The documentation on posix_setsid() is a bit sparse on php.net, but the manpage for setsid on my FreeBSD system gives: DESCRIPTION The setsid() system call creates a new session. The calling process is the session leader of the new session, is the process group leader of a new process group and has no controlling terminal. The calling process is the only process in either the session or the process group. I found a post on the net describing how to run a PHP-script as a daemon, and the author used posix_setsid() for it to work. Actually, the posix_setsid() isn't really required to disconnect the childs I/O using PHP 5.0.4, I can just do: ? echo Hello from parent\n; if(pcntl_fork()) { exit; } fclose( STDIN ); fclose( STDOUT ); fclose( STDERR ); echo This message should not go to stdout\n; ? This is was I originally had in my code, but after moving to 5.1.2 I started to experiment... :-) A while ago, I discovered that PHP 4.3.10-2 (cli) on a Debian Linux with 2.4.27 kernel misbehaves as well, using posix_setsid() or not. I see the output of the last echo command on stdout of the parent process there also. The plot thickens! /Grape -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php-html rendering
Richard Lynch wrote: On Mon, June 12, 2006 4:49 pm, Jochem Maas wrote: Ryan A wrote: Thanks for the suggestion, I am not too familier with wget but (correct me if i am wrong) wont wget just get the output from the pages ignoreing the links? that's the default behaviour - but wget has about a zillion parameters for controlling its behaviour, it's quite easy to scrap a complete site in one call and change the file extension of all files as you go (including the relevant links in the files that are downloaded). that said it could take a week to figure out all the parameters. ;-) True -- even more than a week, for some of us. :-) well I guessed a week - I never actually got past day three ;-) However I'm pretty sure ONE of the examples right in the man page for wget covers exactly what he wants. :-) ditto. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Problem with the passthru function
Hello All, I have a small php file (test.php) whose code is shown below: ?php $retval=1; $command='/bin/ls'; passthru($command, $retval); print(Exit status: . $retval); ? This test.php works fine when I execute from command prompt as php test.php, but when I access it through web browser, it seems not to be working fine, I get an exit status of 127 (which means command not found). I checked for permissions of ls, gave full path, but still it is failing. Can anybody help me in indentifying what is the potential problem? Thank you, Venkatesh ps: Sorry if this is the wrong mailing list. I have subscribed to this list, so posting here. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP6 build help
On 6/14/06, Rory Browne [EMAIL PROTECTED] wrote: Only if (s)he''s on a debian based linux distro. I see from his configure output, that he's on Linux, but what makes you think he's on Debian ( or on a system with apt-rpm ) ? The first line of Ligaya's email said: Ubuntu Breezy Badger, AMD 64. That's a Debian-based distro. Rabin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dettach problem
grape wrote: Hello Richard, Richard Lynch skrev: This seems to me like a cogent bug report... http://bugs.php.net/ Yup, I'll report it if we cannot find a explaination in a couple of days. as a last resort you might as on internals@lists.php.net as to whether anyone there considers this a possible bug. But what does the posix_setsid() bit do? Seems like you could take that out too, no?... Or does that promote the process to be the parent somehow?... Thereby confusing fork into thinking that it's not the child process in some twisted weird way? I read the docs ; But comprehension is not implied. :-) The documentation on posix_setsid() is a bit sparse on php.net, but the manpage for setsid on my FreeBSD system gives: DESCRIPTION The setsid() system call creates a new session. The calling process is the session leader of the new session, is the process group leader of a new process group and has no controlling terminal. The calling process is the only process in either the session or the process group. I found a post on the net describing how to run a PHP-script as a daemon, and the author used posix_setsid() for it to work. Actually, the posix_setsid() isn't really required to disconnect the childs I/O using PHP 5.0.4, I can just do: ? echo Hello from parent\n; if(pcntl_fork()) { exit; } fclose( STDIN ); fclose( STDOUT ); fclose( STDERR ); echo This message should not go to stdout\n; ? This is was I originally had in my code, but after moving to 5.1.2 I started to experiment... :-) A while ago, I discovered that PHP 4.3.10-2 (cli) on a Debian Linux with 2.4.27 kernel misbehaves as well, using posix_setsid() or not. I see the output of the last echo command on stdout of the parent process there also. The plot thickens! /Grape -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with the passthru function
On 6/14/06, Venkatesh Babu [EMAIL PROTECTED] wrote: I have a small php file (test.php) whose code is shown below: ?php $retval=1; $command='/bin/ls'; passthru($command, $retval); print(Exit status: . $retval); ? This test.php works fine when I execute from command prompt as php test.php, but when I access it through web browser, it seems not to be working fine, I get an exit status of 127 (which means command not found). I checked for permissions of ls, gave full path, but still it is failing. Can anybody help me in indentifying what is the potential problem? Check if safe_mode is on in your php.ini. Turn it off if it is enabled. Rabin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with the passthru function
Hi, Thanks for your response safe_mode is Off but still I'm getting this problem. Thank you, Venkatesh --- Rabin Vincent [EMAIL PROTECTED] wrote: On 6/14/06, Venkatesh Babu [EMAIL PROTECTED] wrote: I have a small php file (test.php) whose code is shown below: ?php $retval=1; $command='/bin/ls'; passthru($command, $retval); print(Exit status: . $retval); ? This test.php works fine when I execute from command prompt as php test.php, but when I access it through web browser, it seems not to be working fine, I get an exit status of 127 (which means command not found). I checked for permissions of ls, gave full path, but still it is failing. Can anybody help me in indentifying what is the potential problem? Check if safe_mode is on in your php.ini. Turn it off if it is enabled. Rabin __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace \\1 yIKES!
On Jun 13, 2006, at 1:58 PM, tedd wrote: At 11:33 AM -0700 6/13/06, sam wrote: Wow this is hard I can't wait till I get the hang of it. Capitalize the first letter of a word. Try: ?php $word = yikes; $word[0]=strtoupper($word[0]); echo($word); ? This blows my mind. What should one think, everything is an array? Well, okay not every but everything that's in linear consecutive order; anything that can be indexed? I was trying to make an array from $word but explode() doesn't take an empty delimiter so I gave up and went for the preg_replace. And hey yo, Jochem, I did RTFM, for hours, I always do before I post to the list. I just missed all the answers in the fine manual this time. Cut me some slack. Where should I wire the Euros to? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace \\1 yIKES!
sam wrote: On Jun 13, 2006, at 1:58 PM, tedd wrote: At 11:33 AM -0700 6/13/06, sam wrote: Wow this is hard I can't wait till I get the hang of it. Capitalize the first letter of a word. Try: ?php $word = yikes; $word[0]=strtoupper($word[0]); echo($word); ? This blows my mind. What should one think, everything is an array? an array is an array. a string is a string. characters in a string can be accessed using array-like notation using the offset postion of the relevant char (elements are zero based) Well, okay not every but everything that's in linear consecutive order; anything that can be indexed? I was trying to make an array from $word but explode() doesn't take an empty delimiter so I gave up and went for the preg_replace. And hey yo, Jochem, I did RTFM, for hours, I always do before I post to the list. I just I'd tell you to RTFM (although I did tell you to read the manual regarding the specifics of using preg_replace()'s 'e' modifier after showing you a working example of how to use it, based on your original code snippet) I did berate the fact that you waited no more than 7 minutes before sending a 'help me' reminder regarding your original post. missed all the answers in the fine manual this time. Cut me some slack. cut you slack? are you a graphic designer or something? Where should I wire the Euros to? my paypal account name is my email address :-) --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] Dettach problem
Hi, Jochem Maas skrev: as a last resort you might as on internals@lists.php.net as to whether anyone there considers this a possible bug. I'll do that. Jochem, Richard - thank you for your input. /Grape -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace \\1 yIKES!
Jochem Maas wrote: I did berate the fact that you waited no more than 7 minutes before sending a 'help me' reminder regarding your original post. While I agree with most of what you are saying, you may want to check that email again. Sams 'for Eyes burning...' email was in response to someone privately suggesing that he use ucfirst. It was *not* a 'help me' reminder, so drop that criticism please. Aside from that, anyone who manages to miss ucfirst when R'ingTFM for this problem should RTFM some more. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace \\1 yIKES!
And hey yo, Jochem, I did RTFM, for hours, I always do before I post to the list. I just I'd tell you to RTFM (although I did tell you to read the manual regarding the specifics of using preg_replace()'s 'e' modifier after showing you a working example of how to use it, based on your original code snippet) Yes, I'm using your example right now to help me learn this preg_replace beast. The php.net page on preg_replace was just to overwhelming for the exhausted state of mind I was in. I did berate the fact that you waited no more than 7 minutes before sending a 'help me' reminder regarding your original post. No, that was a misunderstanding, I was just saying thanks to the guy who said, why not just use ulfirst(). (Which I also missed on the php.net page on strings.) missed all the answers in the fine manual this time. Cut me some slack. cut you slack? are you a graphic designer or something? How did you know? I was 'in' graphics for 30 years before I threw my hands up at that lunatic world and decided to become a programmer. I love the printing industry but ever since the Mac took over everybody went nuts. The printers are still mad, after 15 years, that the Mac took away their razor blades and rubylith. Checks in the mail. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] references for beginner...
Hii all I just joined this forum, I'm beginner of PHP programming. I didn't understand almost all the syntax you're talking about (ups too honest, right?), so please... Does anyone have a kinds of references like soft books or something, which talk about all the syntax, and what for are they (also how to use if necessary) and where can I download it? thank for all references best regard BBC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] references for beginner...
BBC a écrit : Hii all I just joined this forum, I'm beginner of PHP programming. welcome. I didn't understand almost all the syntax you're talking about (ups too honest, right?), so please... Does anyone have a kinds of references like soft books or something, which talk about all the syntax, and what for are they (also how to use if necessary) and where can I download it? http://www.php.net/manual/ could be a good starting point. N F thank for all references best regard BBC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace \\1 yIKES!
Stut wrote: Jochem Maas wrote: I did berate the fact that you waited no more than 7 minutes before sending a 'help me' reminder regarding your original post. While I agree with most of what you are saying, you may want to check that email again. Sams 'for Eyes burning...' email was in response to someone privately suggesing that he use ucfirst. It was *not* a 'help me' reminder, so drop that criticism please. consider it dropped - I didn't catch that it was a reply to an offlist post. Aside from that, anyone who manages to miss ucfirst when R'ingTFM for this problem should RTFM some more. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Setting headers for file download
I got it working on one server, but not the real server. I just took your code and voila it was working (with some modifications). It works on: Localhost Windows Plesk Server running Plesk 7.5 Not working on: Plesk Server running Plesk 7.0 Then the questions is: Where should I start to search in WHY the server is not sending the correct headers? This is becoming more and more irritating :) Best regards, Peter Lauri -Original Message- From: Rafael [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 14, 2006 6:28 AM To: php-general@lists.php.net Subject: [PHP] Re: Setting headers for file download I use something like this... $file_len = filesize($file_name); $file_ts = filemtime($file_name); header('Content-Type: application/x-octet-stream'); // none known header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Last-Modified: '. gmdate('D, d M Y H:i:s', $file_ts) .' GMT'); header('Content-Disposition: attachment; filename='. basename($file_name) .''); header(Content-Length: $file_len); readfile($file_name); Peter Lauri wrote: Best group member, This is how I try to push files to download using headers: header(Content-type: $file_type); header(Content-Disposition: attachment; filename=$filename); print $file; It works fine in FireFox, but not that good in IE. I have been googled to find the fix for IE, but I can not find it. Anyone with experience of this? Best regards, Peter Lauri -- Atentamente / Sincerely, J. Rafael Salazar Magaña -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Setting headers for file download
Peter Lauri schrieb: Best group member, This is how I try to push files to download using headers: header(Content-type: $file_type); header(Content-Disposition: attachment; filename=$filename); print $file; It works fine in FireFox, but not that good in IE. I have been googled to find the fix for IE, but I can not find it. Anyone with experience of this? Best regards, Peter Lauri There ya go: // fix for IE catching or PHP bug issue header(Pragma: public); header(Expires: 0); // set expiration time header(Cache-Control: must-revalidate, post-check=0, pre-check=0); // browser must download file from server instead of cache // force download dialog header(Content-Type: application/force-download); header(Content-Type: application/octet-stream); header(Content-Type: application/download); // use the Content-Disposition header to supply a recommended filename and // force the browser to display the save dialog. header(Content-Disposition: attachment; filename=.$path.;); header(Content-Transfer-Encoding: binary); header(Content-Length: .filesize($file)); readfile($file); -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Setting headers for file download
That did it, thanks... Ok, my knowledge about HTTP is not the best. But how can you send three different content-type headers? :) -Original Message- From: Barry [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 14, 2006 8:36 PM To: php-general@lists.php.net Subject: [PHP] Re: Setting headers for file download Peter Lauri schrieb: Best group member, This is how I try to push files to download using headers: header(Content-type: $file_type); header(Content-Disposition: attachment; filename=$filename); print $file; It works fine in FireFox, but not that good in IE. I have been googled to find the fix for IE, but I can not find it. Anyone with experience of this? Best regards, Peter Lauri There ya go: // fix for IE catching or PHP bug issue header(Pragma: public); header(Expires: 0); // set expiration time header(Cache-Control: must-revalidate, post-check=0, pre-check=0); // browser must download file from server instead of cache // force download dialog header(Content-Type: application/force-download); header(Content-Type: application/octet-stream); header(Content-Type: application/download); // use the Content-Disposition header to supply a recommended filename and // force the browser to display the save dialog. header(Content-Disposition: attachment; filename=.$path.;); header(Content-Transfer-Encoding: binary); header(Content-Length: .filesize($file)); readfile($file); -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- 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] Re: Setting headers for file download
Peter Lauri schrieb: That did it, thanks... Ok, my knowledge about HTTP is not the best. But how can you send three different content-type headers? :) There are not so different at all. Just giving the browser the job to download that thing. Every browser likes to interpret every content-type like he wants to. They ignore mostly every type they dislike. That's the problem you encounter in using firefox/IE. Greets Barry -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace \\1 yIKES!
At 3:45 AM -0700 6/14/06, sam wrote: On Jun 13, 2006, at 1:58 PM, tedd wrote: At 11:33 AM -0700 6/13/06, sam wrote: Wow this is hard I can't wait till I get the hang of it. Capitalize the first letter of a word. Try: ?php $word = yikes; $word[0]=strtoupper($word[0]); echo($word); ? This blows my mind. What should one think, everything is an array? Well, okay not every but everything that's in linear consecutive order; anything that can be indexed? I was trying to make an array from $word but explode() doesn't take an empty delimiter so I gave up and went for the preg_replace. Sorry, it was a throwback to my C days -- using ucfist() is better. 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] Re: Setting headers for file download [medium]
Barry wrote: Peter Lauri schrieb: Ok, my knowledge about HTTP is not the best. But how can you send three different content-type headers? :) There are not so different at all. Just giving the browser the job to download that thing. Every browser likes to interpret every content-type like he wants to. They ignore mostly every type they dislike. According to the manual, header() will replace previous similar headers with the new one sent, which would be header(Content-Type: application/download); The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type. By default it will replace, but if you pass in FALSE as the second argument you can force multiple headers of the same type [1]http://php.net/header As for the value of Content-Type it doesn't matter, you only have to specify an unknown (MIME) type so the browser won't know what to do with it, hence forcing to download the file. As minor notes (after reading a bit the RFC)... Expires is expected to be a date, not a number, and Pragma value conflicts with Cache-control, since... public Indicates that the response MAY be cached by any cache, even if it would normally be non-cacheable or cacheable only within a non- shared cache. (See also Authorization, section 14.8, for additional details.) Also, it seems we're given a wrong use for must-revalidate (me included), that or I misunderstood the RFC documentation --I didn't even found pre-check post-check. Content-Disposition is not part of the HTTP standard and Content-Transfer-Encoding is ignored, since both seem to be for e-mail usage (LOL) --and it's possible values are quoted-printable o base64--. Finally, Content-Length and Content-Type seem to apply only if had the request been a GET. Interesting what you learn reading the RFCs, too bad they're too long and sometimes not that clear. RFC: http://www.faqs.org/rfcs/rfc2616 -- Atentamente / Sincerely, J. Rafael Salazar Magaña -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] references for beginner...
At 5:16 AM -0700 6/14/06, BBC wrote: Hii all I just joined this forum, I'm beginner of PHP programming. I didn't understand almost all the syntax you're talking about (ups too honest, right?), so please... Does anyone have a kinds of references like soft books or something, which talk about all the syntax, and what for are they (also how to use if necessary) and where can I download it? thank for all references best regard BBC BBC: Welcome. Lot's of good stuff on the net. Do a cursory review of the following and start where you like. http://www.w3schools.com/php/default.asp http://www.weberdev.com/ViewArticle/433 http://www.weberdev.com/Manuals/ http://www.unf.edu/~rita0001/eresources/php_tutorials/index.htm http://www.phpit.net/article/back-to-basics-arrays/ And, of course don't forget mysql http://www.brainbell.com/tutors/php/php_mysql/index.html http://www.php-mysql-tutorial.com/index.php And, ton's of books. http://www.amazon.com/gp/search/ref=br_ss_hs/102-6441978-4633725?platform=gurupaurl=index%3Dblendedkeywords=phpGo.x=0Go.y=0Go=Go Some, very good and very cheap. I just wish I could remember all I've read. :-) hth's 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] PHP6 build help
/me goes and bangs head against wall. On 6/14/06, Rabin Vincent [EMAIL PROTECTED] wrote: On 6/14/06, Rory Browne [EMAIL PROTECTED] wrote: Only if (s)he''s on a debian based linux distro. I see from his configure output, that he's on Linux, but what makes you think he's on Debian ( or on a system with apt-rpm ) ? The first line of Ligaya's email said: Ubuntu Breezy Badger, AMD 64. That's a Debian-based distro. Rabin
Re: [PHP] Seeking recommendations for use of include()
Larry, Thank you for responding. $untrusted_var = '../../../../../../../etc/passwd'; include($untrusted_var); Or in later versions of PHP, I *think* the following may even work: $untrusted_var = 'http://evilsite.com/pub/evil.php'; include($untrusted_var); I'm still not sure I see the danger. By which I'm not saying that I deny there is danger, just that I don't see this. In both cases cited above, the malicious user has to write the code into my script that says to include($untrusted_var). And, again, it seems to me that if the malicious user has made it far enough to gain enough access to be able to do that, the damage is already done. They already have full access and full write capability, and could do any number of crazy things. I understand that I am being warned of a potential security risk, and I hope to come to understand it. But can someone show me more explicitly how someone could exploit a dynamic include() function with simple access through forms? And, can that access be exploited even when fairly common restrictions on form data is implemented (such as no tags and such)? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Simple class declaration returns error
PHP List, I am in the preliminary stages of designing my first object oriented PHP based web site. I've created file called article.class and included it in my index.php file. I put in a very simple echo statement, just as a place marker before I put in the real code, and just to make sure that the index.php file is successfully including the class. So far, it just looks like this (including line numbers): 4. class article{ 5. public function edit(){ 6. echo test; 7. } 8. } However, when I view my index.php, it says: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /web/article.class on line 5 Of course I consulted the PHP manual to make sure that I had the class syntax correct, and it seems that I've followed the basic structure as described there. Where have I gone wrong? Thank you for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple class declaration returns error
What version of PHP are you using? I suspect something less then 5.0 which means the public/private declarations are not supported... (So remove 'public' and see if it works) -Brad Dave M G wrote: PHP List, I am in the preliminary stages of designing my first object oriented PHP based web site. I've created file called article.class and included it in my index.php file. I put in a very simple echo statement, just as a place marker before I put in the real code, and just to make sure that the index.php file is successfully including the class. So far, it just looks like this (including line numbers): 4. class article{ 5. public function edit(){ 6. echo test; 7. } 8. } However, when I view my index.php, it says: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /web/article.class on line 5 Of course I consulted the PHP manual to make sure that I had the class syntax correct, and it seems that I've followed the basic structure as described there. Where have I gone wrong? Thank you for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Calculating difference between two days
Hi, I need to calculate no. of days between two dates, actually between date stored in DB and today's date. Does anybody has an example I can use? I found an example on http://www.developertutorials.com/tutorials/php/calculating-difference-between-dates-php-051018/page1.html but function gregoriantojd() doesn't work for me Fatal error: Call to undefined function: gregoriantojd() Found this: Please read the manual: http://www.php.net/manual/en/ref.calendar.php You need to either compile the extension in or load it. Since you provided no details about your situation at all, I cannot help you further. on http://bugs.php.net/bug.php?id=10151edit=1 Thanks on any help. -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calculating difference between two days
You could just parse the dates out and feed them to mktime(), subtract the difference between the two (in seconds) and use that to determin the number of days... Something like: ?php $date1=06/01/2006; $date2 = date('m/d/Y'); echo $date1 -- $date2\n; list($m,$d,$y) = explode(/,$date1); $one = mktime(0,0,0,$m,$d,$y); list($m,$d,$y)=explode(/,$date2); $two = mktime(0,0,0,$m,$d,$y); $diff = $two - $one; $days = $diff / (60*60*24); echo $days\n; ? [EMAIL PROTECTED] wrote: Hi, I need to calculate no. of days between two dates, actually between date stored in DB and today's date. Does anybody has an example I can use? I found an example on http://www.developertutorials.com/tutorials/php/calculating-difference-between-dates-php-051018/page1.html but function gregoriantojd() doesn't work for me Fatal error: Call to undefined function: gregoriantojd() Found this: Please read the manual: http://www.php.net/manual/en/ref.calendar.php You need to either compile the extension in or load it. Since you provided no details about your situation at all, I cannot help you further. on http://bugs.php.net/bug.php?id=10151edit=1 Thanks on any help. -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calculating difference between two days
[EMAIL PROTECTED] wrote: I need to calculate no. of days between two dates, actually between date stored in DB and today's date. Does anybody has an example I can use? Your database will have this function. In PostgreSQL: SELECT data_column - NOW() AS date_diff; There are similar functions for MySQL. Otherwise, consider converting your dates to unix time and subtracting the two numbers to find the date difference in seconds. These maay also be your friends: http://us3.php.net/manual/en/ref.datetime.php http://us3.php.net/manual/en/function.mktime.php http://us3.php.net/manual/en/function.date.php Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple class declaration returns error
Brad, What version of PHP are you using? I suspect something less then 5.0 which means the public/private declarations are not supported... (So remove 'public' and see if it works) Yes, it turns out that I am using PHP 4, and I thought I was using 5. Thank you for pointing it out. Now I have to consider whether or not to make my code PHP 4 compatible, or upgrade to version 5. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] references for beginner...
Thank Mr.Figaro. - Original Message - From: nicolas figaro [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, June 14, 2006 5:21 AM Subject: Re: [PHP] references for beginner... BBC a écrit : Hii all I just joined this forum, I'm beginner of PHP programming. welcome. I didn't understand almost all the syntax you're talking about (ups too honest, right?), so please... Does anyone have a kinds of references like soft books or something, which talk about all the syntax, and what for are they (also how to use if necessary) and where can I download it? http://www.php.net/manual/ could be a good starting point. N F thank for all references best regard BBC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Using PHP/HTML effectivly
Hi List, I've been (very slowly) working my way through some basic php, and putting it into my html site. However recently (after trying things out such as cookies or redirects where they have to be set before any page output) I've found that the combination or certainly the way that I'm using php and html together dosn't seem to go too well. I have a question to you experienced PHP developers, how do you mix the html/php together. When I've looked at things like the PHPBB forums, and gone through files they will have absolutly no HTML, just php code. I'm not sure how they manage their page styling, if anyone could explain this too me. At the moment I have things such as table ... ?php Some php code making a page header ? /table table ... ?php Content... ? /table I'm sure that I'm not doing it the best possible way, so if anyone has any tips for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] references for beginner...
[snip] I just joined this forum [/snip] Some must read info; http://zirzow.dyndns.org/php-general/NEWBIE http://www.php.net/manual/en/security.php http://phpsec.org/ http://www.hardened-php.net/advisories.15.html http://phpsec.org/projects/guide/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using PHP/HTML effectivly
I'm guessing that phpBB is doing things the right way.. that is, separating presentation and logic. In cases like that, you have your PHP code and your HTML in separate files with as little 'logic' in the HTML as possible. I'm kind of oversimplifying the explaination and I'm sure there are more profressional php developers that can describe it more precisely, but the general theory is to let your programmers program and let your designers design and this is a way to keep them out of each other's hair and make the code and layout easier to maintain. Just because you change the graphics or layout of a page, doesn't mean you need a PHP developer to go in there and wade through the tangles of PHP code to do so. Most web design people are smart enough to understand things like make sure this input box is of this type and has this name and/or id and/or other kind of label. Even to keep basic PHP stuff like foreach loops intact when redesigning. They don't wanve to have to see all the database calls and array processing that we end up dealing with. Over simplfied example: ?php # editform.php - this form allows editing of a single record // connect to db // perform queries // process data // set some conditions include(editform.tpl); // include the template file with all the HTML ? head titleEdit Form/title /head body form action=someprocessor.php method=POST Username: input type=text name=username value=?php echo $username; ?br Is Active?: input type=checkbox name=isactive?php echo $isactivechecked; ? br /form /body This keeps minimal PHP code in the tpl (template) file and keeps it mostly HTML for easy editing without confusing a non-PHP oriented web developer. That's a really really basic example, but that's one general coding standard. One of these days I hope to actually get to work like that. I keep inheriting big projects that are too much of a mess already that they'd have to be re-written to work like that.. hah Good luck Alex! -TG = = = Original message = = = Hi List, I've been (very slowly) working my way through some basic php, and putting it into my html site. However recently (after trying things out such as cookies or redirects where they have to be set before any page output) I've found that the combination or certainly the way that I'm using php and html together dosn't seem to go too well. I have a question to you experienced PHP developers, how do you mix the html/php together. When I've looked at things like the PHPBB forums, and gone through files they will have absolutly no HTML, just php code. I'm not sure how they manage their page styling, if anyone could explain this too me. At the moment I have things such as table ... ?php Some php code making a page header ? /table table ... ?php Content... ? /table I'm sure that I'm not doing it the best possible way, so if anyone has any tips for me. ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calculating difference between two days
Shouldn't be too difficult in PHP. ?php $yesterday = date(m/d/y, mktime(0,0,0,date(m), date(d) - 1, date(y))); $today = date(m/d/y); $secondsdiff = strtotime($today) - strtotime($yesterday); $minutesdiff = $secondsdiff / 60; $hoursdiff = $minutesdiff / 60; $daysdiff = $hoursdiff / 24; echo Seconds difference: $secondsdiffbr\n; echo Minutes difference: $minutesdiffbr\n; echo Hours difference: $hoursdiffbr\n; echo Days difference: $daysdiffbr\n; ? And if you want a larger example to play with, here's something I did a couple years ago (forgive the word wrapping and any unrefinedness.. it's something I whipped up as a test when someone asked a similar question back then). There's bound to be some way to do it in SQL as well, but unless there's a specific function for it like the other example given by another member, then you're likely to write a lot of really ugly SQL code to tackle the problem. Good luck! -TG ?php # Standard format dates and times $startdate = 04/12/04; $starttime = 13:05:01; $enddate = 10/14/04; $endtime = 13:05:01; # Break apart dates and times for mktime list($smonth,$sday,$syear) = explode(/,$startdate); list($emonth,$eday,$eyear) = explode(/,$enddate); list($shour,$sminute,$ssecond) = explode(:,$starttime); list($ehour,$eminute,$esecond) = explode(:,$endtime); # Number of seconds in each timeframe, 1 month = 30 days $secondsequiv array(Years=31536000,Months=2592000,Days=86400,Hours=3600,Minutes=60); # How many seconds between two dates/times $daydiff = mktime($ehour,$eminute,$esecond,$emonth,$eday,$eyear) - mktime($shour,$sminute,$ssecond,$smonth,$sday,$syear); if ($daydiff 0) { $daydiff *= -1; $negative = TRUE; } # Just to make sure I didn't use $remainder somewhere else in my script and forgot if (isset($remainder)) unset($remainder); # Cycle through timeframes checking to see if number is large enough to be a full year/month/day/etc # If so, find out how many and store remainder for further processing # If not, set to zero and continue processing foreach ($secondsequiv as $timeframe=$seconds) { if (isset($remainder)) { $checkvalue = $remainder; } else { $checkvalue = $daydiff; } if ($checkvalue = $seconds) { $daydiffarr[$timeframe] = floor($checkvalue/$seconds); $remainder = $daydiff % $seconds; } else { $daydiffarr[$timeframe] = 0; } } # If $reminder is never used, then we're dealing with less than a minute's worth of time diff if (isset($remainder)) { $daydiffarr[Seconds] = $remainder; } else { $daydiffarr[Seconds] = $daydiff; } # Display results if ($negative) echo NEGATIVE!!br\n; foreach ($daydiffarr as $timeframe=$count) { echo $timeframe = $countbr\n; } ? = = = Original message = = = Hi, I need to calculate no. of days between two dates, actually between date stored in DB and today's date. Does anybody has an example I can use? I found an example on http://www.developertutorials.com/tutorials/php/calculating-difference-between-dates-php-051018/page1.html but function gregoriantojd() doesn't work for me Fatal error: Call to undefined function: gregoriantojd() Found this: Please read the manual: http://www.php.net/manual/en/ref.calendar.php You need to either compile the extension in or load it. Since you provided no details about your situation at all, I cannot help you further. on http://bugs.php.net/bug.php?id=10151edit=1 Thanks on any help. -afan ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] declaring a class as stdClass?
Hi list, I hace an existencial doubt: i've seem many scripts declaring classes as stdClass. In the documentation (for PHP5 and also for 4), it says that this class is internal of php, and should't be used. By the manner I saw it's being used, i guess that it can be handy to create a 'generic' or so class, and append members when needed on the fly, without the need for a formal class declaration, but i could't find any good source explaining that. Has somebody some info about? Thanks in advance. Mariano Guadagnini.- -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.394 / Virus Database: 268.8.4/363 - Release Date: 13/06/2006 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checking for empty()
I have a form with various fields on it that I want to make sure aren't empty or the user didn't just hit the space bar or return (in a text field). What's the best way to do this? Seems empty() will fail on a textarea if the user simply hits a space or return and submits the form. -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checking for empty()
Weel, since this is a PHP list I will assume you are checking once the page is posted/submitted... off the top of my head, the functions strlen() and isset() come to mind. -Brad Ashley M. Kirchner wrote: I have a form with various fields on it that I want to make sure aren't empty or the user didn't just hit the space bar or return (in a text field). What's the best way to do this? Seems empty() will fail on a textarea if the user simply hits a space or return and submits the form. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checking for empty()
Brad Bonkoski wrote: Weel, since this is a PHP list I will assume you are checking once the page is posted/submitted... That would be correct. At the moment I'm checking with if (empty($_POST['var'])) { throw error flag } But as I read up on empty() I realized that if one simply hits a space and/or a return, empty() will fail. off the top of my head, the functions strlen() and isset() come to mind. Will look into them. Danke. -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple class declaration returns error
Dave M G wrote: Brad, What version of PHP are you using? I suspect something less then 5.0 which means the public/private declarations are not supported... (So remove 'public' and see if it works) Yes, it turns out that I am using PHP 4, and I thought I was using 5. Thank you for pointing it out. Now I have to consider whether or not to make my code PHP 4 compatible, or upgrade to version 5. I wouldn't bother with php4 objects if your only just starting out now - by the time you really get the hang of objects php6 will probably be making an entrance. BUT starting with objects in php5 doesn't mean you have to dive right in and use stuff like public/private/protected ... and stuff like interfaces... they'll probably just take all the fun out of it when your just starting out. jmho. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checking for empty()
Ashley M. Kirchner wrote: I have a form with various fields on it that I want to make sure aren't empty or the user didn't just hit the space bar or return (in a text field). What's the best way to do this? Seems empty() will fail on a textarea if the user simply hits a space or return and submits the form. You can always 'trim' before you do the empty check. Just assign to a variable first since empty doesn't do non-var expressions $value = trim($value); if (empty($value)) { // error not filled in } Of course, you'll also want to validate the data type is a string or number also, etc...and not an array. This is the goal of the up and coming input filtering features. Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checking for empty()
Ashley M. Kirchner wrote: I have a form with various fields on it that I want to make sure aren't empty or the user didn't just hit the space bar or return (in a text field). What's the best way to do this? Seems empty() will fail on a textarea if the user simply hits a space or return and submits the form. if (strlen(trim($var)) == 0) print It's empty; -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] declaring a class as stdClass?
Mariano Guadagnini wrote: Hi list, I hace an existencial doubt: i've seem many scripts declaring classes as stdClass. In the documentation (for PHP5 and also for 4), it says that this class is internal of php, and should't be used. By the manner I saw it's being used, i guess that it can be handy to create a 'generic' or so class, and append members when needed on the fly, without the need for a formal class declaration, but i could't find any good source explaining that. Has somebody some info about? Also, along the lines of this same question, I can do this in PHP very easily: ?php $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 'purple'); $data = (object) $data; print_r($data); ? And my object is magically created for me as an instance of stdClass. Is there a way to cast as some other type of class? ?php $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 'purple'); $data = (MyCustomClass) $data; print_r($data); ? I ask this because the cast in my first example, the (object) cast is WAY faster than using the manual approach of: ?php $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 'purple'); $MYCLASS = new MyCustomClass(); foreach ($data as $key = $value) $MYCLASS-$key = $value; } ? Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checking for empty()
Ashley M. Kirchner wrote: I have a form with various fields on it that I want to make sure aren't empty or the user didn't just hit the space bar or return (in a text field). What's the best way to do this? Seems empty() will fail on a textarea if the user simply hits a space or return and submits the form. I often use trim() on *any* incoming data as the first step to sanitizing the data - that gets rid of the whitespace problem you describe. a second step often involves using strval(), intval(), floatval() et al. subsequent steps might involve funcs like striptags() to remove any HTML that some b** might be trying to XSS your site with. sidenote in the future the filter extension will provide robust, standardized ways to santize incoming data - I think it ill be a huge step forward. /sidenote -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Seeking recommendations for use of include()
Dave M G wrote: Larry, Thank you for responding. $untrusted_var = '../../../../../../../etc/passwd'; include($untrusted_var); Or in later versions of PHP, I *think* the following may even work: $untrusted_var = 'http://evilsite.com/pub/evil.php'; include($untrusted_var); I'm still not sure I see the danger. By which I'm not saying that I deny there is danger, just that I don't see this. In both cases cited above, the malicious user has to write the code into my script that says to include($untrusted_var). And, again, it seems to me that if the malicious user has made it far enough to gain enough access to be able to do that, the damage is already done. They already have full access and full write capability, and could do any number of crazy things. I understand that I am being warned of a potential security risk, and I hope to come to understand it. But can someone show me more explicitly how someone could exploit a dynamic include() function with simple access through forms? And, can that access be exploited even when fairly common restrictions on form data is implemented (such as no tags and such)? ::index.php ?php include $_GET['page']; ? ::urls (ignore the fact that stuff would need to be urlencoded..) http://yoursite.com/index.php?page=/etc/passwd http://yoursite.com/index.php?page=http://evilsite.com/installrootkit.php that is the most simple version of the problem, now consider that people can use security bugs in 3rd party apps to upload php files (or complete [scam] sites) which may not be directly accessible (e.g. in ../uploads relative to the webroot) then they may be able to do stuff like: http://yoursite.com/index.php?page=../uploads/rootkitinstallingphpfilepretendingtobeajpeg.jpg and what goes for GET also goes for POST and COOKIE. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using PHP/HTML effectivly
This is my opinion on the matter... From experience, I would say that mixing PHP and HTML together in a complicated page can often get very ugly. I prefer to separate out presentation and code into separate layers as much as possible. I have most often used template systems such as Smarty (smarty.php.net) for that. I use Smarty for work - I find it quite nice. It allows you to separate your code from your presentation very effectively. It's easy to use, and provides things like caching for performance. However, I came to the realization recently that PHP itself is essentially a very feature rich template system (nevermind the fact that it's a well defined language. ;-) By splitting up my most recent project into includes, templates, and pages, I get a solution to the problem in pure PHP. In the end, code looks like code, and HTML looks (almost) like HTML and both are readable. (Same result as what Smarty gives you, without needing Smarty.) Most pages look something like: ?php include('include/data_functions.php'); if ($condition) { $title = 'Here is Some Data!'; $data = getSomeData($var1,$var2); } else { $title = 'Here is the Other Data!'; $data = getOtherData($var1,$var2); } include('template/page.php'); ? And most templates look something like: ?php include('template/head.php'); ? h1?= $title ?/h1 ... table ?php foreach ($data as $item) { ? tr td?= $item['part1'] ?/td td?= $item['part2'] ?/td /tr ?php } /* END foreach ($data as $item) */ ? /table ... pThanks for your interest in my data!/p ?php include('template/foot.php'); ? jon Alex Major wrote: Hi List, I've been (very slowly) working my way through some basic php, and putting it into my html site. However recently (after trying things out such as cookies or redirects where they have to be set before any page output) I've found that the combination or certainly the way that I'm using php and html together dosn't seem to go too well. I have a question to you experienced PHP developers, how do you mix the html/php together. When I've looked at things like the PHPBB forums, and gone through files they will have absolutly no HTML, just php code. I'm not sure how they manage their page styling, if anyone could explain this too me. At the moment I have things such as table ... ?php Some php code making a page header ? /table table ... ?php Content... ? /table I'm sure that I'm not doing it the best possible way, so if anyone has any tips for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calculating difference between two days
Thanks for all your, very usefull examples. -afan Shouldn't be too difficult in PHP. ?php $yesterday = date(m/d/y, mktime(0,0,0,date(m), date(d) - 1, date(y))); $today = date(m/d/y); $secondsdiff = strtotime($today) - strtotime($yesterday); $minutesdiff = $secondsdiff / 60; $hoursdiff = $minutesdiff / 60; $daysdiff = $hoursdiff / 24; echo Seconds difference: $secondsdiffbr\n; echo Minutes difference: $minutesdiffbr\n; echo Hours difference: $hoursdiffbr\n; echo Days difference: $daysdiffbr\n; ? And if you want a larger example to play with, here's something I did a couple years ago (forgive the word wrapping and any unrefinedness.. it's something I whipped up as a test when someone asked a similar question back then). There's bound to be some way to do it in SQL as well, but unless there's a specific function for it like the other example given by another member, then you're likely to write a lot of really ugly SQL code to tackle the problem. Good luck! -TG ?php # Standard format dates and times $startdate = 04/12/04; $starttime = 13:05:01; $enddate = 10/14/04; $endtime = 13:05:01; # Break apart dates and times for mktime list($smonth,$sday,$syear) = explode(/,$startdate); list($emonth,$eday,$eyear) = explode(/,$enddate); list($shour,$sminute,$ssecond) = explode(:,$starttime); list($ehour,$eminute,$esecond) = explode(:,$endtime); # Number of seconds in each timeframe, 1 month = 30 days $secondsequiv array(Years=31536000,Months=2592000,Days=86400,Hours=3600,Minutes=60); # How many seconds between two dates/times $daydiff = mktime($ehour,$eminute,$esecond,$emonth,$eday,$eyear) - mktime($shour,$sminute,$ssecond,$smonth,$sday,$syear); if ($daydiff 0) { $daydiff *= -1; $negative = TRUE; } # Just to make sure I didn't use $remainder somewhere else in my script and forgot if (isset($remainder)) unset($remainder); # Cycle through timeframes checking to see if number is large enough to be a full year/month/day/etc # If so, find out how many and store remainder for further processing # If not, set to zero and continue processing foreach ($secondsequiv as $timeframe=$seconds) { if (isset($remainder)) { $checkvalue = $remainder; } else { $checkvalue = $daydiff; } if ($checkvalue = $seconds) { $daydiffarr[$timeframe] = floor($checkvalue/$seconds); $remainder = $daydiff % $seconds; } else { $daydiffarr[$timeframe] = 0; } } # If $reminder is never used, then we're dealing with less than a minute's worth of time diff if (isset($remainder)) { $daydiffarr[Seconds] = $remainder; } else { $daydiffarr[Seconds] = $daydiff; } # Display results if ($negative) echo NEGATIVE!!br\n; foreach ($daydiffarr as $timeframe=$count) { echo $timeframe = $countbr\n; } ? = = = Original message = = = Hi, I need to calculate no. of days between two dates, actually between date stored in DB and today's date. Does anybody has an example I can use? I found an example on http://www.developertutorials.com/tutorials/php/calculating-difference-between-dates-php-051018/page1.html but function gregoriantojd() doesn't work for me Fatal error: Call to undefined function: gregoriantojd() Found this: Please read the manual: http://www.php.net/manual/en/ref.calendar.php You need to either compile the extension in or load it. Since you provided no details about your situation at all, I cannot help you further. on http://bugs.php.net/bug.php?id=10151edit=1 Thanks on any help. -afan ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] order of include on include()
If I have a file: /code/folder1/test.php and in that file, it has these includes: include_once(../../file1.php); include_once(../../file2.php); include_once(../../file3.php); I then have another file: /code/test2.php That file pulls in test.php. include_once(folder1/test.php); Why do I get errors on the includes? Does php first pull in the includes of test.php before pulling it into test2.php? It seems to be looking for the includes in test.php from where I am in test2.php and is failing. Thanks!
RE: [PHP] order of include on include()
[snip] Why do I get errors on the includes? [/snip] Includes are included in the order of their inclusion. If an include includes a child function (such as a class declaration) its parent must be included first. What error did you get? My bet is it is a path issue. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using PHP/HTML effectivly
I used many functions as template to change the html syntax. this is one of the function as a sample: ?php function tabletag($border=0,$width=100%,$height=100%,$cellpadding = 0,$cellspacing=0,$style=) { print (table width=\$width\ height =\$height\ border=\$border\ cellspacing=\$cellspacing\ cellpadding=\$cellpadding\ style=\$style\); } ? so I don't need to type table , just call those functions. and I don't think it works slowly (cause we just set one function for many tables) - Original Message - From: Alex Major [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, June 14, 2006 10:37 AM Subject: [PHP] Using PHP/HTML effectivly Hi List, I've been (very slowly) working my way through some basic php, and putting it into my html site. However recently (after trying things out such as cookies or redirects where they have to be set before any page output) I've found that the combination or certainly the way that I'm using php and html together dosn't seem to go too well. I have a question to you experienced PHP developers, how do you mix the html/php together. When I've looked at things like the PHPBB forums, and gone through files they will have absolutly no HTML, just php code. I'm not sure how they manage their page styling, if anyone could explain this too me. At the moment I have things such as table ... ?php Some php code making a page header ? /table table ... ?php Content... ? /table I'm sure that I'm not doing it the best possible way, so if anyone has any tips for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-WIN] Re: Executing External Application
Please include the list when replying. [EMAIL PROTECTED] wrote: Stut wrote: Eww!! Eww!! and thrice EWW!! There is *never*, and I mean *never* an acceptable reason to run a GUI app in response to a web request - even on an Intranet. *NEVER* IMMHO Bah. Pure ignorance. Here's one reason. I run Apache on my PC. I wrote a Php script that I run as a scheduled task to zip up a folder once a day. I used the WinZip command line interface. It will not run until I allow Apache to interact with the desktop. Simple, to the point, and it works. WinZip is a GUI app. There are lots of CLI utilities for zipping - use one of those! If you're doing this as a personal utility, why is Apache getting involved in running a PHP script as a scheduled task? Here's another. I have a photo gallery script written in Php that triggers an Irfanview slide show. It's very efficient and simple. Never come across Irfanview, but a quick Google reveals a GUI app for viewing images. How is this useful for a web-based visitor? You're Eww, Eww, Eww and Never!! rules are just so much hot air. Maybe in your opinion, which you are entitled to just as much as I am. However, IMHO web-based appplications and GUI applications should not mix. Ever. But that's just my opinion. If your use is not as a web application, but rather as a way to start processes on your local machine I would question why Apache needs to be involved at all. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: [PHP-WIN] Re: Executing External Application
Oops, wrong list, sorry guys. Stut wrote: Please include the list when replying. [EMAIL PROTECTED] wrote: Stut wrote: Eww!! Eww!! and thrice EWW!! There is *never*, and I mean *never* an acceptable reason to run a GUI app in response to a web request - even on an Intranet. *NEVER* IMMHO Bah. Pure ignorance. Here's one reason. I run Apache on my PC. I wrote a Php script that I run as a scheduled task to zip up a folder once a day. I used the WinZip command line interface. It will not run until I allow Apache to interact with the desktop. Simple, to the point, and it works. WinZip is a GUI app. There are lots of CLI utilities for zipping - use one of those! If you're doing this as a personal utility, why is Apache getting involved in running a PHP script as a scheduled task? Here's another. I have a photo gallery script written in Php that triggers an Irfanview slide show. It's very efficient and simple. Never come across Irfanview, but a quick Google reveals a GUI app for viewing images. How is this useful for a web-based visitor? You're Eww, Eww, Eww and Never!! rules are just so much hot air. Maybe in your opinion, which you are entitled to just as much as I am. However, IMHO web-based appplications and GUI applications should not mix. Ever. But that's just my opinion. If your use is not as a web application, but rather as a way to start processes on your local machine I would question why Apache needs to be involved at all. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using PHP/HTML effectivly
Thankyou everyone who responded to my original message. All of your ideas have showed me the various ways of doing it, however I believe that the idea from Jons message is best suited to my needs. I realise the logic behind it, its put together some knowledge I have already so I think I'll use it for the time being. Thankyou for taking the time to respond to my message. Regards, Alex On 14/6/06 19:48, Jon Anderson [EMAIL PROTECTED] wrote: This is my opinion on the matter... From experience, I would say that mixing PHP and HTML together in a complicated page can often get very ugly. I prefer to separate out presentation and code into separate layers as much as possible. I have most often used template systems such as Smarty (smarty.php.net) for that. I use Smarty for work - I find it quite nice. It allows you to separate your code from your presentation very effectively. It's easy to use, and provides things like caching for performance. However, I came to the realization recently that PHP itself is essentially a very feature rich template system (nevermind the fact that it's a well defined language. ;-) By splitting up my most recent project into includes, templates, and pages, I get a solution to the problem in pure PHP. In the end, code looks like code, and HTML looks (almost) like HTML and both are readable. (Same result as what Smarty gives you, without needing Smarty.) Most pages look something like: ?php include('include/data_functions.php'); if ($condition) { $title = 'Here is Some Data!'; $data = getSomeData($var1,$var2); } else { $title = 'Here is the Other Data!'; $data = getOtherData($var1,$var2); } include('template/page.php'); ? And most templates look something like: ?php include('template/head.php'); ? h1?= $title ?/h1 ... table ?php foreach ($data as $item) { ? tr td?= $item['part1'] ?/td td?= $item['part2'] ?/td /tr ?php } /* END foreach ($data as $item) */ ? /table ... pThanks for your interest in my data!/p ?php include('template/foot.php'); ? jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: [PHP-WIN] Re: Executing External Application
Stut wrote: Oops, wrong list, sorry guys. no worries - made me laugh anyway :-) but one worries about the one you were trying to help: cron to run apache to run php to run a gui app. are the loons running the nut house after all? Stut wrote: Please include the list when replying. [EMAIL PROTECTED] wrote: Stut wrote: Eww!! Eww!! and thrice EWW!! There is *never*, and I mean *never* an acceptable reason to run a GUI app in response to a web request - even on an Intranet. *NEVER* IMMHO Bah. Pure ignorance. Here's one reason. I run Apache on my PC. I wrote a Php script that I run as a scheduled task to zip up a folder once a day. I used the WinZip command line interface. It will not run until I allow Apache to interact with the desktop. Simple, to the point, and it works. WinZip is a GUI app. There are lots of CLI utilities for zipping - use one of those! If you're doing this as a personal utility, why is Apache getting involved in running a PHP script as a scheduled task? Here's another. I have a photo gallery script written in Php that triggers an Irfanview slide show. It's very efficient and simple. Never come across Irfanview, but a quick Google reveals a GUI app for viewing images. How is this useful for a web-based visitor? You're Eww, Eww, Eww and Never!! rules are just so much hot air. Maybe in your opinion, which you are entitled to just as much as I am. However, IMHO web-based appplications and GUI applications should not mix. Ever. But that's just my opinion. If your use is not as a web application, but rather as a way to start processes on your local machine I would question why Apache needs to be involved at all. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: [PHP-WIN] Re: Executing External Application
Jochem Maas wrote: Stut wrote: Oops, wrong list, sorry guys. no worries - made me laugh anyway :-) but one worries about the one you were trying to help: cron to run apache to run php to run a gui app. are the loons running the nut house after all? Well, it was on the PHP-Windows list. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] can I do this: update table while selecting data from table?
Am I allowde to do this: $query = mysql_query(SELECT member_id, member_name FROM members); while($result = mysql_fetch_array($query)) { if(empty($result['member_name'])) { mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id = .$result['member_id'].); } } As far as I know, after SELECT query, data are in buffer and I AM able to connect to the same table and do UPDATE, right? Thanks -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Production release of 4.4.3 soon?
Greetings - Is there any further word on the production release of PHP 4.4.3? Last I heard, (May 22nd) Derick Rethans had kindly put an RC (4.4.3RC1) out at http://downloads.php.net/derick/ and mentioned May 30th as possible date for production release. I haven't seen anything since that time, though... I'm eager to upgrade since there have been so many vulnerabilities reported in recent weeks. Thanks for any additional info. -paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: can I do this: update table while selecting data from table?
As far as *I* know, yes, the SELECT statement is excuted at that particular moment, and any further execution will be independant of your initial (SELECT) query. Was there any problem? [EMAIL PROTECTED] wrote: Am I allowde to do this: $query = mysql_query(SELECT member_id, member_name FROM members); while($result = mysql_fetch_array($query)) { if(empty($result['member_name'])) { mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id = .$result['member_id'].); } } As far as I know, after SELECT query, data are in buffer and I AM able to connect to the same table and do UPDATE, right? Thanks -afan -- Atentamente / Sincerely, J. Rafael Salazar Magaña -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] can I do this: update table while selecting data from table?
[EMAIL PROTECTED] wrote: Am I allowde to do this: $query = mysql_query(SELECT member_id, member_name FROM members); while($result = mysql_fetch_array($query)) { if(empty($result['member_name'])) { mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id = .$result['member_id'].); } } As far as I know, after SELECT query, data are in buffer and I AM able to connect to the same table and do UPDATE, right? no you'll have to reboot the machine first. seriously though, have you tried it? that said your [probably] better off just doing 1 query: UPDATE members SET member_name = 'N/A' WHERE member_name = ''; that said your [probably] better off leaving the name empty or setting it NULL if it's unknown and showing 'N/A' in whatever output screen it's relevant for any names that are found to be empty. Thanks -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] can I do this: update table while selecting data from table?
It looks very much as if you did: update members set member_name = 'N/A' where member_name = null Nevertheless, I would rather keep null within the database and use 'N/A' at the presentation level. My rule is that the data in the database should be in a machine oriented format. For example, I store timestamps, never formated dates, numbers as actual numerical datatypes, not as strings, though PHP can cope with either. 'N/A' is a way to present that information to the user, which might even be, for example, language dependant. On displaying, you could well do: SELECT member_id, ifnull(member_name,'N/A') FROM members Satyam - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, June 14, 2006 11:37 PM Subject: [PHP] can I do this: update table while selecting data from table? Am I allowde to do this: $query = mysql_query(SELECT member_id, member_name FROM members); while($result = mysql_fetch_array($query)) { if(empty($result['member_name'])) { mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id = .$result['member_id'].); } } As far as I know, after SELECT query, data are in buffer and I AM able to connect to the same table and do UPDATE, right? Thanks -afan -- 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] Re: [PHP-WIN] Re: Executing External Application
At 10:23 PM +0100 6/14/06, Stut wrote: Jochem Maas wrote: Stut wrote: Oops, wrong list, sorry guys. no worries - made me laugh anyway :-) but one worries about the one you were trying to help: cron to run apache to run php to run a gui app. are the loons running the nut house after all? Well, it was on the PHP-Windows list. -Stut That explains it. 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] Using PHP/HTML effectivly
At 1:28 PM -0700 6/14/06, BBC wrote: I used many functions as template to change the html syntax. this is one of the function as a sample: ?php function tabletag($border=0,$width=100%,$height=100%,$cellpadding = 0,$cellspacing=0,$style=) { print (table width=\$width\ height =\$height\ border=\$border\ cellspacing=\$cellspacing\ cellpadding=\$cellpadding\ style=\$style\); } ? so I don't need to type table , just call those functions. and I don't think it works slowly (cause we just set one function for many tables) BBC: Personally, I see what you are trying to do, but I would not be going that route. Like many others, I don't work in a shop where one group does php and another does the designing and such -- I'm just a one man band who has to do it all and make it work. For me, I use php/mysql, html, js, and css all together to do stuff -- but, I try to keep them as separate as I can. CSS helps a LOT because I can use simple html tags like: table ... /table And put the presentation code for the table in css. CSS seldom mixes with php and it helps reduce the amount of code I have to review. Plus, css separates look from performance (i.e., php/js/html) -- I can change one without worrying about the other. Typically, the amount of html code I have is far less than php. I often roll html code segments (like header and footer) into php includes and keep them tucked away so I don't have to look at anything except: include(header.inc); Now, there is html code that I have to mix into my php and I usually separate it by using the method you first suggested, such as: ?php ... bunches of php code ? bunches of html code ?php ... bunches more of php code ? To me, that's easy to read and I have no problem mixing stuff that way. Occasionally, I have to intermix html and php together in the same statement such as filling text field from a dB, such as: input type=text size=7 maxlength = 7 name=price value=?php echo($price); ? But, it's pretty clear that I'm using php to set what the value is in an html statement. Even fewer times, but I still do, I intermix css, js, html, and php all together, such as: td class=search_btn input type=button value=Album onclick=window.location='search.php?unique_id=?php echo($unique_id);?' /td But still, I think it's pretty clear what I'm doing. CSS takes care of how the button looks; js takes care of what happens when the user clicks; php provides something from the dB; and html is the glue that holds everything together. They all work in concert. One of the things I keep in mind is when I start using a lot of escape characters (as you did above), then I'm not doing it the best way (IMO) and I look for another solution. I would much rather see code ? table ... /table ?php Than to intermix it as you did. Now, purest would like all languages to be separate and I can't argue with that -- however -- if this is what it takes to get the job done, then what choice do you have? I look at it all like it's one big language and that works for me -- others mileage may vary. hth's 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] can I do this: update table while selecting data from table?
?!?!?!?!?!?! [EMAIL PROTECTED] wrote: Am I allowde to do this: $query = mysql_query(SELECT member_id, member_name FROM members); while($result = mysql_fetch_array($query)) { if(empty($result['member_name'])) { mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id = .$result['member_id'].); } } As far as I know, after SELECT query, data are in buffer and I AM able to connect to the same table and do UPDATE, right? no you'll have to reboot the machine first. seriously though, have you tried it? that said your [probably] better off just doing 1 query: UPDATE members SET member_name = 'N/A' WHERE member_name = ''; that said your [probably] better off leaving the name empty or setting it NULL if it's unknown and showing 'N/A' in whatever output screen it's relevant for any names that are found to be empty. Thanks -afan -- 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] can I do this: update table while selecting data from table?
No, that was just an exapmle to explain better. Of course this is not the REAL code. :) And there are some more thing to do inside while loop. Thanks. -afan It looks very much as if you did: update members set member_name = 'N/A' where member_name = null Nevertheless, I would rather keep null within the database and use 'N/A' at the presentation level. My rule is that the data in the database should be in a machine oriented format. For example, I store timestamps, never formated dates, numbers as actual numerical datatypes, not as strings, though PHP can cope with either. 'N/A' is a way to present that information to the user, which might even be, for example, language dependant. On displaying, you could well do: SELECT member_id, ifnull(member_name,'N/A') FROM members Satyam - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, June 14, 2006 11:37 PM Subject: [PHP] can I do this: update table while selecting data from table? Am I allowde to do this: $query = mysql_query(SELECT member_id, member_name FROM members); while($result = mysql_fetch_array($query)) { if(empty($result['member_name'])) { mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id = .$result['member_id'].); } } As far as I know, after SELECT query, data are in buffer and I AM able to connect to the same table and do UPDATE, right? Thanks -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] declaring a class as stdClass?
To answer both of you: $var = new stdClass(); is perfectly acceptable. I do it all the time. The caveat is that the behavior is slightly different in PHP 4 than PHP 5. In PHP 4, $var would behave exactly like an associative array, just with different funky characters to access its properties. Internally, in fact, they're represented the same. In PHP 5, $var would behave exactly like an associative array, EXCEPT when passing it as a parameter to a function. In PHP 4, objects pass by value by default. In PHP 5, they pass by reference by default. Also, yes, casting an object to an array or vice versa is much faster than manually iterating it. So: $var = (object)array('a'='foo', 'b'='bar', 'c'='baz'); Is perfectly acceptable. I've never tried casting to some other type of class, though. Give it a try and let us know how it goes. :-) On Wednesday 14 June 2006 13:26, D. Dante Lorenso wrote: Mariano Guadagnini wrote: Hi list, I hace an existencial doubt: i've seem many scripts declaring classes as stdClass. In the documentation (for PHP5 and also for 4), it says that this class is internal of php, and should't be used. By the manner I saw it's being used, i guess that it can be handy to create a 'generic' or so class, and append members when needed on the fly, without the need for a formal class declaration, but i could't find any good source explaining that. Has somebody some info about? Also, along the lines of this same question, I can do this in PHP very easily: ?php $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 'purple'); $data = (object) $data; print_r($data); ? And my object is magically created for me as an instance of stdClass. Is there a way to cast as some other type of class? ?php $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 'purple'); $data = (MyCustomClass) $data; print_r($data); ? I ask this because the cast in my first example, the (object) cast is WAY faster than using the manual approach of: ?php $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 'purple'); $MYCLASS = new MyCustomClass(); foreach ($data as $key = $value) $MYCLASS-$key = $value; } ? Dante -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Seeking recommendations for use of include()
Jochem, ::index.php ?php include $_GET['page']; ? Wouldn't strip_tags() eliminate the ?php ? tags that make this possible? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Simulating a POST
I hit the script by http://server/netgeo.post.php?ip=192.168.1.1 But the script entered an endless loop. What's wrong? -- .~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (Ubuntu 6.06) Linux 2.6.16.20 ^ ^ 11:47:02 up 8 days 21:30 0 users load average: 1.09 1.06 1.21 news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Simulating a POST
I hit the script by http://server/haha.php?ip=192.168.1.1 But the script entered an endless loop. What's wrong? -- .~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (Ubuntu 6.06) Linux 2.6.16.20 ^ ^ 11:48:01 up 8 days 21:31 0 users load average: 1.06 1.06 1.20 news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk htmlhead/head body onload=document.myform.submit() ?php function getLocationCaidaNetGeo($ip) { $NetGeoURL = http://netgeo.caida.org/perl/netgeo.cgi?target=.$ip; if($NetGeoFP = fopen($NetGeoURL,r)) { ob_start(); fpassthru($NetGeoFP); $NetGeoHTML = ob_get_contents(); ob_end_clean(); fclose($NetGeoFP); } return $NetGeoHTML; } if ($HTTP_POST_VARS['btnsubmit']) { print_r(getLocationCaidaNetGeo($_POST['ip'])); } else { ? form method=post enctype=multipart/form-data name=myform action=?php echo($PHP_SELF); ? input type=text name=ip input type=submit name=btnsubmit action=submit /form ?php } ? /body/html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Upgrade to PHP5 on Fedora Core
PHP List, My hosting service allows me enough access to do things like handle my own upgrades and full administrative access. Usually, because I am more of a web designer than an server administrator, I get their support staff to manage upgrades and installations. However, that does cost money, so I thought this time, if it's easy enough, I would try upgrading PHP myself. Currently my hosting service is running PHP Version 4.4.2, and I would like to upgrade to the latest stable build of PHP 5. At home, I use Ubuntu LTS, and to upgrade to PHP 5 I just used apt-get (with the Synaptic GUI) to upgrade. It was very easy. The hosting machine is using Fedora Core 1. I'm less familiar with Red Hat systems, but I do understand that yum is the equivalent of apt-get. So, I'm hoping I can just do: yum install php5 ... and be off and running. But because I don't really want to suffer any downtime, I hoped to get confirmation here on this list that this will work, and check if I need any other configuration options. If it makes a difference, I'm also running MySQL 5.0 on the system, and Apache 2. Is there anything else I need to know for a smooth upgrade to PHP 5? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php