[PHP] Re: Best way to mass mail
* Ryan A [EMAIL PROTECTED]: My client has a dating site and now he wants to mail all his members, he does not want to use any of the already installed mailing lists but wants us to make one for him, he's on a dedicated server. Presently he does not have too many members, just a few thousand (around 3k i guess), I remember reading sometime back on the list that using the mail() may not be the best option...not sure if thats still true. The thing that bothers me the most is if the program times out..., how do I start again from the ones that have not been sent? eg: (10 members) mail gets sent to first 4 members then times out we re-click on the send button and it starts again from one...again times out (this happens 5 times) that means members 1-4 will get the same email 5 times Doing this the hard way would be to connect to the db after each successful mail and mark each member with todays date or something...but I would like to avoid so many calls to the DB if possible...esp if the site grows. Ideas/suggestions? Build a queueing system, and use cron to actually process and mail the list. Longer explanation: I run a mass-mailer for a non-profit, and the way our works is to store all mail information in a database. We then have a cronjob that runs each minute and checks to see if any mailings need to be sent (basically, the absense of a 'sent' flag), and then processes the mailing. Mails are then queued to an MTA -- in our case, Postfix. This allows us to handle bounces (another script is triggered when email bounces back to the reply-to address). So, on your web-based front-end, when you click 'Send', it actually simply places the information in a database queue, and the cronjob does the actual sending. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Best way to mass mail
* Manuel Lemos [EMAIL PROTECTED] : Hello, on 09/12/2005 02:56 PM Chris W. Parker said the following: Matthew Weier O'Phinney mailto:[EMAIL PROTECTED] on Monday, September 12, 2005 6:55 AM said: Mails are then queued to an MTA -- in our case, Postfix. This is the part I don't know how to do. Can you explain/show some code? Just use the mail function and it will get queued in Postfix. Or mail via SMTP to running postfix/sendmail/whatever. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Best way to mass mail
* Manuel Lemos [EMAIL PROTECTED] : on 09/12/2005 05:18 PM Matthew Weier O'Phinney said the following: Mails are then queued to an MTA -- in our case, Postfix. This is the part I don't know how to do. Can you explain/show some code? Just use the mail function and it will get queued in Postfix. Or mail via SMTP to running postfix/sendmail/whatever. If he is running postfix on the same machine that postfix is running, it does not make much sense to send the message via SMTP because it is a much slower way to do the same thing. This was more in the instance that the server with the MTA is separate from the web server (which it often will be). You're right though -- if the MTA is on the same machine, just use the local executables. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Error Handling
* Chuck Brockman [EMAIL PROTECTED]: What is a good way to capture errors that occur. I've tried the following code in development, but it still spits out an error (Parse error: syntax error, unexpected '}', expecting ',' or ';' in X:\\\.php on line 7) ? // error handling test try{ $test = 1; echo $test1 You're missing a semicolon at the end of the above line. } catch (Exception $e) { print Exception caught\n; } ? -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: php equivalent for cut
* Michelle Konzack [EMAIL PROTECTED]: I am searching for the right equivalent for cut -d : -f5 but it must work with php4. $fields = explode(':', $string, 5); Since the website http://www.php.net/manual/de/ has no seperated manuals for php4 and php5, it is not easy to find the right stuff. explode() works the same in both PHP4 and PHP5. Additionally, the manual is very good at detailing in what versions of PHP a function is valid. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: is it worth using apache2 with php 4.3.4
* bala chandar [EMAIL PROTECTED]: i am now using apache 1.3.x with php 4.3.4 is it worth upgrading to apache 2.x Currently, no: http://ilia.ws/archives/32-Apache-1-vs-Apache-2-Performance.html -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match
* John Nichel [EMAIL PROTECTED] : Richard Lynch wrote: On Thu, August 18, 2005 2:50 pm, Jon wrote: preg_match_all(/Charges \s\s+ $total x (.+) /siU, $single, $from_invoice); I would recommend using \\s instead of \s -- While \s doesn't have any meaning in PHP strings, so PHP just figures you must have meant \\s snip But in perl type regex's, the \s is a space. Without testing it, I don't think \\s would match what the OP was looking for (I *think* it would match '\s'). However, I don't understand why the OP is looking for a space , followed by a space \s, followed by multiple spaces \s+a \s{1,} would have done all that just fine. But in double quotes, \ is seen as an escape, and could be interpreted differently. Probably the better way to do this would be: $pattern = '/Charges\s+' . $total . ' x ([^\s]*)/si'; preg_match_all($pattern, $single, $from_invoice); -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: run remote shell script
First off, Roger, Thomas, not sure which is your given name -- please use a mail or news agent that will wrap your lines with linebreaks at 72 characters. Some of us are on text-based clients, and it's difficult to read your posts when they extend beyond the screen boundaries... ;-) * Roger Thomas [EMAIL PROTECTED] : OK. I am able to setup remote key authentication between svrA and svrB. From svrA I can login to svrB with something like [EMAIL PROTECTED] www]$ ssh [EMAIL PROTECTED] and I can also execute a shell script like [EMAIL PROTECTED] www]$ ssh [EMAIL PROTECTED] /tmp/test.sh On svrA I have a PHP script like so: ? system('ssh [EMAIL PROTECTED] /tmp/test.sh someDIR'); ? /tmp/test.sh on svrB is only a one liner like so: mkdir /tmp/$1 I ran the script from the browser but the /tmp/someDIR is not created :( Could it be that user nobody on svrA is *not* allowed to connect to svrB because the public key belongs to user www ? How do I rectify this ? In the actual situation, I need to execute a shell script in svrB (from browser served by Apache on svrA) that only root can run. Please advise. I am getting very worried. Okay, I should have been a little more explicit. There are two ways I've done this. The initial details are different, but the final call is pretty much the same. 1. Using sudo 'sudo' allows users to run commands as different users. In this case, we want the user running the web server (usually www, apache, or nobody) to run ssh, or a script that executes the ssh command, as a normal user. I usually opt for the latter, and create a script such as: #!/bin/bash exec ssh [EMAIL PROTECTED] /path/to/remote/script and save it in /usr/local/bin. Then, edit sudoers (usually executing 'visudo' as root), and add a line like nobody ALL = (username) NOPASSWD: /usr/local/bin/SCRIPTNAME What this does is to allow the user 'nobody' (or whomever runs the web server process) to execute /usr/local/bin/SCRIPTNAME as 'username', and they do not need to enter a password to do so (normally with sudo you do). You'll need to restart the webserver after granting the sudo privileges. In this scenario, the normal user, specified by 'username' above, needs to have the the SSH keys setup between the servers. 2. Give the web user a home directory The other option is to setup a home directory for the web user. This will mean editing the /etc/passwd file to give the web user both a home directory and a shell; these are teh last two items in the colon delimited list. A sample entry might look like: nobody:x:65534:65534:nobody:/var/www:/bin/bash Once you've done this, restart the web server. At this point, you'll then need to become the web user briefly in order to: * generate an SSH key * send the key to the remote server Then, on the remote server, add the SSH key to the appropriate user on that system. Good luck! Quoting Matthew Weier O'Phinney [EMAIL PROTECTED] : * Roger Thomas [EMAIL PROTECTED] : My PHP script is in svrA. How do I run a shell script in svrB? svrB does not have PHP and Apache :( Is this at all possible? Please advise. Use ssh. You will have to setup remote key authentication from svrA to svrB (so that a password will not be needed), and then in your script you would call: system('ssh svrB /path/to/scriptToRun'); -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to suppress HTTP headers?
* Thomas Capote [EMAIL PROTECTED]: 3) The header() command inserts or replaces headers to be sent by PHP. However, header() (with no arguments) does not suppress header output, it simply generates an error. Even if something like header('Content-type:') suppressed the 'Content-type' header, how would we suppress all header output including the status line ('HTTP/1.1 200 OK')? The HTTP/1.1 200 OK is a header sent by your web server; PHP has NO control over headers sent by the web server -- only those that PHP appends to them. 5) Mr. Lynch is right: this is NOT an HTTP compliant exchange. This is a bug in the client machine that cannot be fixed (by me), but must be worked around somehow. This is the real nut of the problem. Tough little problem, eh guys? I see three possible avenues to a solution. 1) Find some PHP command that will suppress header generation, or simply circumvent it, if only as a side-effect. Already noted, cano't be done. 2) Get Apache to not send headers for this page, maybe through SSI directives, .htaccess file, or some other mechanism. I don't think there's a way to do this -- HTTP headers are part of the HTTP protocol, and that's what Apache tries to implement. But I can't say with 100% certainty that someone hasn't done it. Search on the apache web site. 3) Write my own mini-server (to listen on port 6237 or something) to handle these requests using socket calls in PERL, Java, or even the PHP CLI. I'm not sure I could pull off programming something robust enough, frankly. I'd rather hijack Apache to do the heavy lifting. I think this is likely to be the direction you'll need to go. This sort of thing actually isn't too difficult to do -- I've used and tinkered on PHP chat server implementations that do similar things. Perl has a wealth of tools for creating net servers which, again, make this stuff fairly trivial. Good luck! -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Thursday, August 18, 2005 3:48 AM To: [EMAIL PROTECTED] Cc: php-general@lists.php.net; [EMAIL PROTECTED] Subject: RE: [PHP] How to suppress HTTP headers? On Tue, August 16, 2005 10:02 am, [EMAIL PROTECTED] wrote: BTW: I made a mistake last time. Apparently with CLI there are headers. You can use php -q to suppress headers when using PHP via CGI has always sent out at least one header. Content-type: text/html -q has always suppressed that. CLI may or may not have sent headers... CLI. Odd. Not sure I had to do that when I wrote a few CLI scripts before. Oh well, something to play with another day (don't have time to check it right now). So another thing I may be wrong on.. but a thought.. If you use the header() command, does it prevent the web server from generating it's own headers? I believe your header() commands only REPLACE any headers PHP would have sent, but any other headers it's gonna send, it's still gonna send them. That is, if you send out htmlbodySomething/body/html does the web server automatically generate the headers but if you use header() it uses what PHP generates rather than it's own? If so.. can you just do: header(); With nothing in it to suppress headers? I think that will suppress headers... by issuing an ERROR that a required argument is missing :-) Or can you do something like: header(xmlstuff/xml); No. That is not a valid header, for starters. You MIGHT be able to wipe out the headers PHP sends by doing something like: header(Content-type:); //Wipe out Content-type: but I wouldn't cound on it. Sounds to me like the remote server isn't actually using HTTP at all. HTTP without headers is just not HTTP. You may want to write your own server in PHP using sockets -- but then you'll need to convince the remote server to connect/use that different server you have written. Either connecting on a different port, or to a different domain, or a different URL (maybe) so you can configure your box to use your server for these weird requests. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: run remote shell script
* Roger Thomas [EMAIL PROTECTED]: My PHP script is in svrA. How do I run a shell script in svrB? svrB does not have PHP and Apache :( Is this at all possible? Please advise. Use ssh. You will have to setup remote key authentication from svrA to svrB (so that a password will not be needed), and then in your script you would call: system('ssh svrB /path/to/scriptToRun'); -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: optional argument when creating a function
* D A GERM [EMAIL PROTECTED]: I'm throwing a warning on a function I created. I thought a in front of the argument was supposed to make it optional. Is there something else I need to do make that argument optional? As others have noted, the ampersand tells the function to grab a reference to the variable passed. There are two ways to do optional arguments: 1) Set a default value for the argument (must be last argument in the list, or else all other arguments in the list must also have default values): function doEmail($username, $link = null) {} function doEmail($username, $link = null, $linkName = '') {} 2) Parse the argument list via the func_* functions: function doEmail($username) { $argCount = func_num_args(); if (1 $argCount) { // Retrieve second argument, from a 0-based array: $link = func_get_arg(1); } ... } function doEmail($username) { $argCount = func_num_args(); if (1 $argCount) { // Retrieve all arguments $args = func_get_args(); // Remove $username from it array_shift($args); // Get $link: $link = array_shift($args); } ... } -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Form Processor?
* [EMAIL PROTECTED] [EMAIL PROTECTED]: Does anyone have any recomendations for a GOOD PHP Form Processor software? Kind of in a bind and don't want to reinvent the wheel if I don't have to. Sorry for thr O/T. Not OT at all. Many people like PEAR's HTML_QuickForm. I didn't like it much -- I didn't like the way it interacted with template systems. shamelessSelfPromotion I've been doing work on Paul Jones' Solar project, particularly in the Solar_Filter, Solar_Valid, and Solar_Form packages, which offer some nice, generic, and extensible ways to validate and filter forms. Documentation is still pending, but much of the usage is documented in the class files themselves. http://solarphp.com/ /shamelessSelfPromotion patForms also looks good, and is a stable, robust product -- http://www.php-tools.net/site.php?file=/patForms/overview.xml -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: which operating system?
* Sebastian [EMAIL PROTECTED]: I will be building a new server and wondering what would be a good choice for php/mysql/apache other than redhat. I was thinking either Debian or CentOS. can anyone share their thoughts on them for php environment? does anyone use them on high traffic php sites? or is there not a difference in what distro you run php on? sorry these may sound like stupid questions but i mostly used redhat since i started using php and thought i'd try something different. Use an OS that either doesn't have an end-of-life for support, or which can be upgraded to a new version without breaking everything. I've used Redhat and Fedora, but will never use them for production servers again -- after a couple years getting out-of-date, it becomes next to impossible to find packages for them, and upgrading to a new version almost always requires an attended install, and usually down time. Debian and Gentoo are very nice in that you can upgrade packages as they become available, usually with no issues. You might also want to look into one of the BSDs, as the ports system many of them employ also allows seamless upgrades in most situations. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 'God' has spoken... :-)
* Sebastian [EMAIL PROTECTED] : Matthew Weier O'Phinney wrote: * Sebastian [EMAIL PROTECTED] : why php6 and not php5? look how long it took to get to php4 (with php5 just starting to rolling out) and people are already talking about php6? My observation was that more people jumped to PHP4 from PHP3 than have so far from PHP4 to PHP5. And PHP5 has hardly just started to roll out; the official 5.0.0 release was over a year ago. sure it is just a 'versioning' thing, but right now huge numbers of php users aren't using php5 (including me) on production environments, let alone start talking about php 6. And why aren't you using PHP5? Is there any specific reason? Is it because your service provider doesn't offer it? If so, ask them why -- and report it here. As soon as PHP5 hit stable, I started using it, and I've never looked back. Performance is better, and there are many features -- exceptions, the new OOP model, autoload, iterators, etc. -- that simply have no analogs in PHP4. anyway, i think i will be with php4 for a long time to come. Please tell the list why -- what does PHP4 offer over PHP5 for you? I honestly want to know, and I'm sure there are others who would be interested to see why people are not making the switch i spent hundreds of hours building my site on php4, im not about to rewrite any of it to make it 'compatible' with php5. Don't rewrite it to make it compatible with PHP5 -- rewrite it to take advantage of PHP5's better performance and new features. Besides, you probably will not need to rewrite any code -- probably just do some cleanup and a few changes. More below. maybe my impressions of php5 are wrong, but last i heard apps built on php4 may or may not work right under php5 - meaning you would have to rewrite code. am i wrong? I've converted quite a bit of PHP4 code to PHP5, and I've had very few problems. Typically, I find that I get a few notices about deprecated functions or some warnings -- and the warnings are usually about things that should have generated warnings in PHP4, didn't, but now do in PHP5 (things like declaring a class property twice, for instance). The fixes for these are typically not rewrites, but, as I said, fixes -- if anything, they make the code better. Additionally, it's fairly easy to make such code backwards compatible with PHP4, if you feel the need to do so. so i am 'afraid' of going with php5 in fear it will break my website. The only way to find out if it will break is to try it. I'm willing to wager that your code, if written well, will not only *not* break, but likely perform better. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: 'God' has spoken... :-)
* Michelle Konzack [EMAIL PROTECTED] : --TnYVF1hk1c8rpHiF Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 2005-08-14 00:48:23, schrieb Sebastian: i spent hundreds of hours building my site on php4, im not about to rewrite any of it to make it 'compatible' with php5. You are not alone... maybe my impressions of php5 are wrong, but last i heard apps built on=20 php4 may or may not work right under php5 - meaning you would have to rewrite code. am i wrong? Right, I have a Dual-Athlon MP1900 with 4 GByte of memory running Apache 1.3, php4, ssh und courier. This Server support curently around 4860 VHosts. Now, since the System Disk was gone, I I have installed Debian=20 3.1/Sarge with apache2, php5 and latest build of courier. Now ich more then 50 Clients connect to the website using php appications are kicked out of the memory. :-/ It seems that php5 consums much more resources then php4. Swichting back to the latest Debian 3.0/Woody Backup and all is working fine Actually, this is likely an issue with running Apache2 with *any* version of PHP. Try switching to Apache1 again with PHP5, and see if you get similar results. You shouldn't. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 'God' has spoken... :-)
* Robert Cummings [EMAIL PROTECTED] : On Sat, 2005-08-13 at 23:51, Matthew Weier O'Phinney wrote: * Sebastian [EMAIL PROTECTED] : Jochem Maas wrote: if you haven't seen it yet and are interested in the future of php you might be interested in the _big_ thread on php-internals that starts with the message: http://www.manucorp.com/archives/internals/200508/msg00398.php IMHO every halfbaked php coder should read it ;-) to cut it short for those to busy, or what not, Rasmus offered his his vision of php6 (which seems will be the version that will first bring the awesome unicode [and date?] functionality to the masses - hey thats us! :-) ) and there seems to be pretty much unanimous agreement on his main points (lots of discussion on more issues/ideas other people have brung up in response) the future's bright, the future is green. why php6 and not php5? look how long it took to get to php4 (with php5 just starting to rolling out) and people are already talking about php6? My observation was that more people jumped to PHP4 from PHP3 than have so far from PHP4 to PHP5. And PHP5 has hardly just started to roll out; the official 5.0.0 release was over a year ago. sure it is just a 'versioning' thing, but right now huge numbers of php users aren't using php5 (including me) on production environments, let alone start talking about php 6. And why aren't you using PHP5? Is there any specific reason? Is it because your service provider doesn't offer it? If so, ask them why -- and report it here. As soon as PHP5 hit stable, I started using it, and I've never looked back. Performance is better, and there are many features -- exceptions, the new OOP model, autoload, iterators, etc. -- that simply have no analogs in PHP4. anyway, i think i will be with php4 for a long time to come. Please tell the list why -- what does PHP4 offer over PHP5 for you? I honestly want to know, and I'm sure there are others who would be interested to see why people are not making the switch. While I've dabbled with PHP5 and made my framework compatible with it I haven't bothered to make a wholehearted leap into it. The following reasons basicly sum up why, and are probably common amongst those that aren't leaping into PHP5. - Better the devil you know than the devil you don't. Many PHP developers have spent years using PHP4 and know it inside and out and have come to terms with all of it's deficiencies... as few as those may be once you learn how to adapt to them. This is a fear-based argument. Arguments like this prevent innovation. Yes, I know PHP4's deficiencies and quirks inside and out -- but that doesn't mean I should stick with them. If I were to use that argument, I would never have left perl for PHP. PHP5 actually *fixes* many of PHP4's deficiences and quirks -- such as how objects are passed, how errors are handled, etc. I jumped onto PHP5 because I wanted a PHP that worked *better*. - A multitude of code already exists that is known to work under PHP4 but can be expected to have quirks when run under PHP5. Explain. My experience, while limited, has shown that well-written PHP4 code generally works quite well under PHP5. - Much of the code written in PHP4 works without the new features of PHP5 and so there's no compelling reason to invest time and resources for 0 ROI other than compatibility with PHP5. Except that if you stay on an old version of PHP4, someday it will be deprecated and you'll *have* to upgrade. I, for one, would rather take smaller steps over time between versions than need to scrap an entire project and rewrite it from the ground up when the version reaches end-of-life. The ROI may be zero or small now, but priceless later. - PHP5 had a large focus on bringing missing OOP features to PHP that have little merit to those who write mostly procedural code. The OOP rewrite was only a portion of the changes brought into PHP5. What about exceptions, or the mysqli support, or the simplexml addition, or...? There's a lot of stuff in PHP5 that procedural programmers can utilize. - Accelerators for PHP5 are not particularly good at this time, so unless you've got cash to shell out to Zend (which can be expensive for the little guy) then why move from your trusty PHP4 accelerators that already get the job done satisfactorily. As Rasmus noted under separate cover, the APC project has made tremendous headway in the past few months, and is working fairly well with PHP5 at this time. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: wrapping text
* John Taylor-Johnston [EMAIL PROTECTED]: Folks are complaining mail arrives and text will not wrap. $message comes directly from a textarea. Old mail readers, I guess? Not necessarily old. Many of us use text-based mail readers, where tradition and usability dictate line lengths of 72-80 characters. Also, many mail user agents render text/plain without wrapping lines (or make line wrapping optional). How can I make their life better and make the text wrap? Yep. Investigate http://php.net/wordwrap: mail([EMAIL PROTECTED], stripslashes($subject), stripslashes($message), Return-Path: [EMAIL PROTECTED]\r\nFrom: \[foo] foo\ [EMAIL PROTECTED]\r\nbcc: $bcc \r\nReply-To: [EMAIL PROTECTED] \r\n.X-Mailer: PHP/ . phpversion()); Make stripslashes($message) into wordwrap(stripslashes($message), 72). -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 'God' has spoken... :-)
* Sebastian [EMAIL PROTECTED] : Jochem Maas wrote: if you haven't seen it yet and are interested in the future of php you might be interested in the _big_ thread on php-internals that starts with the message: http://www.manucorp.com/archives/internals/200508/msg00398.php IMHO every halfbaked php coder should read it ;-) to cut it short for those to busy, or what not, Rasmus offered his his vision of php6 (which seems will be the version that will first bring the awesome unicode [and date?] functionality to the masses - hey thats us! :-) ) and there seems to be pretty much unanimous agreement on his main points (lots of discussion on more issues/ideas other people have brung up in response) the future's bright, the future is green. why php6 and not php5? look how long it took to get to php4 (with php5 just starting to rolling out) and people are already talking about php6? My observation was that more people jumped to PHP4 from PHP3 than have so far from PHP4 to PHP5. And PHP5 has hardly just started to roll out; the official 5.0.0 release was over a year ago. sure it is just a 'versioning' thing, but right now huge numbers of php users aren't using php5 (including me) on production environments, let alone start talking about php 6. And why aren't you using PHP5? Is there any specific reason? Is it because your service provider doesn't offer it? If so, ask them why -- and report it here. As soon as PHP5 hit stable, I started using it, and I've never looked back. Performance is better, and there are many features -- exceptions, the new OOP model, autoload, iterators, etc. -- that simply have no analogs in PHP4. anyway, i think i will be with php4 for a long time to come. Please tell the list why -- what does PHP4 offer over PHP5 for you? I honestly want to know, and I'm sure there are others who would be interested to see why people are not making the switch. kinda of how apache2 hasn't been a real success over apache1. That's a completely different story. Apache2's internal structure adds thread support, and since many loadable modules are not necessarily threadsafe, using them with Apache2 often negatively impact performance (PHP, for instance, must be run non-threaded because many of the libraries against which it links are not threadsafe -- and thus running PHP on Apache2 is much less efficient than on Apache1). The differences between PHP4 and PH5 are much more trivial, and those people who choose to use the features of PHP5 are not going to lose performance or functionality -- actually, quite the opposite. i just hope php doesn't end up being bloat-filled with the not-so-useful thing just taking up resources. I think one of the things I like most about PHP is that you can easily compile it with *only* the features you need -- it only needs as much bloat as you need to use it. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP smarty - nested queries and arrays
* Amanda Hemmerich [EMAIL PROTECTED]: I'm using PHP and Smarty to try to build an array of arrays using the results from nested queries. I am just learning about nested arrays, and I'm not sure what I'm doing wrong. I am hoping someone can give me a hint as to what I am doing wrong. I looked on php.net, but still couldn't figure it out. If I remove the PHP foreach loop, it works fine, except, of course, no sub projects show up. The error must be in there, but I'm just not seeing it. I get the following error with the code below: Warning: Smarty error: unable to read resource: welcome/Object.tpl in /usr/local/lib/php/Smarty/Smarty.class.php on line 1088 Actually, this error indicates it either cannot find or open the template file. make sure you have a 'welcome' directory in your templates directory, and an Object.tpl file within -- and that they have permissions such that the web server can open them. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Blatantly Evil Question
* Brian Dunning [EMAIL PROTECTED] : On Aug 11, 2005, at 4:06 PM, Evert | Collab wrote: First hit on google: http://www.searchengineworld.com/robots/robots_tutorial.htm Search engines check for a robots.txt on your site, in the robots.txt file you can specify that certain or all search engines shouldn't index your site I know what robots.txt is, I meant how would you use that to cloak the site. Put PHP code in robots.txt to log the IP of any requests to a db, and then use that db to cloak the rest of the site or not? If you want to dynamically determine what to disallow based on the UserAgent string, simply tell Apache, via an .htaccess file, to pass robots.txt to PHP for handling. Then have that script do the processing and return output compatible with the robots.txt specification. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php output to string
* Jesús Fernández [EMAIL PROTECTED]: thanks, it works, but that returns the php code. what i actually need is the output of that php code evaluated. So eval() the string... -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: dynamic object instances
* Thomas Angst [EMAIL PROTECTED]: I would like to create an object inside a function with its classname and a parameter list submitted by the function call. function create($class, $parameter) { $obj = new $class($parameter); return $obj; } This is working very well. But I have not every time the same count of parameters for a class constructor. If this is a normal method call of an object I can realise it like this: $ret = call_user_func_array(array($obj, 'method'), $parameter_array); The $parameter_array contains as many entries as the function needs. Works well too. But how can I write a function to instance objects with various count of parameters in the constructor? I know, can do this with an eval. But I would like to find a solution where I don't need an eval. Use the func_* functions, along with array_shift(). In addition, you'll need to use either a standard-named static instantiator, or the class name as the constructor method: function create($class) { $args = func_get_args(); array_shift($args); // remove $class from the args list // Do this if using a standard-named static instantiator method // across classes; in this case 'init': return call_user_func_array(array($class, 'init'), $args); // Or use a function named after the class name as the instantiator // method (ala PHP4): return call_user_func_array(array($class, $class), $args); } -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: need help finding parsing error please
* Bruce Gilbert [EMAIL PROTECTED]: Hello, I am getting this on the following code, and I am not sure what is causing the error and need some pros to take a look at it for me. the error is: Parse error: parse error, unexpected '{' in /hsphere/local/home/bruceg/inspired-evolution.com/Contact_Form2.php on line 161 snip if ($_POST['op']!='ds') { // they need to see the form echo $form_block; } else if ($_POST[op] == ds) { Where's the end to this elseif? You follow it immediately with the following lines, which simply won't work (can't define functions inside if() blocks). //Function saves time and space by eliminating unneccesary code function check($fieldname) { -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: need help finding parsing error please
* Jochem Maas [EMAIL PROTECTED] : Matthew Weier O'Phinney wrote: * Bruce Gilbert [EMAIL PROTECTED] : I am getting this on the following code, and I am not sure what is causing the error and need some pros to take a look at it for me. the error is: Parse error: parse error, unexpected '{' in /hsphere/local/home/bruceg/inspired-evolution.com/Contact_Form2.php on line 161 the error is correct. (that sounds funny) find the line containing: if (isset($err_msg) || isset($email_err) { echo and look _very_ _very_ carefully at it. look again. see it now? I don't know if my mail client made a mess of your code layout or if it was just a mess - if it was a mess to begin with then I would recommend you try and be more consistent in the way you present your code - it makes it easier to maintain and debug - granted php doesn't care about the layout - you can write everything on a single line if you really want. google on Coding Standards - pick a style your eyes like and try to stick with it - you wont regret it. +1 I personally use PEAR's CS, and made that decision a little over a year ago. I've never looked back, and code I've had to maintain that predates that decision gets updated -- simply because it makes maintenance and debugging a thousandfold easier. snip if ($_POST['op']!='ds') { // they need to see the form echo $form_block; } else if ($_POST[op] == ds) { Where's the end to this elseif? You follow it immediately with the following lines, which simply won't work (can't define functions inside if() blocks). Matthew but it's perfectly valid to define a function inside an if() block... It generally gets doen in apps where they have to support older versions of php and conditionally define functions if they don't exist e.g. if (!defined(array_push)) { function array_push($arr, $val) { /*stuff*/ } } D'oh! I was thinking this was an anonymous function (ala perl), and of course it's not. Good catch, Jochem. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: shell_exec(zip.. ?
* Sam Smith [EMAIL PROTECTED]: shell_exec(zip -r ddd ddd); // don't work Many version of zip won't append the .zip extension. In such a case, what you have above will try to name the zip file the same as the existing directory, which obviously won't work. Try: shell_exec(zip -r ddd.zip ddd); -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: syntax highlighting your php code on a web page
* Steve Turnbull [EMAIL PROTECTED]: Is there a class or some code out there which enables you to print your PHP code to a web page and make it appear with syntax highlighting? As an example of what I am after, have a look here; http://www.phpfreaks.com/phpmanual/page/function.ldap-add.html Please note this is just an example page which highlights what I am after... There's a few ways. highlight_file() and highlight_string() will do it. Another way is to symlink to the .php file as extension .phps -- and provide a link to the .phps file. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to determine if a script instance is already running?
* Matt [EMAIL PROTECTED] : Perhaps svscan and its associated daemontools programs could be used to monitor the script instead of relying on cron. Just a note: The above suggestion would assume you control the box, and that you're running on a *nix system (i.e., you've got root on a linux, bsd, solaris, AIX, etc. server). On 8/2/05, André Medeiros [EMAIL PROTECTED] wrote: On Tue, 2005-08-02 at 15:09 +0100, Stut wrote: André Medeiros wrote: Do like some services do: 1) Check if script.pid exists 2) If it doesn't 2.1) Write the process's PID onto the file (http://pt.php.net/manual/en/function.getmypid.php) 3) If it does 3.1) Die gracefully :) Personally I'd extend that slightly to have the process touch the PID file every so often and to check that it's been touched recently when it starts up. Alternatively use the ps shell command to check that a process with that PID is still running, but that tends to be less reliable. If the process does decide to continue in spite of the PID file existing it should issue a a shell kill command to kill that PID in case it's hung or a zombie. -Stut Excelent point! -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Performace and segfault errors with Php5 + Apache 1.3.x + linux-2.6.x
* Edwin Barrios [EMAIL PROTECTED]: i'am developing a web framework SifEngine (Secure Web Inteface framework) that implement MVC applaying the security ideas from http://phpsec.org. I'am using DomXML, Sqlite, Mcrypt and PostgreSql. After of post my development on the internet ( i have been thinking to post on PEAR ), i made simple tests of aplications with my framework. During the implementation, i used Slackware 10.1 with kernel 2.4.29 + php5.0.4 + Apache 1.3.2, with no problems. I didn't detect performace problems or segfaults by apache. Then i decided to do the same test but with kernel 2.6.10, wating that no problems occur. However my expectation, on this new configuration all the aplications develped with my framework, had performance issues or in the worst situation produce apache forks to be restarted, or a lot of apache forks. i don't undestand why this occur, i try to use valigrand to verify memorie lacks without results. Are you using __call() or any of the other overloading methods? I had a situation several months ago where __call() was going into an infinite loop and causing segfaults. Once I tracked that down and fixed it, everything worked fine. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: overwrite private class members in php5?
* Norbert Wenzel [EMAIL PROTECTED]: Hi, I've done something like this: class MyClass { private $var; function __construct($value) { $this-var = $value; } public function printVar() { echo($this-var); } } $object = new MyClass('1'); $object-printVar(); // prints 1 $object-var = 3; // Fatal Error as expected $object-$var = 2; // no error msg $var is empty, so this is setting a non-existent class property to 2. $object-printVar(); // prints 2 I got 1 when running this -- just as I would expect. Are you sure it printed 2? Basically, if a property is undeclared, it is assumed public, so you can set undefined properties without issue. If defined private or protected, the calling script will not be able to alter the value. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Class constants
* Marcus Bointon [EMAIL PROTECTED]: I'm not sure if this is a bug or a feature, but it seems you can't use class constants to set default values for class properties. You can, however, use them for default values for method params, e.g.: class foo {} const BAR = 100; private $thing = self::BAR; function wibble($a = self::BAR) { echo $a; } } In this case $this-thing will be undefined, but wibble() will get the correct default value for $a. Comments? This has been the case since PHP4. From http://php.net/oop: In PHP 4, only constant initializers for var variables are allowed. To initialize variables with non-constant values, you need an initialization function which is called automatically when an object is being constructed from the class. What is meant by 'constant initializers' is that you cannot define class variables based on variables, constants, or globals -- defined in the class or otherwise. So, the following is okay: private $thing = 100; But, as you saw, the following will barf: private $thing = self::BAR; private $thing = BAR; private $thing = $_SERVER['SCRIPT_NAME']; // etc. So, in other words, the issues you're seeing are consistent with the documentation. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: WAMP Performance Tuning
* JM [EMAIL PROTECTED]: I'm quoting out a system for a Windows/Apache/PHP/MySQL database-driven web application I've written. I've never gotten too deep into determining what is the actual performance bottleneck in this scenario. Is it the disk or the RAM? I expect about 75-100 users during business hours. 90% will be in the LAN and 10% will go over the WAN. I'm wondering if I can get good performance out of a small system with 2GB RAM, 1GBps NIC, and a SATA disk or three spanned. You don't indicate how many queries are made on a given page, how much data is handled, etc., Without seeing some code, it's hard to say what the bottleneck for performance will be. I've done some fairly critical stuff that, because I took the time to optimize the database, optimize how much data gets displayed at a given time (pagination is a *good* thing), streamlined the code to minimize file and database calls, and setup the box to only run what was necessary for serving pages, I was able to get away with using a sub-400Mhz box with 384MB of RAM and a 20GB drive (this was a LAMP setup). And it performed well, even with decent user load. Disk calls are always more expensive than RAM calls -- but if you're hitting a database, you're hitting the disk anyways (unless the queries are getting cached). Run benchmarks, and try to minimize the number of file calls and database calls to what is absolutely necessary. Consider dumping Windows for a Linux flavor, or one of the BSDs. You can tune these better to only run the services needed for the web stack (Apache, MySQL, cron, firewall, formail/msmtp/sendmail). Because of the shared-nothing architecture of PHP, you really don't need heavy hitting boxes in order to get good performance. They don't hurt, but they're not necessary. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: can I use Apache v 2 with PHP?
* Taksam [EMAIL PROTECTED]: I finally installed Apache 1.3.3 and PHP 5.0.4 engine and made my first PHP page and it works! thanks for your help! And didn't use an IDE, just UltraEdit :) but, I WILL use and IDE someday anyway. The beauty of PHP (and most scripting languages) is that you don't need an IDE ever. A good editor with syntax highlighting will get you where you need to go reliably. I use vim. Now, my question is: can I use Apache version 2 with PHP? And, even if I can use it in my development environment... is it safe to use Apache 2+PHP in a production environment? Yes. But there *are* issues with it. The biggest thing Apache2 introduced was threaded processes. Unfortunately, PHP isn't necessarily threadsafe -- not all of the libraries it can be compiled are threadsafe, and many are in a state where thread status is simply unknown. (My understanding is that the PHP core is probably threadsafe; it's the extensions -- database, mail, etc --- that you can't be sure of. Somebody correct me if I'm wrong.) The upshot is that when compiling PHP to work with Apache2, you have to compile it to work without threads -- which means that, in the end, there are no performance gains, and, in most instances, PHP performance actually suffers under Apache2 (up to 30% decrease). John Coggeshall announced today that he is going to work to get PHP completely threadsafe, but my guess is that this will likely be a late version of PHP 5.1, if not even another minor version (5.2, 5.3) before it's complete. By the way -- I'm hoping you meant Apache 1.3.33, and not Apache 1.3.3... ;-) -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with a home-grown function
* Ford, Mike [EMAIL PROTECTED] : On 21 July 2005 22:19, Chris W. Parker wrote: 2. It will be a good idea to get out of the habit of breaking in and out of PHP like that. Instead just do: echo 'hi1'; Why? Some of us just strongly prefer the breaking in and out style -- I use it almost exclusively. In my 10,000s of lines of code, you can probably count the number of echos on your fingers! You'll have problems down the road with modifying the headers (cookies, redirects, content-type, etc.) if you break in and out. Absolute rubbish -- whatever gives you this idea? The sequence ? x?php Is functionally identical to echo 'x'; so anything that works with the latter will work identically with the former. I disagree with both statements. Echoing and breaking out of PHP are typically both undesirable in large applications where you may wish to change headers. Capture your output into a variable and send it to output once all processing is done. This may be done using output buffering or other techniques. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: performance.
* Rodolfo Gonzalez Gonzalez [EMAIL PROTECTED]: this could be a silly question. Is there some performance penalty when using the operator like this: $var =EOP add a bunch of text here and here EOP; Just curious. Try doing some benchmarks using microtime(). My gut reaction is that there shouldn't be any difference; heredoc syntax is simply another form of quoting strings. The other factor to consider is if a few microseconds more of processing time is worth the extra programming time it takes to get quotes right (assuming heredoc syntax *does* take longer). I personally prefer heredocs when using long, multiline strings to using double quotes -- they're easier to maintain. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: quick question about using capital letters coding w/ PHP
* Bruce Gilbert [EMAIL PROTECTED]: I am well versed in coding with xhtml which requires all lower case and am pretty much a newbie at PHP so that is why I am asking this question. is this acceptible if ($_post [sender_email] == ) or does at have to be if ($_POST [sender_email] == ) in short, do uppercase and lowercase always have the same meaning. PHP is case sensitive. Additionally, quotes, or the absense of quotes, can change the context. I bring this up because the example you have above, $_post[sender_email] contains two errors: * $_post will likely be empty, whereas the PHP superglobal $_POST will likely contain the data you're looking for ;-) * $_post[sender_email] refers to the value in the $_post array returned by an array key that is the same name as the value of the constant sender_email. You almost certainly were actually meant $_POST['sender_email'] (note the quotes), which would refer to the value associated with the array key 'sender_emaail' in the $_POST array. You should probably do some reading in the introductory chapters of the PHP manual, specifically the variables section: http://php.net/variables Cheers! -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PEAR DB issue
* Chris Boget [EMAIL PROTECTED]: I'm using PEAR::DB to connect to a MS SQL Server 2000. I'm attempting to run the following query: SELECT * FROM myTable FOR XML AUTO, ELEMENTS When I run the above query using the Query Analyzer, I get back the results as expected. However, when I try to run the same query using PEAR, I get the following error: [nativecode=4004 - Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier.] and I'm not sure why. I've googled the error and see that alot of other people are getting the same error (though, it doesn't seem that they are necessarily using PEAR). From what I can tell, it is a client error and not a server error. So my questions are 1) is there something wrong with PEAR and 2) if so, is there a fix in the works? Does anyone know? But that aside, has anyone else come up against this issue and found a workaround using PEAR? You should probably post this to php-pear-general, or to the pear-dev list. If no response there, or if no solutions are forthcoming, file a bug report with PEAR::DB. PEAR::DB *is* under active maintainership, from what I can tell, and some of the more recent changes had to do with MS-SQL report, if memory serves. Good luck! -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Content Header
* Richard Lynch [EMAIL PROTECTED] : On Thu, July 21, 2005 4:55 am, Chris Shiflett said: Christopher J. Umina wrote: I currently have a script which streams data out of a MySQL database, and prints the content headers correctly, however, when I use the following line: header(Content-Disposition: attachment; filename=\. $filename .\); it prompts the user to download the file each time they go to the site. Then it works. :-) But it will only work on *SOME* browsers -- those which honor the johnny-come-lately Content-Disposition header. Use Content-type: application/octet-stream to guarantee it gets downloaded in ALL browsers. The OP indicated s/he *was* setting Content-Type. They were also sending Content-Disposition in order to indicate the suggested filename -- and wanted to alternately either send the filename *or* have the content echoed to the screen. The 'solution' was to use different URLs, and set Content-Disposition to either 'attachment' or 'inline', respectively. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] db insert question
* JamesBenson [EMAIL PROTECTED] : Thanks for your reply, your example demonstrates what i was doing but does that do a MySQL query for every piece of data? So 20 form values would be 20 db queries, would that not consume a lot of resources? Not necessarily. If you use a prepared statement first, then execute it, you'll get excellent performance. If you're interested in prepared statements, or don't know what they are, look at DB abstraction layers like PEAR::DB, PEAR:MDB(2), and ADODB -- they utilize them. As an example: $sql = INSERT INTO someTable(field1, field2, ...) VALUES (?, ?, ...); $insert = $db-prepare($sql); foreach ($data as $vals) { $db-execute($insert, $vals); // Assuming each element of $data // is an array of values } Basically, you prepare a SQL statement that contains placeholders for the values. Then when executing the statement, you pass an array of values equal to the number of placeholders in the statement. The benefits are (a) speed, and (b) security. Regarding (b), the values are quoted in a proper format for your RDBMS, so you don't need to worry about escaping each and every value -- the DB abstraction layer and/or the RDBMS takes care of it for you. Is their another way? Yes -- Build your SQL first, in the following format: INSERT INTO someTable(field1, field2, ...) VALUES ('rec1Field1', 'rec1Field2', ...), ('rec2Field1', 'rec2Field2', ...), ('rec3Field1', 'rec3Field2', ...); And some PHP code that could help create this: // Beginning of SQL $sql = INSERT INTO someTable(field1, field2, ...) VALUES ; // Loop through records to insert $INS = array(); foreach ($data as $values) { $final = array(); // Loop through each value in the record and quote it foreach ($values as $val) { $final[] = sprintf('%s', mysql_real_escape_string($val)); } // Join them with commas and enclose all in () $INS[] = '(' . implode(',', $final) . ')'; } // Finally, join all the records with commas, and end the SQL with a // semicolon $sql .= implode(',', $INS) . ';'; $result = mysql_query($sql); HTH... Jim Moseby wrote: Im using mysql with PHP4, whats the best way to insert as many as 20 records at one time from a form? Currently im just assigning each one a variable but that is messy and takes ages, is their a way to loop over the array of form data then maybe do the same to enter it into a database? Thanks for any help. A generic question begs a generic answer: foreach($formdata as $thisdata){ $result=mysql_query(insert into ... values($thisdata) where ...); } Hope this helps, but it would be useful to have code examples, etc so that a more relevant answer could be rendered. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Content Header
* Christopher J. Umina [EMAIL PROTECTED]: Hello! I currently have a script which streams data out of a MySQL database, and prints the content headers correctly, however, when I use the following line: header(Content-Disposition: attachment; filename=\. $filename .\); it prompts the user to download the file each time they go to the site. The problem is, I want the filename to be in the header, incase somebody right clicks and saves the file, but I don't want the user to be prompted to download the file when they're just trying to look at it. Does anybody know a way I can achieve this result? As long as the Content-Disposition: attachment header is present, the browser will believe a file is being sent. One solution is to have two different links, with an optional download flag in the query string. Then, in your script, generate the Content-Disposition header for 'download' requests, don't otherwise. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting file size before upload
* Jay Blanchard [EMAIL PROTECTED]: [snip] I know it is a often asked question, but after googling for about 2hours and trying out some wired examples I am still not any closer to a solution. So I was hoping to find expert advice here. I want to save the user the hastle of uploading a 2MB file and waiting for a long time for an error message that the file is to big. Is there any usefull workaround in warning the user that he is about to upload a 2MB file and only smaller files are supported? I tried around with megaupload: http://sourceforge.net/projects/megaupload to get a progress bar and to get the file size prior to upload, but that somehow does not work the way I want it to. Is there an easier solution without perl,just with PHP or/and JS? [/snip] http://www.php.net/stat The OP wants a solution that is client-side -- stat() would be server-side. And, to answer the OP's question, no, there is not a reliable way to do this. You can provide some hints via the HTML form -- set hidden keys for MAX_UPLOAD_SIZE, for instance -- but many browsers ignore these. My understanding is that it's possible to use javascript in some cases to determine the file size on the upload element's population, but that is going to be unreliable as well, due to differences in client OS and browser javascript implementations. The easiest solution is to simply provide some warning text indicating that the file size should not exceed a certain threshold -- and give back a nice, big error message when it does so they know why the upload failed. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: jpgs into database
* Jasper Bryant-Greene [EMAIL PROTECTED] : George B wrote: is it possible to put in a jpg file into a database? I am trying to make like a catalong and have all the files (including pics) and everyone can see. is this possible? Sure -- if you're using a MySQL database, just use a BLOB field and put the data in as you would a string of text. Be aware of your storage requirements, however. There are several BLOB types -- TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB -- so make certain you choose the one that exceeds the maximum file size you expect to place in the DB. Additionally, there are performance hits to storing images in a database. Another approach that is widely used is to store the images on the filesystem, and then image *details* -- location, size, caption, photographer, etc. -- in the database. This is typically faster, and will reduce the number of DB calls. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] syntax error, unexpected T_STRING
* George B [EMAIL PROTECTED] : Jim Moseby wrote: I am trying to connect to a datbase: mysql_select_db ('database') or die (couldnt connect to databse) What is wrong here? This is the error: Parse error: syntax error, unexpected T_STRING in file name on line 12 Extra spaces, and no semicolon? try: mysql_select_db('database') or die(couldnt connect to databse); Thanks JM! It was another one of my usual mistakes :P Forgot the semicolon. I don't underestand why you have to put in so many semicolons... Hmm.. Is it a thing from C or something? C *AND* something... PHP borrows heavily from both C and perl (and a variety of other languages) -- both of which use this notation. Most languages I've used other than python use a delimiter to indicate the end of a statement (python does as well, technically -- the EOL character). -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: change letter to all caps
* George B [EMAIL PROTECTED]: Lets say I have a form. And when user types in the form and clicks go, it shows output. but. lets say the person type in monday But I want the php code to change it too MONDAY how do I do that? The PHP manual is your friend, if you know what to look for. You're manipulating a string, so look in the 'Strings' section of the manual (http://php.net/strings). Then look for words like 'case' or 'upper', and you'll find: strtoupper - Make a string uppercase Enjoy! -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP 5 Object Inheritance
* Chris [EMAIL PROTECTED]: I've got a collection of Element classes (about 8 different ones). They are all subclasses of a single parent element. I'm trying to extend their functionality (both the individual classes, and the parent class they inherit). I can extend each Element subclass with it's new specific functionality, but I would also like to add specific functionality to all of the subclasses. Extending the parent element with the new functionality would *seem* to be the way to go, but I can't make it work None of the Subclasses inherit from the extended superclass. That should work. Have you checked your include_path to make sure a different, unmodified version of the parent class isn't getting loaded? -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $PHP_SELF or echo $PHP_SELF
* Richard Davey [EMAIL PROTECTED]: Hello Ross, Thursday, July 14, 2005, 11:11:25 AM, you wrote: R Just a quick thing that is bugging me. In some of my older R textbooks a form is returned to the same page by using R echo $PHP_SELF no just $PHP_SELF R is this just used in older versions of php?? Does the it make a R difference what one is used? PHP_SELF is part of the $_SERVER super global, you should really access it like this: $_SERVER['PHP_SELF'] To answer your question though, it's just a variable - if you want to output it into your form action then you can do either: ? echo $_SERVER['PHP_SELF'] ? or ?=$_SERVER['PHP_SELF']? Either would work. Actually, to be truly portable, it should be: ?php echo $_SERVER['PHP_SELF']; ? Not all hosts have short tags enabled in their PHP installations. Additionally, you have to be careful with PHP_SELF. On web servers that allow PATH_INFO -- i.e., arguments to the script in the form of path information, like '/path/to/script.php/more/path/info -- PHP_SELF will contain the path to the script PLUS the contents of $_SERVER['PATH_INFO'] -- which leaves PHP_SELF vulnerable to cross-site scripting attacks. For some discussion on this, see: http://blog.phpdoc.info/archives/13-XSS-Woes.html If you're using Apache, the safer bet is to use $_SERVER['SCRIPT_NAME']; otherwise, use PHP_SELF, but filter it to exclude the path information. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Template Engine with Event Handlers
* Rory Browne [EMAIL PROTECTED]: Anyone know if any of the current PHP templating solutions implement event handling? I mean something similar to ASP.NET's onClick events, etc. I was thinking maybe a js-triggered ajax system, which allowed php to access some of the JS Objects? I was thinking about doing something like this, and just want to make sure that there isn´t already something done like this. You can probably use an existing template engine in combination with JPSpan, Sajax, or another PHP + AJAX solution (google for them, or google for Joshua Eichorn, who has many such resources listed on his blog). -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: pear channel
* blackwater dev [EMAIL PROTECTED]: I am trying to install something via pear and have tried to add the channels from two different programs but get errors each time: pear channel-discover pear.chiaraquartet.net PHP Warning: PHP Startup: Unable to load dynamic library './php_mcrypt.so' - ./php_mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0 Command 'pear.chiaraquartet.net' is not valid, try 'pear help' I tried this with another channel and got the same error...of course the channel name was different. Is there something special I need for this? I have php 5.0.3 You need to compile PHP --with-mcrypt and --with-mhash, as the PEAR installer for =1.4.0 is dependent on one or more libraries that require these. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Help - need to quickly optimize a record count!
* Brian Dunning [EMAIL PROTECTED]: I am cross-posting this to the PHP and the MySQL lists because I'm not sure in which technology my solution will lie. I have a pretty busy PHP/MySQL site that executes the following query a lot: select count(*) as `count` from terms; My MySQL account was disabled by my ISP because this query was causing resource issues, so I need to find a different way to know the record count in that table. A few records are added once every 5 minutes by a cron job. The record count is constant the rest of the time. No records are ever deleted. Is it possible to create some kind of server-side variable, in which the cron job could store the record count, which would be accessible to all scripts, and would stay the same until it gets reset? Or is there a less-intense MySQL query I should be using instead? If the cron job is running anyways, you could run the count query after updating, and then store the count in a file. Then have your scripts read from that file. You could also store the count in the database. Another possibility is to run the count once, and then each time you add records, add the count of new records to that count. Again, storage could be in either a file or a DB. Either way, you're down to doing the count at most 12 times per hour, instead of every time your scripts are hit. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: x years old
* Ryan A [EMAIL PROTECTED]: This is the code I am using to display a persons age from the mysql db: $day1=strtotime($age); $day2 = strtotime(date(Y-m-d)); Just to be pedantic... just use time() for the above statement; no reason to do extra work here. (date() will actually call time() anyways) $dif_s = ($day2-$day1); $dif_d = ($dif_s/60/60/24); $age = round(($dif_d/365.24)); And, as someone else mentioned, you want to do floor() here, as somebody is 16 until their 17th birthday. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] PHP vs. ColdFusion
* Andrew Scott [EMAIL PROTECTED]: CF is very rapid development, and you might say the same about PHP. The point is that these are all the things you need to take into consideration, the cost that it would take to develop and maintain in either language, as well as cost involved in the need of the application having to be a true enterprise solution. I am not here to bag php, I am here to make some points about the cost of the application in the overall scenario. Would you develop in a language that you know could not deliver an enterprise solution if in 6 months that's what you really need, and how would you look if you recommended a language because it was free, but in time had to spend more again to make it fully scalable to an enterprise level if it needed it. You've insinuated several times that PHP is not 'scalable to an enterprise level'. Could you perhaps explain what you mean by this? One informal definition for 'enterprise framework' I've read recently is an enterprise framework allows the end-user to drop in only the business logic to make it work; they do not need to add anymore programming to the framework (http://benramsey.com/2005/05/09/what-is-an-enterprise-framework/) Now, I've seen a number of PHP frameworks where this is the case; you drop in a config file of some sort, point your application to it, and voila! Solution delivered! That doesn't address scalability, however. So, let's look at that. I'm not sure how CF scales, not having been in a CF shop. However, I know what I can do to scale PHP: * Use code optimizers/bytecode caches (zend, apc, eAccelerator) * Build an LVS-HA cluster for a web farm (i.e., increase the number of machines able to serve data and pages) * Focus on code optimization (i.e., make my code as efficient as possible) (As an aside, the beauty of a cluster is that you can add or subtract machines without the public noticing; the site remains up. Additionally, since all the director does is pass requests to the nodes, and possibly relay the responses back to the requestor, you can have machines of just about any configuration running on the backend -- Linux, FreeBSD, Windows, etc. -- so long as they speak the HTTP protocol.) Could you please share why you feel PHP isn't enterprise ready, or why CF is more enterprise ready? Other than the java integration; others have pointed out that the Zend platform addresses that issue. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Object Oriented PHP (5)
* Richard Lynch [EMAIL PROTECTED] : On Fri, June 24, 2005 12:56 pm, Josh Olson said: PHP has inspired me to become a better programmer. I have been actively reading books as well as online content to try to become better at designing and programming object oriented web applications. My primary focus is PHP. Will you help a pragmatic programmer in training out by suggesting some worthwhile resources? I have read the following already: snip I didn't read any of those books. snip One other piece of advice: Write lots and lots of code. Lots of it. Amen. Only after approaching similar problems several times will you find a more general, elegant solution that could solve all of them. It's the repetition of the problem, and the differing approaches that inform your ability to program towards it. The only way to get there is doing lots of coding. Re-write some old code of your own. Amazingly instructive, and often leads you to new heights. Plus your old stuff suddenly has a lower maintenance cost, for some odd reason... :-) I do this all the time. It's invaluable. Sometimes you find some little gems -- and most of the time you discover how much you've learnt since then, and you refactor it and make it better. Publish some articles or code snippets on your site. The act of trying to explain what you did to somebody else will open up worlds of understanding. You never really understand something until after you've taught it to somebody else. :-) I keep a blog, mostly about my PHP development. I do this in part for myself. If I act as if I'm explaining it for someone else, I often get to the meat of an issue or problem -- a place I might not have visited had I not spent that extra time trying to understand it enough to explain it. My blog has a public face, but it's really for myself. snip Try to work on a project with another developer. You may tear your hair out. You may want to kill them. You may learn a whole hell of a lot. Maybe what you learn is that a whole lot of developers just don't think like you do. That's okay too. At least, it's okay for me. :-) [shrug] I work with another developer, and we're constantly refactoring each other's code. But the brilliant part of it is that we then learn from each other as well. Do some code review for another developer some time. As Richard notes, writing lots of code will improve your coding ability; so will *reading* lots of code. snip Ooooh. At the risk of being branded a heretic, try to pick up another language or two. Start with something a whole lot like PHP. Maybe Perl, or even C. I wouldn't understand PHP half as well as I do if I didn't know perl already. I still use perl regularly; sometimes it's suited for the task. But that's another reason to learn other languages -- to determine when PHP is the right tool for the job, and when another language is. Well, that got long and philosophical, didn't it? Yes, but well worth th read. Thanks, Richard! -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP vs. ColdFusion
to develop in coldfusion. But you may need to spend money for the actual application server. I'm not going to debate the merits of PHP versus ColdFusion; I'm not familiar enough with the latter to make an objective case. However, I think the important thing here is that if you know a language inside out, it will almost always be easier to do development in that language than in one to which you've had less and less frequent exposure. PHP is certainly a good web programming language. So is ColdFusion. I'm choosing PHP because: * It's free; I don't need to purchase anything in order to run programs written in PHP. * No vendor lock-in. I can run it on a variety of web servers, and on a variety of OS flavors. * Variety of plugins. I can mix and match a variety of RDBMS drivers, choose what extensions I may want (IMAP is unnecessary, but I want FTP, etc.). * Community support. I don't have to pay for support, and there's a large community of developers upon whom to draw. Some of these may be true for ColdFusion as well. What the OP needs to do is determine what merits PHP or ColdFusion may have over the other, as well as what demerits might be present for each, and then evaluate those in the context of their work environment. -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Stop spreading PEAR FUD; WAS Re: [PHP] Re: PHP web archeticture
* Catalin Trifu [EMAIL PROTECTED] : I also tend to stay away from PEAR, which is kinda bloated for my taste, except the Log package. rant I hear that a lot on this list, and I don't understand the reasoning behind such comments -- perhaps because nobody offers any reasoning, only the opinion? I'm a PEAR user, and I've found the packages anything *but* bloated. Granted, I only use a subset of PEAR, but that subset has made mycoding easier. I use DB, Log, Mail, Mail_MIME, HTML_QuickForm, Cache_Lite, and Pager daily; additionally, we use custom PEAR error handlers to catch errors generated by these packages, log them, and display custom error pages. If I'd had to write the functionality I have readily available in these packages, I wouldn't have a job right now. They've helped me meet numerous deadlines. If somebody could offer some *constructive* criticism of PEAR -- PEAR as it is TODAY, not 3 years ago, when I last tried it -- these comments would have more weight. As it is, I feel they're just FUD based on ignorance. /rant -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop spreading PEAR FUD; WAS Re: [PHP] Re: PHP web archeticture
* Robert Cummings [EMAIL PROTECTED] : On Sat, 2005-06-25 at 10:32, Matthew Weier O'Phinney wrote: * Catalin Trifu [EMAIL PROTECTED] : I also tend to stay away from PEAR, which is kinda bloated for my taste, except the Log package. rant I hear that a lot on this list, and I don't understand the reasoning behind such comments -- perhaps because nobody offers any reasoning, only the opinion? I'm a PEAR user, and I've found the packages anything *but* bloated. Granted, I only use a subset of PEAR, but that subset has made mycoding easier. I use DB, Log, Mail, Mail_MIME, HTML_QuickForm, Cache_Lite, and Pager daily; additionally, we use custom PEAR error handlers to catch errors generated by these packages, log them, and display custom error pages. If I'd had to write the functionality I have readily available in these packages, I wouldn't have a job right now. They've helped me meet numerous deadlines. It may be my opinion, but I've also given some reasoning for my opinion: help in meeting deadlines, centralized error handling, and variety of packages. I've helped to *qualify* my opinion. I'll do more of that below. No matter how many deadlines PEAR helps you meet and how much you may find the PEAR modules indispensable, you are expressing a subjective opinion unrelated to the OP's comment about bloated. A package can be very bloated and still be extremely useful to someone who doesn't have the time or the ability (not to say you don't have the ability) to implement similar functionality themself. Correct; ability isn't the problem; time often is. aside However, I also find that I start by creating some functionality myself, and then as special cases start popping up, modifying, adding on... and then discovering that an equivalent PEAR package already exists that covers all these special cases and a number I hadn't thought of. (Pager comes to mind). I often wonder if what is meant by 'bloat' is that those claiming 'bloat' feel that the PEAR code covers too many special cases -- cases they have not encountered or do not expect to encounter. Personally, I feel that I'd rather have all my bases covered; I can see a point in wanting to keep code trimmed to the necessary cases, though. /aside Additionally PEAR does present a centralized location for common functionality with good peer review, This is one of the selling points for PEAR; many eyes looking at the code, including people who aren't invested in the particular problem. Having the diversity of reviewers often makes for better code. however IMHO I side with the OP with respect to much of PEAR being bloated. Then explain what you mean by 'bloated'. Just throwing out that phrase doesn't give anybody any extra information -- just your opinion. Can you give some examples to *qualify* your statement that PEAR is bloated? That was the main thrust of my rant -- people throwing out unqualified opinion statements like 'PEAR sucks' or 'PEAR is bloated' without explaining *why*. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop spreading PEAR FUD; WAS Re: [PHP] Re: PHP web archeticture
* Robert Cummings [EMAIL PROTECTED] : On Sat, 2005-06-25 at 11:06, Matthew Weier O'Phinney wrote: * Robert Cummings [EMAIL PROTECTED] : On Sat, 2005-06-25 at 10:32, Matthew Weier O'Phinney wrote: * Catalin Trifu [EMAIL PROTECTED] : I also tend to stay away from PEAR, which is kinda bloated for my taste, except the Log package. rant I hear that a lot on this list, and I don't understand the reasoning behind such comments -- perhaps because nobody offers any reasoning, only the opinion? I'm a PEAR user, and I've found the packages anything *but* bloated. Granted, I only use a subset of PEAR, but that subset has made mycoding easier. I use DB, Log, Mail, Mail_MIME, HTML_QuickForm, Cache_Lite, and Pager daily; additionally, we use custom PEAR error handlers to catch errors generated by these packages, log them, and display custom error pages. If I'd had to write the functionality I have readily available in these packages, I wouldn't have a job right now. They've helped me meet numerous deadlines. It may be my opinion, but I've also given some reasoning for my opinion: help in meeting deadlines, centralized error handling, and variety of packages. I've helped to *qualify* my opinion. I'll do more of that below. Your argumentation is flawed, you are using a red-herring technique to justify how PEAR is not bloated by giving examples of its usefulness. Actually, my argumentation was not specifically about 'PEAR is bloated', but more along the lines of the many comments I've seen on this list to the effect of 'PEAR sucks'. But I've also seen many comments like the one from Catalin about 'PEAR... is kinda bloated', without indicating why they think so. I should have been more clear in my rant that I'm tired of hearing generalized negative statements against PEAR that are then unqualified (i.e. no substative reasons given). The statement 'PEAR is bloated' doesn't indicate in what way it is bloated. Unfortunately, many read 'bloated' as a negative, and thus as an indication that one should stay away from the code; thus may a developer who has a problem that could be easily solved by PEAR code be turned away from it. Additionally, saying 'PEAR is bloated' doesn't take into account the fact that PEAR is a large group of packages, and that each package within PEAR should be judged on its own. For instance, I've heard and read some good arguments as to why the PEAR package itself is bloated; however, if you've ever taken a look at Cache_Lite, you'd probably agree that it is anything *but* bloated. (The authors of that package put no dependency on PEAR.php, and coded with a goal of efficiency and optimization.) snip Then explain what you mean by 'bloated'. Just throwing out that phrase doesn't give anybody any extra information -- just your opinion. Can you give some examples to *qualify* your statement that PEAR is bloated? That was the main thrust of my rant -- people throwing out unqualified opinion statements like 'PEAR sucks' or 'PEAR is bloated' without explaining *why*. So far all the reasons you've given to indicate why PEAR is NOT bloated have nothing to do with why PEAR is or is not bloated. You have clearly indicated a passion for it, a usefulness from it, even established a decent amount of superiority in it, but if anything your arguments have indicated why it is bloated in many respects: - covers all of these special cases (and by virtue probably more) - I can see a point in wanting to keep code trimmed to necessary cases though - rather have all my bases covered It is my opinion and the opinion of many others that the fact that PEAR covers so many exceptional cases, the fact that PEAR implements such a generalize error handling system, the fact that PEAR do so much generic everything to make everone happy, that these elements that make it so versatile also make it feel bloated. It's like kicking a soccer ball to the goal, but rather than take the most direct route, you take the fringe route to cover all your bases...ultimately this is generally a longer path. And, as I said, I can completely see your point. But, as noted above, saying PEAR gives a false impression that *all* code in PEAR is bloated, which is simply not the case. On the other hand, you've also given a very nice overview of *why* people feel some code in PEAR is bloated -- which is what I've been driving at. You've qualified the statement, and that's worth much more than simply tossing the phrase off. Thank you! I guess the moral of the story is: we now have a thread we can point to that shows some of the arguments for why some consider code in PEAR bloated, but also that : * bloat != lack of usefulness. * not all code in PEAR is bloated Thanks for your responses, Rob. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org
Re: [PHP] Stop spreading PEAR FUD; WAS Re: [PHP] Re: PHP web archeticture
* Paul Waring [EMAIL PROTECTED] : On Sat, Jun 25, 2005 at 10:32:41AM -0400, Matthew Weier O'Phinney wrote: If somebody could offer some *constructive* criticism of PEAR -- PEAR as it is TODAY, not 3 years ago, when I last tried it -- these comments would have more weight. As it is, I feel they're just FUD based on ignorance. The documentation for some of the less well known packages is poor or non-existant, or at least that's what I've always noticed and has been my major bug bear with PEAR for a long time. Indeed, the DocBook requirement for PEAR documentation is a major issue even with PEAR developers. For example, I want to use the DB_Pager module but there is *no* end user documentation, all I have to work with is some poorly formatted information pulled from the API comments. Just an FYI: Use the Pager package instead. Under doc/Pager/examples in your PEAR directory is a Pager_Wrapper.php script that shows how to use it easily with DB. Pager, unlike DB_Pager, is well documented. There are also a lot of packages (again, less well known ones) that haven't been updated in a long time, in some cases several years. I'm not saying that PEAR in general is a stale project, or that it's no good (on the contrary, I use several of the packages on my sites and they're very useful), but I do get the feeling that the non-core packages have been left to rot both in terms of updates and documentation. This is an issue I've seen PEAR attempt to address this past year through the introduction of its QA team. But the process is still far from tuned. The above are *great* examples of why people might not choose PEAR -- and constructive ones at that. Thanks. I've used both PEAR and CPAN for a few years now and I've noticed that CPAN tends to win hands down in terms of documentation and updates. That might just be down to the particular packages I've happened to use but given a choice I know which one I'd rather use. Ah, a fellow perl developer! CPAN is, for me, *the* reason to code in perl. The perl culture is one that includes testing and documentation as the norm -- and that has made for a solid library in CPAN. However, the TIMTOWDI principle also means that forking is a foundation principle. This can be seen as either a pro or a con: pro, in that you have choice in what module to use; con, in that you then have to evaluate a number of modules. After having said that, though, I'll continue coding PHP anyday! -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Module testing; WAS Re: [PHP] Stop spreading PEAR FUD; WAS Re: [PHP] Re: PHP web archeticture
* Chris Shiflett [EMAIL PROTECTED] : Matthew Weier O'Phinney wrote: The perl culture is one that includes testing and documentation as the norm You might be interested to know that there is a PHP equivalent for Test::More, the CPAN library that prompted the testing revolution that Perl seems to have undergone in the past five years or so. It is packaged as a standard part of Apache-Test (which now has support for testing PHP applications): http://search.cpan.org/dist/Apache-Test/ I've seen you mention Apache-Test before, but I didn't realize that it had integrated PHP testing in it. Looks interesting. I've actually been using phpt tests for a number of months now, and find them very well suited for most tasks I throw at them (typically API testing). However, I could see Apache-Test being useful for full application testing. Thanks for pointing this out! -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop spreading PEAR FUD; WAS Re: [PHP] Re: PHP web archeticture
* Colin Ross [EMAIL PROTECTED] : I don't think a lot of people think tat PEAR sucks, we are all, as a community, just looking for ways to make it better. I don't think a lot of people think it sucks; it's just that I often see statements on this list like 'PEAR sucks' or 'PEAR is bloated' without the authors of said statements offering any reasons why they think so. I wanted to address these reasons, instead of just letting the comment slide on by this time. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Strange notation to create object
* Robert Cummings [EMAIL PROTECTED] : On Fri, 2005-06-24 at 10:02, Jason Barnett wrote: Robert Cummings wrote: ... There's a difference between a reference to a reference and a copy of a reference *hehehe*. Now that makes sense. And am I correctly filling in the blanks when I guess that $foo3 = $aObj is merely copying the reference instead of referencing the reference? I probably could have written that more clearly, but I think you get what I'm saying. Yeah, *grin*. And on that note, there are times when you will actually want $foo = new SomeClass(); versus $foo = new SomeClass(); since assigning by reference will break any previous references -- something I forgot to mention to Matthew Weier when he challenged the relevance of the snippet I sent. Funny... I just ran into that last night as I was writing some unit tests for an app that uses PEAR_ErrorStack! I was unsetting the object, but that only unset the reference to it -- and so the singleton reference that PEAR_ErrorStack created was still available when I instantiated a new object -- which meant previous errors were still present in the object. So, I stand corrected; I've seen it now! Good discussion! -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP web archeticture
* Joe Muddah [EMAIL PROTECTED]: I am trying to design a website archeticture. Does anyone have any links or experience with archetictures that actually work. Any ideas of how to layout a website would be greatly appreciated. This is what I am thinking of doing 1)Seperate Logic from presentation Using Templates (Smarty) for presentation Using PHP Objects for logic (no echo statements) 2)Use Controllers to bring together logic and presentation I don't really have an idea yet of how to do this. I am thinking about having something like a page variable to figure out what template to output, action variable to figure out what objects are called (save, delete, etc.). All this would be under a switch statment. Example: shamelessSelfPromotion I'm the author of the PHP port of Perl's CGI::Application, Cgiapp.class.php (http://cgiapp.sourceforge.net/). Cgiapp is designed for exactly the usage you present above. It is a lightweight, abstract Controller class upon which you build your application class. All screens are handled as 'run modes', and each run mode is a method in the class. Templates are used by default, with Smarty being the default engine, though the template methods may be easily overridden to accomodate other template engines (several users indicate they use it with Savant). Additionally, it's built to allow the creation of reusable, customizable web applications. Your libraries can be placed in one location, and then instance scripts in your document root may customize the behaviour of the application through parameters passed to the constructor. I've used it on two of the sites below, garden.org and nationalgardenmonth.org, both of which get very high traffic. Additionally, I've used it on a client site for a Fortune 100 company. It's robust and tested. If you give it a whirl and have questions, feel free to email me directly. /shamelessSelfPromotion -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Can't even make a simple test RSS feed
* Brian Dunning [EMAIL PROTECTED]: What am I doing wrong? This doesn't work. The browser does not even load the page, no error or anything: ?php echo '?xml version=1.0?rss version=2.0channel'; echo 'item'; echo 'titlehdfghdf/title'; echo 'descriptiondfghdfh/description'; echo 'linkhttp://somelink/link'; echo '/item'; echo '/channel/rss'; ? You need to add the following before echoing anything: header('Content-type: text/xml'); -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Strange notation to create object
* Michael Stepanov [EMAIL PROTECTED]: Usually, I develop on Perl. But my current task pushes me to start use PHP. Generally, it's great but sometimes I'm a little bit confused. For example, recently I've found a strange notation of creation of PHP objects: $obj = new SomeObject(); Can anyone explain me meaning of **? is used to create references -- kind of like \ in perl. The above notation is unnecessary when developing in PHP5, as objects in PHP5 are passed by reference by default. However, in PHP4, this was often necessary if you needed to, for instance, store an object in an array or another object (otherwise you got a copy of the object, which means state would then differ between the original and the copy). -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Strange notation to create object
* Robert Cummings [EMAIL PROTECTED] : On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote: * Michael Stepanov [EMAIL PROTECTED] : Usually, I develop on Perl. But my current task pushes me to start use PHP. Generally, it's great but sometimes I'm a little bit confused. For example, recently I've found a strange notation of creation of PHP objects: $obj = new SomeObject(); Can anyone explain me meaning of **? is used to create references -- kind of like \ in perl. The above notation is unnecessary when developing in PHP5, as objects in PHP5 are passed by reference by default. However, in PHP4, this was Not entirely, there's still a subtle difference in PHP5 between assigning an object with = versus assigning with = . Would you mind explaining the difference? I've seen nothing in the docs, to indicate that assigning objects with = in PHP5 is necessary, or even desired. My experience with PHP5 hasn't shown this either. I'd be interested to know to what you refer. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Strange notation to create object
* Robert Cummings [EMAIL PROTECTED] : On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote: * Robert Cummings [EMAIL PROTECTED] : On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote: The above notation is unnecessary when developing in PHP5, as objects in PHP5 are passed by reference by default. However, in PHP4, this was Not entirely, there's still a subtle difference in PHP5 between assigning an object with = versus assigning with = . Would you mind explaining the difference? I've seen nothing in the docs, to indicate that assigning objects with = in PHP5 is necessary, or even desired. My experience with PHP5 hasn't shown this either. I'd be interested to know to what you refer. See for yourself when running the following script: ?php class a { } class b { } $aObj = new a(); $bObj = new b(); $foo1 = $aObj; $foo2 = $aObj; $foo3 = $foo1; $foo4 = $foo2; echo --\n; print_r( $foo1 ); print_r( $foo2 ); print_r( $foo3 ); print_r( $foo4 ); $foo1 = $bObj; $foo2 = $bObj; echo --\n; print_r( $foo1 ); print_r( $foo2 ); print_r( $foo3 ); print_r( $foo4 ); $foo1 = $aObj; ? This doesn't demonstrate what the OP was talking about, which is initial assignment of an object using a reference operator. The results of this make perfect sense to me -- the references are passed exactly as I would expect. Let me rephrase my question to you: is there a reason to do the initial object assignment using a reference operator using PHP5? I.e., is there a good reason to do this: $foo = new Foo(); instead of: $foo = new Foo(); I haven't seen any reason to do the former case using PHP5. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Strange notation to create object
* Robert Cummings [EMAIL PROTECTED] : On Thu, 2005-06-23 at 15:28, Matthew Weier O'Phinney wrote: * Robert Cummings [EMAIL PROTECTED] : On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote: * Robert Cummings [EMAIL PROTECTED] : On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote: The above notation is unnecessary when developing in PHP5, as objects in PHP5 are passed by reference by default. However, in PHP4, this was Not entirely, there's still a subtle difference in PHP5 between assigning an object with = versus assigning with = . Would you mind explaining the difference? I've seen nothing in the docs, to indicate that assigning objects with = in PHP5 is necessary, or even desired. My experience with PHP5 hasn't shown this either. I'd be interested to know to what you refer. See for yourself when running the following script: snip -- code sample This doesn't demonstrate what the OP was talking about, which is initial assignment of an object using a reference operator. The results of this make perfect sense to me -- the references are passed exactly as I would expect. Let me rephrase my question to you: is there a reason to do the initial object assignment using a reference operator using PHP5? I.e., is there a good reason to do this: $foo = new Foo(); instead of: $foo = new Foo(); I haven't seen any reason to do the former case using PHP5. Your original response said that the above notation was unneccessary, I took that to mean the operator for reference. Looking back I see ow that your comment was ambiguous, and I agree there is no need for the when assigning a new object. I was merely clarifying that references and normal assignment are not synonymous for objects in PHP 5. Okay -- good to see that we're on the same page. I was worried I'd missed something critical in the manual! References aren't easy to wrap your head around; I, for one, am very happy that I don't need to worry about them nearly as much with PHP5 (syntax is now, do what I mean). Interestingly enough, however, the PHP4 behaviour is actually much closer to perl's -- which should have made it easier for me (being a perl programmer), but somehow didn't. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Strange notation to create object
* Jason Barnett [EMAIL PROTECTED] : Matthew Weier O'Phinney wrote: ... This doesn't demonstrate what the OP was talking about, which is initial assignment of an object using a reference operator. The results of this make perfect sense to me -- the references are passed exactly as I would expect. But not exactly as I would expect! I thought that all objects were created as references, but apparently this is not the case. Here's what happens (in PHP5) with the statement '$obj = new Class();': * the 'new Class()' construct creates an object * it then returns a reference to the object * assignment is then to the reference Thus, $obj is actually a *pointer* to the object -- not the actual object. Is there some kind of dereferencing going on when you're using an object on the right side of the assignment (=) operator? No. It's simpler: you're simply passing around a reference to the object. Before, in PHP4, when you would use assignment, the variable on the left side would receive a *copy* of the object on the right -- a clone of the object. *UNLESS* what you had on the right side was a reference; then it would clone the reference, meaning you have the same behaviour as in PHP5. This is why the $obj = new Class() idiom occurred in PHP4; that way you could pass around your object safely, because you were simply passing around a reference to an object. PHP5 simplifies this by simply assigning the object reference only in the first place. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: security question...??
* david forums [EMAIL PROTECTED]: Why don't you try to get interactivity with ID machin which is unique, or with mac address. MAC address wouldn't work if the user is behind a proxy. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: security question...??
* Rory Browne [EMAIL PROTECTED] : On 6/21/05, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: * david forums [EMAIL PROTECTED] : Why don't you try to get interactivity with ID machin which is unique, or with mac address. MAC address wouldn't work if the user is behind a proxy. I think you mean IP addresses. MAC's won't work if the user is behind a router - which they generally are, unless you're on the same network - ie on an Intranet, and even then... Good catch -- I meant router, not proxy. Thanks! -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: security question...??
* bruce [EMAIL PROTECTED]: a number of you write apache/web/server apps that deal with secure information.. in doing some research it occured to me that a potential weak link is on the client side, regarding the browser? how many of you actually attempt to verify that the browser being used by the client is indeed a legitimate (non-hacked) browser?? or is there even a way to do this? or should i just go back to sleep..?? What's the point? The reason I ask is that (1) it shouldn't matter HOW the HTTP request is initiated. What *should* matter is that the page handles the request gracefully and returns something (HTTP headers only, or headers + page) as a result. The request is simply a TCP transmission, nothing more, nothing less. (2) What is done with the page once received by the client shouldn't be an issue, either. Browsers may render the page however they choose; HTML is meant to give hints as to how to perform layout, but in the end, it's just a huge string. Is there some specific issue you're thinking about? -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: security question...??
* bruce [EMAIL PROTECTED]: you miss what i'm saying, and what my point is. i as a server communicate with clients. under normal situations, the client is used to communicate back to the server. but what if someone created a 'client' that looked like IE, except this client was really sending the information entered by the user to who knows where... I can see what you're saying here. But I can already see some other issues that make this hard, if not impossible, to deal with: * Proxy server between client and server. If there's a proxy server between the client and server, it's possible the proxy server is munging the browser agent strings. If that's the case, we simply will not know for sure what the browser is -- or even necessarily what IP from which a request originates. * Many browsers allow the user to set the browser agent string. Look through your server logs some time -- you'll see some incredibly creative browser strings in there. This ability also allows one browser to spoof as another. For instance, I know in the past that Opera would allow you to select on the fly whether you wanted the browser agent to be reported as IE (to get IE-specific CSS files). * Who's going to keep the database of 'trusted' client browsers? You mention MS IE as one such... but I sure as hell wouldn't place it on *my* list. And, knowing how easy it is to spoof browser agent strings, I wouldn't place Firefox of Opera on there either... oops! there goes over 98% of my browser share! Limiting based on browser directly contradicts the purpose of the web. More on that below. snip this issue has nothing to do with HTTP protocols. Maybe I'm seeing this entirely differently than you, but I think it's *all* about HTTP protocols. Web applications are written on top of HTTP, and HTTP has a very fluid specification, because from the very beginning HTTP was designed to deliver HTML documents in an agnostic way -- so that they may be read from text-based browsers, graphical browsers, browsers on TVs, etc. The fundamental building block, then is HTTP, which is a series of stateless transactions. The servers and clients speak across this protocol, and in between transactions have no inkling of the others' existence. Furthermore, an HTTP server should not care what makes the request, so long as it is well formed; if it is well formed, it returns a string (a document). That's all it's supposed to do. You mention above except this client was really sending the information entered by the user to who knows where. If they're not getting to my site, or the request is getting redirected elsewhere, I can't do anything about the situation; my server knows nothing about it. If they are, there are a number of ways to maintain some awareness of particular users between requests; sessions and cookies come to mind. It's very easy to create server-side tags in sessions to prevent session hijacking very much like you describe (using things like dates, browser agent strings (looking for consistency between requests), etc.). hope this provides more clarification as to what i'm dealing with, and why it should be important to people who write secure apps/sites/systems. if you only focus on the server, you can't really say your service is really secure... On the whole, I'm less worried about hijacked client browsers than I am about zombie networks making repeated requests to my systems (DDOS on port 80). I can use the tools of HTTP and PHP to track users across requests. I personally think these are plenty powerful -- and help me provide a service that can be agnostic of the device using it. I understand your concerns, but they come more from a world where environments can be strictly controlled, and the web ain't one of them. -Original Message- From: Matthew Weier O'Phinney [mailto:[EMAIL PROTECTED] Sent: Monday, June 20, 2005 1:23 PM To: php-general@lists.php.net Subject: [PHP] Re: security question...?? * bruce [EMAIL PROTECTED]: a number of you write apache/web/server apps that deal with secure information.. in doing some research it occured to me that a potential weak link is on the client side, regarding the browser? how many of you actually attempt to verify that the browser being used by the client is indeed a legitimate (non-hacked) browser?? or is there even a way to do this? or should i just go back to sleep..?? What's the point? The reason I ask is that (1) it shouldn't matter HOW the HTTP request is initiated. What *should* matter is that the page handles the request gracefully and returns something (HTTP headers only, or headers + page) as a result. The request is simply a TCP transmission, nothing more, nothing less. (2) What is done with the page once received by the client shouldn't be an issue, either. Browsers may render the page however they choose; HTML is meant to give hints as to how to perform layout, but in the end, it's just a huge string
Re: [PHP] Re: security question...??
* bruce [EMAIL PROTECTED]: if you're going to be writing apps that deal with sensitive information, you better damm well give some thought as to how secure the client is, That's what encryption using public/private keypairs is for. The client encrypts the data with the public key, and the only way to decrypt it is using the private key -- which the server has. That way the server doesn't *need* to know what the client is, so long as the request is made over HTTP and the server is able to decrypt the data sent. or even if the client is actually valid! Here's a valid client: open up a command line and type # telnet php.net 80 My point? Anything that can communicate over TCP and talk using HTTP commands is a valid client. That's the way the web was designed, and that's the way it works. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP autogenerating Website Templates
* John Nichel [EMAIL PROTECTED] : [EMAIL PROTECTED] wrote: Maybe off topic: I would not agree totally with that link because this really doesn't make a sense: snip snip I am new in PHP and got so many times RTFM answers and didn't find them helpful at all. From 'skilled' friends, if they were there at the moment, I'll get an answer immediately. Here, sometimes I'm scared to ask because of RTFM Why be scared? Good thing this isn't Usenet. ;) Speak for yourself... I read via news.php.net... ;-) -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Problems with header()
* Martn Marqus martin@bugs.unl.edu.ar: I have to send a PDF file after a submit on a form. The PDF is well created, and I'm sending it to the client with this: $fpdfName = /tmp/ . session_id() . .pdf; // Vamos a mandar el PDF header('Content-type: application/pdf'); // El archivo se va a llamar libreDeuda.pdf header('Content-Disposition: attachment; filename=libreDeuda' . '.pdf'); // El PDF fuente va a ser $ftexName. readfile($fpdfName); The problem is that the PDF file that is sent is corrupted for acroread (xpdf reads it like a charme), because, after the end of file (%%EOF) of PDF there is an HTML page add to the file. Likely what's happening is that there's extra output happening after your readfile() call. Do an 'exit();' call right after it, and make sure there's no whitespace after your closing PHP tag (or simply don't include a closing PHP tag). -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: form inside an email
* Ross [EMAIL PROTECTED]: I would like to send a form to customers to get some information. The form will be a HTML email and collect a few bits of data...name. age etc. Can I put this inside an html email so customers do not have to open an external webpage to fill in the fields. How can this then be processed? Why don't you want the customer to open an external web page? what happens if said customer does not read mail as HTML -- or if security settings in their MTA don't allow submitting forms? or submitting a form in the MTA cannot spawn a browser? (For instance, I use a text-only MTA -- so I won't see the form, and won't be able to submit it. Blind people often use text-based MTAs along with a text-to-speech application.) I understand the idea behind such things, but if you must do it, give a text alternative to the HTML version that can link to an external page with the form. If this can be done in php then great. If not any other suggestions are welcome. The form handler can be done in any language you want... so, of course, use PHP! -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: split()?
* [EMAIL PROTECTED] [EMAIL PROTECTED]: How would I do this ? Take this string and return everything between [ ] as an array output doesnt have to inlude [ ] $rr=thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd; $a = some function echo 'pre'; print_r($a); [0] = [ OUT1 ] [1] = [ OUT2 ] [2] = [ OUT3 ] preg_match_all('/\[(.*?)\]/', $rr, $a); This will throw all the matches into $a. $a[0] will be an array that includes the full string matched for each (which will include the braces); $a[1] will be an array with just the portions captured (no braces): Array ( [0] = Array ( [0] = [ OUT1 ] [1] = [ OUT2 ] [2] = [ OUT3 ] ) [1] = Array ( [0] = OUT1 [1] = OUT2 [2] = OUT3 ) ) -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Retrievable weather service info?
* Murray @ PlanetThoughtful [EMAIL PROTECTED]: Just wondering if anyone knows of a free weather service that can be interrogated by PHP for information such as current temperature for a range of cities around the world? www.wunderground.com has free banner 'stickers' you can use (i.e., graphics). They don't have an API for grabbing the information, but the schema they use is very easy to determine just by grabbing a few stickers here and there. Been a while since I messed with it, and the best detail I can give you is that the stickers included a common path, followed by COUNTRYCODE/STATE_PROVINCE_CODE/City_Name.gif, and that when you choose what type of sticker you want, that determines the path and the image size. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split()?
* Mark Cain [EMAIL PROTECTED] : Here is one way to do it: $rr=thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd; preg_match(/.*\[(.*)\].*\[(.*)\].*\[(.*)\].*/, $rr, $match); list($whole_match[],$a[],$a[],$a[]) = $match; This is fine as long as there's precisely three escape sequences in the string; if there's an arbitrary number, that won't work. I've posted another solution already using preg_match_all() that will. - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, June 14, 2005 8:13 PM Subject: [PHP] split()? How would I do this ? Take this string and return everything between [ ] as an array output doesnt have to inlude [ ] $rr=thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd; $a = some function echo 'pre '; print_r($a); [0] = [ OUT1 ] [1] = [ OUT2 ] [2] = [ OUT3 ] -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: include()
* I. Gray [EMAIL PROTECTED]: Is there a big difference between me including a file by putting the url in the include() such as include(http://www.examplesite.com/examplefile.php) and putting the server path such as include(number/www.examplesite.com/public_html/examplefile.php) ? I want to get into good habits you see. I assume I have to use the first example when the file is on a different server. From a security standpoint, you usually only want to include and/or require files that are on your local system (your second example), unless under unusual circumstances (content sharing agreements with other sites, etc). Ideally, unless you want access to those scripts directly (i.e., http://www.examplesite.com/examplefile.php), you should place them somewhere in your include_path, which should be _outside_ the web server's document root. This prevents idle hacking attempts, and is generally considered a best practice. Additionally, using a network stream (which is what you're using when you specify 'http://') means that you've got additional performance overhead. Network streams are often more costly, resource wise, than file streams, and if the file truly is on a remote network, you then have to wait for that transaction to finish before continuing with your own processing. If you need to pull content off another server, but that content does not change often, you would be wise to have a background process running that pulls this content and caches it for use in your scripts. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Documenting Code Question
* Chris Drozdowski [EMAIL PROTECTED]: I need some help regarding documenting code. Say you have a function/method that takes an object as a parameter and/or returns an object. When documenting, do you specify the specific class of the object when listing the datatype in the docblock @param and @return specs or do you simply specify object? You should mention that this has to do with PhpDocumentor... :-) The documentation for PhpDoc says that you can specify either 'object' or the classname of the object's type that is expected. If the class is in your documentation tree, then it will even link to that class' documentation; if not, it shows it statically. I tend to go with the class name, as it gives more information to the individual reading the documentation. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: tidy question
* Thomas [EMAIL PROTECTED]: I was wondering if it is possible to let tidy repair and format only parts of your html without putting the head and doctype stuff in. I.e. only the content of the page between the body tags. The reason for that is twofold: 1. I want to cache that repaired string so I don't have to call that repair function on every page call, 2. I am using xhtml1.1 as DOCTYPE and tidy only gives me the 1.0 transitional version. tidy_repair_string() OR tidy_parse_string() + tidy_clean_repair() -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: output buffering / output compression
* Paul Birnstihl [EMAIL PROTECTED]: I have recently set up a machine with PHP with both buffering and compression turned on. Some of the pages being served include up to 3MB of HTML. Can someone explain the benefit(s) of setting these ini directives to values (ie. larger than 4kb) rather than On ? I've played around with it as I thought it might speed things up by using a bigger buffer etc. but the only difference I noticed is a big jump in memory usage. The reason to set to a value is to set the buffer size -- and usually you do this to tune interaction between PHP and Apache and/or the underlying OS. You want to set it to a value that matches Apache's buffer size and/or the OS's network buffer size. If you don't know these, using the defaults is probably the best bet. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Objects and Performance
* Greg Donald [EMAIL PROTECTED] : On 6/8/05, Greg Beaver [EMAIL PROTECTED] wrote: If you want to compare object methods versus functions, you should compare identical code inside a method to code inside a function. Greg's benchmarks compare two different ideological code structures. Quite honestly, the wrapping of mt_srand() inside a function or method does not satisfy the definition of good coding, object-oriented or otherwise. Functions/methods should be used to abstract common operations. mt_srand() already does this necessary abstraction, and putting a further wrapper around it makes no sense. I called mt_srand() inside the constructor, so it's only called once, same as the procedural version. This being an example of a class, it seems like the logical place to put it. I can remove it from both versions but it's not gonna change much as far as speed. If your code does simple operations on a few operands and returns a value, like our mt_srand() function, there is absolutely no point in making it more complicated. I agree. In the real world a given task will likely be more complicated, but that's not the point here. Actually, that is the point. What Chris was getting at is that usually you have a bit more going on in a function or method -- several operations, not just a wrapper for a single operation -- that the function/method call serves to abstract. So, calling a method that simply calls and returns a single php internal function call isn't going to give a good comparison; we already know that calling the function is faster. However, you could consider wrapping the functions inside a class and using them as static methods. There is little point in making classes to then only use the methods statically. You could just put all your similar functions in an include file and be done with it. Nothing more annoying than working on someone else's OO code and seeing Foo::bar() all over the place. Pointless. Unless you have several function libraries that were developed separately and *do* have the same function names. Where I work, for instance, at one point we had three function libraries, developed separately, that each had their own 'send' function, which worked fine until we tried to develop an application that mixed some functionality from the different libraries. Granted, we could have refactored and split out the common functionality from the libraries into a separate library, but we found it was much easier to wrap everything into classes and uses the class structure as a namespace. (We've since completely refactored and gone all OOP, but that's neither here nor there.) This would essentially give them a namespace that would allow any conflicts with other programmer's function names to be more easily resolved. If PHP needs namespaces then add them, last I heard the consensus was that it didn't. I've never needed them personally. It doesn't seem like enough justification to use objects just because you don't want to rename a few functions in the rare event you actually have a conflict. Seriously, how many times have you been working on a PHP project that was so big, with so many developers, that you bumped into each other with function names? Has yet to happen to me. That's *your* experience. You're going to keep seeing namespace discussions pop up whenever other people have experiences that indicate namespaces would help solve the issue. You're also going to have the issue pop up whenever you have developers from other languages start using PHP. I come from a perl background; I'd *love* to have namespaces in PHP... but I can use classes to emulate them fairly well. snip make the code readable and maintainable and it will cut down on bugs and work better than faster code. I always value efficient code over time to code. Doing more with less hardware should always be a programmer's first goal in my opinion. The overhead involved in bringing a web-based object into existence for the extremely short period of time it will live can never justify the 'maintainability' and 'readability' arguments I'm always hearing preached. I've never seen any OO PHP code that was easier to read or maintain for that matter. Again, your experience. I *have* seen OOP PHP that was easier to read and maintain. I've seen (and written) some perfectly horrendous procedural code that was a nightmare to read and maintain. You're right -- you should try to write efficient code. But sometimes you have to look at programmer efficiency as well -- if you're working for a client under a deadline, you don't always have that luxury. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP
Re: [PHP] Really simple regex
* Rory Browne [EMAIL PROTECTED] : preg_replace(/x+/, x, $string); should do it. Having that said, regex generally comes back and bites me in the ass, so... That one won't -- that's spot on. On 6/8/05, Dotan Cohen [EMAIL PROTECTED] wrote: Now, I know that this is easy, but I am embarassed to say that I can't find a regex tutorial that will show me how to match any occurances of x and replace them with one x: x x xx x x x $string=I have apples!; $string=preg_replace(-regex here-,x, $string); print $string; I have x apples! I searched marc because I know that I've seen this, but I don't know on what keywords to search. I know that php uses perl-compatable regular expressions, but in no tutorial did I find this. I know that * matches any amount of occurances of a string, but formulating it to do it in the middle of a string of text I could not get. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] linux php editor
* [EMAIL PROTECTED] [EMAIL PROTECTED] : On windows platform I use HomeSite 5.5 and I'm more then happy. On Linux platform QuantaPlus For small and fast changes on file vi/vim is the best. You know that vim exists for windows, right? and that it can be used for large changes as well? (I use vim as my primary editor :-) On 6/6/05, Clive Zagno [EMAIL PROTECTED] wrote: what php GUI editors do you recommend. any other recommendations, thanks -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Explanation in Shiflett's PHP Security Briefing
likely been tainted. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to execute local applications on the client
* Mauricio Pellegrini [EMAIL PROTECTED]: Some one has asked me to set a web page from within wich users could launch local applications. Those applications are allready installed in the client PC. The link on the web page would act as a simple link to start the application. system() -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Unit testing ?
* mbneto [EMAIL PROTECTED] : Thanks for the reply. Your email confirmed what I've read/thought about the tests. I'll look this SimpleTest even tough PHPUnit2 seems to do the job fine. Use the unit testing framework with which you are most comfortable; the ideas remain the same, just the details differ. If you have more info (like books, urls, examples) please send me. Unfortunately, no. Most of this is personal experience, a little of it was garnered from php|Tropics, and that portion wasn't an official part of Jason Sweat's presentation. On 6/2/05, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: * mbneto [EMAIL PROTECTED] : I am trying the phpunit2 for unit testing but the examples found in the documentation are few and do not address, for example, tests when database access is involved. Perhaps this belongs to a more general question (i.e strategies for unit testing) so any urls, docs would be great. Jason Sweat covered this at php|Tropics, using SimpleTest as the unit testing framework. I use phpt unit tests (developed for testing php itself, and used by the PEAR project for regression tests). The principles are the same regardless of framework, however. The fundamental problem is: your code may depend on the results of a DB operation -- it's primary purpose may even be to perform a DB operation. While you can test the code, you still need to test whether or not your code can successfully perform the DB operation as well. A common problem I find is that I'm building SQL on the fly -- and that process may build shoddy SQL. It may be building exactly what I designed it to do, but the RDBMS will never be able to actually utilize the SQL I build. Tests can help catch these issues. snip -- full explanation -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How to execute local applications on the client
* John Nichel [EMAIL PROTECTED] : Matthew Weier O'Phinney wrote: * Mauricio Pellegrini [EMAIL PROTECTED] : Some one has asked me to set a web page from within wich users could launch local applications. Those applications are allready installed in the client PC. The link on the web page would act as a simple link to start the application. system() No, that won't work. system() will execute a command on the server, not the client. Absolutely correct. Mea culpa. I use PHP on my machine all the time for running scripts, and so the line between server and workstation is often blurred. Even then, I probably wouldn't want system() launching a desktop application, even if I called sudo first to switch to the appropriate user. Thanks for catching this! -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP bug within multi. dimensional arrays?
* Merlin [EMAIL PROTECTED]: Hi there, I am outputting an multidim. array. That works fine, except one thing. The first letter of the value inside dimension 1 always gets printed. For example: I fill the arrays: while ($row = mysql_fetch_object($result)){ $cat[$row-main_id][name] = $row-main_name; $cat[$row-main_id][$row-sub_id][name] = $row-sub_name; } First off, if you're creating associative arrays, you should quote the keys: $cat[$row-main_id]['name'] = $row-main_name; If you don't do so, PHP assumes you're using a constant value for the key name. Then I output them: foreach ($cat AS $maincat){ echo $maincat[name].':'; Quote your keys! foreach($maincat AS $subcat){ You do realize that the above will also loop over the index 'name', right?... echo $subcat[name].$br; and since it does, the first element in that array is 'name', which isn't an array, but a string. Since the 'name' constant isn't defined, it will interpret that as 'true', or 1, and so it takes the first character of that string. } echo $br; } Which does result in: Europe:E Germany UK North America:N US CA As you can see I get the extra letters N and E. Is this an php error or did I do something wrong? So, what you should probably do is create an additional layer in your multi-dimensional array for the subcategories, and have it of the form sub_id = sub_name: $cat[$row-main_id]['subs'][$row-sub_id] = $row-sub_name; Then loop over that: foreach ($cat as $main_cat) { echo $maincat['name'] . :\n; foreach ($maincat['subs'] as $sub_id = $sub_name) { echo $sub_name$br; // could also use $sub_id here if // desired } } -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: headers and session
* Alessandro Rosa [EMAIL PROTECTED]: Hi to all, I got a problem while storing session variables. ?php session_start(); header( Cache-control: private ); require_once(config.inc.php); $_SESSION['session_psw'] = $_POST['txtPassword']; $_SESSION['session_user'] = $_POST['txtIdUtente']; $PHPcmd = $GLOBALS['gestionale_path_name'].test/2.php ; header( Location: .$PHPcmd ); ? After the call to header(...), the values of session variables are lost. Does config.inc.php have any whitespace following the closing ? tag, or does it output any HTML? That could be your culprit. What happens if you do your $_SESSION setting *before* the require, but directly after the initial header() call? -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP bug within multi. dimensional arrays?
* Merlin [EMAIL PROTECTED] : Matthew Weier O'Phinney wrote: * Merlin [EMAIL PROTECTED] : I am outputting an multidim. array. That works fine, except one thing. The first letter of the value inside dimension 1 always gets printed. For example: I fill the arrays: while ($row = mysql_fetch_object($result)){ $cat[$row- main_id][name] = $row- main_name; $cat[$row- main_id][$row- sub_id][name] = $row- sub_name; } First off, if you're creating associative arrays, you should quote the keys: $cat[$row- main_id]['name'] = $row- main_name; If you don't do so, PHP assumes you're using a constant value for the key name. Then I output them: foreach ($cat AS $maincat){ echo $maincat[name].':'; Quote your keys! foreach($maincat AS $subcat){ You do realize that the above will also loop over the index 'name', right?... echo $subcat[name].$br; and since it does, the first element in that array is 'name', which isn't an array, but a string. Since the 'name' constant isn't defined, it will interpret that as 'true', or 1, and so it takes the first character of that string. } echo $br; } Which does result in: Europe:E Germany UK North America:N US CA As you can see I get the extra letters N and E. Is this an php error or did I do something wrong? So, what you should probably do is create an additional layer in your multi-dimensional array for the subcategories, and have it of the form sub_id = sub_name: $cat[$row- main_id]['subs'][$row- sub_id] = $row- sub_name; Then loop over that: foreach ($cat as $main_cat) { echo $maincat['name'] . :\n; foreach ($maincat['subs'] as $sub_id = $sub_name) { echo $sub_name$br; // could also use $sub_id here if // desired } } This is very helpful and does work. However I did not understand it completley. What if I want to add another value, for example name2 or name3. It looks like this example is limited to id and name. Could I just add: $cat[$row- main_id]['subs'][$row- sub_id] = $row- name2; Guess not. Can you tell me how to add other fields to the array? You should probably do some studying up on multidimensional and/or nested arrays so you can get a better handle on this stuff. If you need to be able to add multiple names for a sub_id, do it as an array: $cat[$row-main_id]['subs'][$row-sub_id][] = $row-name1; $cat[$row-main_id]['subs'][$row-sub_id][] = $row-name2; $cat[$row-main_id]['subs'][$row-sub_id][] = $row-name3; However, this will break your loop above -- you'll need another layer of looping added in: foreach ($cat as $main_cat) { echo $maincat['name'] . :\n; foreach ($maincat['subs'] as $sub_id = $names) { foreach ($names as $name) { echo $name$br; // could also use $sub_id here if // desired } } } Hope that helps. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: headers and session (question)
* Alessandro Rosa [EMAIL PROTECTED]: Here's below the solution (the encryption will be shortly performed into login.php). 1 ?php 2 session_start(); 3 $_SESSION['session_user'] = $_POST['txtIdUtente']; 4 $_SESSION['session_password'] = $_POST['txtPassword']; 5 $PHPcmd = login.php ; 6 header( Location: .$PHPcmd ); 7 ? But a QUESTION now : if line 5 is replaced by these two lines, say here 5a and 5b: 5a require_once(config.inc.php); 5b $PHPcmd = $GLOBALS['gestionale_path_name'].phpcode/login/login.php ; this does not work (meaning user and psw are not passed to login.php); but again the below code works again: 5a require_once(config.inc.php); 5b $PHPcmd = $gestionale_path_name.phpcode/login/login.php ; Again, look at your config.inc.php and make sure it's not sending any output. If you have even a blank line before an opening ?php tag or a blank line following, output will have been sent, and you will not be able to send a cookie or additional HTTP headers. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: What is faster?
* Andy Pieters [EMAIL PROTECTED]: Of these two expressions, which one is faster? if(!(is_null($customMenu)) (is_array($customMenu))) $menu=$customMenu; else $menu=array('Documentation','Settings'); OR $menu=(!(is_null($customMenu)) (is_array($customMenu))?$customMenu:$menu); Anybody have any documentation on this? Try benchmarking it. Use microtime(), and do each in a for loop that iterates 1000 times or so. $timestart = microtime(true); for ($i = 0; $i 1000; $i++) { if (!is_null($customMenu) is_array($customMenu)) { $menu = $customMenu; } else { $menu = array('Documentation', 'Settings'); } } $timeend = microtime(true); $timestart2 = microtime(true); for ($i = 0; $i 1000; $i++) { $menu = (!is_null($customMenu) is_array($customMenu)) ? $customMenu : array('Documentation', 'Settings'); } $timeend2 = microtime(true); $time1 = $timeend - $timestart; $time2 = $timeend2 - $timestart2; echo if-else took $time1 seconds\n; echo ternary took $time2 seconds\n; (Note: the above works in PHP5; you need to do some additional contortions in PHP4 to get similar functionality with microtime.) From my own benchmarks, it looks like the if-else is slightly faster. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: stripping html tags
* Dotan Cohen [EMAIL PROTECTED]: I took this example from php.net, but can't figure out where I went wrong. Why does this: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); throw this error: syntax error at line 265, column 39: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); ==^ It seems to be pointing to the 'e' is 'head'. Why? Thanks. Why are you using regexes instead of strip_tags()? -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Check class definition
* Chris Boget [EMAIL PROTECTED]: You can use defined() to check to see if a constant has been defined. You can use function_exists() to see if a function has been defined. But what can you use to check to see if a class has been defined? class_exists() -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Unit testing ?
* mbneto [EMAIL PROTECTED]: I am trying the phpunit2 for unit testing but the examples found in the documentation are few and do not address, for example, tests when database access is involved. Perhaps this belongs to a more general question (i.e strategies for unit testing) so any urls, docs would be great. Jason Sweat covered this at php|Tropics, using SimpleTest as the unit testing framework. I use phpt unit tests (developed for testing php itself, and used by the PEAR project for regression tests). The principles are the same regardless of framework, however. The fundamental problem is: your code may depend on the results of a DB operation -- it's primary purpose may even be to perform a DB operation. While you can test the code, you still need to test whether or not your code can successfully perform the DB operation as well. A common problem I find is that I'm building SQL on the fly -- and that process may build shoddy SQL. It may be building exactly what I designed it to do, but the RDBMS will never be able to actually utilize the SQL I build. Tests can help catch these issues. Basically, when testing code that interacts with a database, you've got two basic strategies: (1) test against the DB, or (2) use mock objects. The latter is a tricky subject, as it assumes you're using a DB abstraction layer, and because you then have to mimic how that abstraction layer works. Basically, you end up doing a lot of code simply to test. Which brings us back to (1), test against the DB. The way to do this is to have some code that sets up and tears down a TEST database -- not the one with your live data. It should likely create and populate any tables you need, and then be able to tear them down again. The reason behind this is that you can then have a set of consistent data to test against -- once you run tests, chances are likely that you've altered the data. Each test you run should tear down the DB and then recreate and/or repopulate it. If you use the phpt unit tests, the place to do this is in your setup.php.inc file. I then create a file with the raw SQL for setting up and populating a test table, slurp it in with file_get_contents, and pass it on to the DB from within a function in that setup file. Then another function can truncate or delete all records from the tables utilized. The code within the test might then look like this: ?php include_once dirname(__FILE__) . '/setup.php.inc'; setupDb(); // do a test teardownDb(); setupDb(); // do another test teardownDb(); ? That's kind of a long-winded answer to your question, but it's not something you see a lot of information on. I hope that it helps. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Best way to use other objects within classes?
* Murray @ PlanetThoughtful [EMAIL PROTECTED]: snip (Note: my development environment is PHP 5.0.3, but the production environment is 4.3.10. This is my first project built with 5.x local and 4.1.x remote, so if anyone with more experience spots any fatal flaws where I'm using 5.x specific methods etc, I'd appreciate knowing about them) snip ? $db = connectMDB2(); // function that returns instantiated MDB2 object $comments = new displayComments(); // class that performs displaying of comments $comments-set_db($db); // passing the MDB2 object to the class $comments-doSomethingElse(); ? The displayComments() class might then look something like: class displayComments{ private $db; public function set_db($db){ $this-db = $db; } The above is the nut you need, and you're doing it right. As Greg pointed out, you'll need to change that from 'private $db' to 'var $db' as PHP4 doesn't have member visibility. However, you're correctly passing by reference -- something required by PHP4 if you want to share the same object amongst several classes. (In PHP5, objects are passed by reference by default, and the above code will actually generate some notices -- but since you're developing for PHP4, you can safely ignore them). -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 5 Question about OO
* janbro [EMAIL PROTECTED] : Okay, I see there is a workaround but nothing realy satisfying, but I'm not hoing to complain, I'm hapy to have oo in PHP at all. I never worked with __autoload so far, but I will give it a try and check it out The best way to use autoload is with the auto_prepend_file configuration directive. By adding the __autoload() function to a file that is automatically prepended, you don't even have to think about it in your scripts. This kind of flexibility is nice -- you can have different prepend files for different sites or different areas of the same site -- so that you only have the funcationality accessible that you need right there. You can also define your own naming schema -- which, admittedly is a dubious advantage, but an advantage nonetheless. Marcus Bointon schrieb: On 1 Jun 2005, at 09:01, janbro wrote: require (Class2.php); class Class1{ private function ... { $refClass2 = new Class2; } } Now my question, is it possible to skip that require/ include part? In Java you don't need that, as class and file names are identical. PHP doesn't have this luxury - people can call files whatever they like. However, PHP5 does have a nice feature to deal with this. In your class1 class, create a function called __autoload like this: function __autoload($class_name) { require_once $class_name . '.php'; } In this case when you ask for a new class2 and you've not required it before, it will automatically call __autoload with $class_name set to 'Class2', which then requires the class file according to the pattern used in the function, in this case 'Class2.php'. Note that while PHP is not case sensitive to class names, the file system you're on probably is, so keep your case consistent throughout. Docs are here: http://www.php.net/manual/en/language.oop5.autoload.php -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Looking for a developer's weblog/cms system?
* Philip Hallstrom [EMAIL PROTECTED]: Over the years I've collected and done some things (tips, howtow, code snippets, etc.) that I think might be useful to others. Heck, I'd like to have them nicely organized too as now they are spread across machines, in email, etc. I'm thinking it might be nice to have an easy to use web-based cms system that I could post this sort of stuff too and assign it to a category and then let google index it. My problem is that there are hundreds of apps that do this. And a lot of them don't do what I need. A lot of them seem geared toward diary type applications, I want more of a this is my stuff which you might find useful. I can think of a couple of things: * A wiki. This would likely require some reformatting on your part, but even that could probably be scripted. The nice thing about a wiki is that you can either have it wide open so others may comment and contribute, or you can lock it down so only you or others you appoint may contribute. Additionally, each page gets its own URL, and most wikis worth their salt have search functionality. * A blog. Many blog packages allow you to add code snippets and will even hilight them for you; you usually also get search functionality and the possiblity of static URLs for content. Mostly I want something that has a decent look so I dont' have to think about that part. So, I'm asking you all for any recommendations you might have so I don't have to try dozens of these things out. I figure some of you must be doing the same thing and I'm hoping I can leverage your experience :-) I've used a variety of wikis; you just have to choose one and run with it. I'm not familiar with many blog packages, but do use Serendipity (http://www.s9y.org), and have played a little with Jaws (http://www.jaws-project.com/index.php); they have some nice features and are relatively easy to set up. Basically, I want a way to post things I think others might find useful. I'm not interested in user comments. I don't care about RSS. I would like to easily be able to mark things as code or type this at a shell prompt as well as link to entire source files, etc. If you'r interested in posting things I think others might find useful, why are you not interested in RSS? How will *others* know when you've posted something new? I find that RSS is a great tool for me to keep track of developers, projects, and other sundries. I rarely use my bookmarks anymore. Anyways -- the blog packages I've indicated above all utilize RSS, and may wikis do as well, so if you use one of the above solutions, you'll likely get that 'for free'. If all else fails... you're a PHP developer -- code your own! -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Excellent language PHP5 is!
* Robert Meyer [EMAIL PROTECTED]: There is one thing I hope is implemented in PHP soon. That is the ability to pass by reference and receive the reference in variable parameter lists. You can pass by reference to a function taking a variable number of parameters, but func_get_arg() only returns the value and therefore, any changes to that variable do not change the variable as seen by the caller. Maybe a func_get_refarg() could be implemented. Indeed, there's a comment on the func_get_arg() manual page to this very effect. One possibility is to wrap the reference into an array: // in functioncall(): function functioncall() { $args = func_get_arg(0); $arg = $args[0]; // retrieving reference from array $arg++; } $arg = 1; functioncall(array($arg)); // passing an array with a ref echo $arg; I tested this, and it works. Requires a bit more work in the function, but a little architecting could get it working. Another possiblity is to pass associative arrays to your functions; then, in your function, check for the existence of keys you need. The beauty of this approach is that you don't have to muck about with the func_get_arg() calls, you still get a variable number of arguments, and you can easily pass references. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php