Re: [PHP] Question about a security function
On 20 May 2010 16:51, Al n...@ridersite.org wrote: I'm not being clear. First pass is thru the blacklist, which effectually tells hacker to not bother and totally deletes the entry. If the raw entry gets past the blacklist, it must then only contain my whitelist tags. e.g., the two examples you cited were caught by the whitelist parser. Ah, gotcha. That seems like a much better approach to me. But if the whitelist's going to stop the submission, then why bother with a blacklist at all? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about a security function
On 21 May 2010 14:21, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I still think you might be better off using BBCode, which is used on websites just for this very purpose. When any input comes back, you can remove all the HTML completely and replace the BBCode tags that you allow. This should guarantee that the only HTML in the text is what you put there. That way, the only chance someone has to enter malicious code is to manipulate your replacement algorithm. We don't know what the use case is. It's likely that HTML is a fixed requirement here. In any case, stripping the HTML from a post and leaving just the BBCode is almost as difficult as stripping out all tags except p. There are so many text encodings and weird quirks out there that I wouldn't trust any code I'd written myself to do it. HTMLPurifier is widely adopted and tested, and actively maintained. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about a security function
On 20 May 2010 13:53, Al n...@ridersite.org wrote: I have a password-protected, user, on-line editor that I'm hardening against hackers just in case a user's pw is stolen or local PC is infected. The user can enter html tags; but, I restrict the acceptable tags to benign ones. e.g., p, b, table, etc. e.g., no embed... script... etc. Just to be extra safe, I've added a function that parses for executables in the raw, entered text. If found, I post and nasty error message and ignore the entry altogether. That's not really going to work. See: http://ha.ckers.org/xss.html Blacklisting is a fundamentally flawed approach. I suggest using http://htmlpurifier.org/ instead. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about a security function
On 20 May 2010 15:52, Al n...@ridersite.org wrote: I agree blacklisting is a flawed approach in general. My approach is to strictly confine entry text to a whitelist of benign, acceptable tags. The But that's not what you've done. You've blacklisted the following patterns: \script\x20, \embed\x20, \object\x20, 'language=javascript', 'type=text/javascript', 'language=vbscript\', 'type=text/vbscript', 'language=vbscript', 'type=text/tcl', error_reporting\(0\),//Most hacks I've seen make certain they turn of error reporting \?php,//Here for the heck of it. and allowed everything else. A couple of examples: You haven't blacklisted iframe IMG SRC=javascript:alert('XSS'); would sail straight through that list. I can't tell from that list alone, but are your checks case-insensitive? Because ScRipT would pass through a case-sensitive check. We can go on like this all day, and at the end of it you still won't be sure you've blacklisted everything. The first answer at http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags is related, also. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] In need of CVS/SVN checkout script for Production servers [solved]
On 6 May 2010 04:14, Adam Richardson simples...@gmail.com wrote: Daevid asked the list for a an app that facilitated SVN/CVS, and when nobody provided options, he crafted a solution of his own and then offered it back to the list. Er... I suggested Phing. Phing/Ant/Gradle/Maven/Capistrano... a build tool is the standard solution here, and there are about a million of them (http://en.wikipedia.org/wiki/List_of_build_automation_software). I can't believe people are seriously discussing rolling your own when all those mature tools are sitting right there. Did my post not get through or something? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting floats to ints with intval
On 6 May 2010 11:52, Paul Waring p...@xk7.net wrote: If I was designing the system from scratch, that's what I'd do. Unfortunately this is an add-on to a legacy system where currency values are already stored as strings in the database (yes, not ideal I know, but you have to work with what you've got). I don't know much about your situation, but it does sound like you need to fix the root problem. I'd use a decimal type, and lean on the database to do the maths. http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html You many also find money_format() useful: http://php.net/manual/en/function.money-format.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Little php code - error
On 8 April 2010 15:21, Juan j...@rodriguezmonti.com.ar wrote: The structure is pretty easy to understand, however I'm not able to solve this. Could you tell me why I'm not able to run this code. Your else has a condition on it } else (empty($b) and empty($c)) { Should be } else { BTW, the and is fine. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to redefine a function if it doesn't exist?
On 30 March 2010 14:16, Andre Polykanine an...@oire.org wrote: I need a quoted_printable_encode function but it's available only since PHP 5.3. How do I redefine that function only if PHP version is lower than 5.3? function_exists(). if (!function_exists('myfunc')) { function myfunc() { ; } } http://uk3.php.net/function_exists -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Memory investigation
On 3 March 2010 15:49, la...@garfieldtech.com la...@garfieldtech.com wrote: Yep, I'm familiar with XDebug and KCacheGrind. As you say, though, it doens't (as far as I am aware) offer the particular data that I'm after. We've already got cachegrind gurus working on the code who know how to use it better than I do. :-) What I'm looking for is see this big cache object we've been building up in memory for this whole page request? Now that we're done with the page, how big is it, really? You could try Memtrack (http://pecl.php.net/package/memtrack) but I can't comment as to what state it's in. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to write specification
2010/1/8 Dušan Novaković ndu...@gmail.com: I've been programing for some time, but I never tried to write code for two different application in same way. How when I work with more programmers it's even worse. Everyone is forcing it's way of writing functions inside classes or writing variables, etc. My idea is to code according to the standard protocol so that in future it would be easier to make applications. Is there some specification (or standard) how to write code for web application, but which describes all possibilities(writing css, JS, php, etc.)? Specification and coding standard are two different things... I think you're looking for a coding standard. Some helpful links: http://framework.zend.com/manual/en/coding-standard.html http://pear.php.net/manual/en/standards.php http://drupal.org/coding-standards http://www.dagbladet.no/development/phpcodingstandard/ [last updated 2003 - obsolete?] Pick one (at random if necessary) and don't make any changes. Changes imply discussion, and discussion is a waste of time. You can enforce a coding standard, should you so wish, at repository level: http://pear.php.net/manual/en/package.php.php-codesniffer.intro.php http://svnbook.red-bean.com/nightly/en/svn.reposadmin.create.html#svn.reposadmin.create.hooks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] amount of overlaping dates
2009/12/3 Merlin Morgenstern merli...@fastmail.fm: I am searching for a way to identify the amount of simultanious date ranges. Example: array start=('1.12', '5.12', '9.12'); array end =('8.12', '12.12', '16.12'); Looks like this in a table: start end 1.12 8.12 5.12 12.12 9.12 16.12 Obviously the first and last daterange do not overlap. So the amount of overlaping bookings is 2. But how to identify this with PHP?! Store the start and end times of each event in an SQL table. SELECT COUNT(*) FROM `event` WHERE `start` = NOW() AND `end` = NOW() gets you the number of events that are happening right now. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] amount of overlaping dates
2009/12/3 Merlin Morgenstern merli...@fastmail.fm: That is what I thought first, too! But this does not work correct as there might be a booking starting for example tomorrow. There needs to be free place for the entire booking period. Ah, of course. I see the problem now. It's an odd situation, because you don't seem to care if room A is available for the first half of the period, and room B is available for the second half - as long as the number of rooms never goes above 3. Checking for a single room being available continuously for that entire period would be a lot simpler. If your resolution is 1 minute, then I'd run the query for every minute of the event. 5 minute or 15 minute resolution would mean doing far fewer queries. If the event count ever goes above 3, you can short-circuit. Something like (pseudo-code)... function is_room_available($start, $end, $resolution, $max) { for($i = $start; $i $end; $i+=$resolution) { $count = SELECT COUNT(*) FROM `event` WHERE `start` = $i AND `end` = $i if($count = $max) { return false; } } return true; } But I think turning it around might be simpler. Think: I have three rooms. For each room, can it accept a 4 hour booking starting at time $time? Then the number of queries is a function of the number of rooms, rather than the length of the meeting. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Metadata - mysqli
2009/11/24 keyser soze bajopala...@yahoo.com.ar: mysqli_fetch_field provide result metadata like 'column name', 'max length', 'datatype' etc but i need the comment of each column is this possible? The table that stores data about columns is information_schema.COLUMNS. You're looking for the COLUMN_COMMENT column. Eg SELECT COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'database' AND TABLE_NAME = 'table' AND COLUMN_NAME = 'column'; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Convert deprecated POSIX functions into wrappers for equivalent PCRE functions
2009/11/9 Tony Marston t...@marston-home.demon.co.uk: So you wouldn't trust the PHP developers to write simple code which takes each POSIX function and redirects it to a PCRE function? I have more faith in their ability than I do yours. If it's as simple as you claim, why don't you mock-up your solution in PHP, rather than C? You'll get taken more seriously if you have working code that someone can write unit tests against. If your solution doesn't get any traction with the core team, you'll still be able to offer it to the community as a simple download, just include this at the top of your script to fix ereg*() not found problems. That would be really useful to all those people whose cause you are championing. (BTW, the reference implementation for PHP is... PHP. There isn't an ISO standard or anything here. How PHP6 behaves is correct, because it's PHP6). (BTW^2 - you're on the wrong list for this. If you want to influence the guys who make the decisions you need to take this to php-internals, where the heavyweights hang out). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Convert deprecated POSIX functions into wrappers for equivalent PCRE functions
2009/11/9 Tony Marston t...@marston-home.demon.co.uk: Because I can't do that until I install PHP 6, but as I never play with beta software waiting for it to go live will be too late. Not sure why not. If it's just the name collision, call them alt_ereg*() until ereg*() goes away. In fact, it's much easier to write unit tests against your new functions if the old functions are still hanging around. I've tried looking at the PHP wiki, but I cannot see any method of creating an RFC. Well, the RFCs are here, but you probably already found them: http://wiki.php.net/rfc (register is in the bottom-right corner). Can't help you with your php-internals problem, I'm afraid. Tried emailing the list manager? I have, however, created a request in php_compat in the PEAR system at http://pear.php.net/bugs/bug.php?id=16769 Fair enough. Good luck. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to Get the Sub Classes of a Parent Class
2009/10/28 Raymond Irving xwis...@yahoo.com: I'm try to do something like what Martin Scotta did but I'm looking for a solution that did not require me to loop through get_declared classes() to find a sub class. Place all your child classes in the same namespace, and use ReflectionNamespace::getClasses(). But I stress, again, that I think there's a design issue that needs to be fixed here. There's going to be a better way to do what you're trying to do. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to Get the Sub Classes of a Parent Class
2009/10/28 David Otton phpm...@jawbone.freeserve.co.uk: 2009/10/28 Raymond Irving xwis...@yahoo.com: I'm try to do something like what Martin Scotta did but I'm looking for a solution that did not require me to loop through get_declared classes() to find a sub class. Place all your child classes in the same namespace, and use ReflectionNamespace::getClasses(). Hah. Turns out that's on the @todo list... wait for PHP 5.4 maybe. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How is this possible?
2009/10/28 tedd t...@sperling.com: Hi gang: http://php.net/manual/en/security.globals.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is the best practice for adding persistence to an MVC model?
2009/10/27 Paul M Foster pa...@quillandmouse.com: On Tue, Oct 27, 2009 at 05:27:07PM +1100, Eric Bauman wrote: I'm in the process of implementing an ultra-light MVC framework in PHP. It seems to be a common opinion that the loading of data from a database, file etc. should be independent of the Model, and I agree. What I'm unsure of is the best way to link this data layer into MVC. I disagree. There should be database class(es) which know how to deal Paul, you already did this in one of Eric's threads a couple of weeks back, and the best you could come up with when pressed was Probably not a great example, but Is it really necessary to rehash this? Eric, I recommend reading up on how to develop testable code (especially Mock Objects) - it's great discipline because it requires everything to be decoupled. The short version is that it's often useful in unit testing to fake the classes that your target relies on, so that you're testing it in isolation. For example you could provide the class under test with a fake DB class that returns static results. It's much easier to do this when you pass objects /to/ your class: class MyClass { function MyClass($db) { } } than when your class inherits from the object: class MyClass extends Db { } or when the class instantiates the object: class MyClass { function MyClass() { $this-db = new DB_CLASS; } } If you go with the first approach, you're writing code that you and anyone who comes after you can write useful tests for. The others, and you're denying maintenance programmers a useful tool. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is the best practice for adding persistence to an MVC model?
2009/10/27 David Otton phpm...@jawbone.freeserve.co.uk: If you go with the first approach, you're writing code that you and anyone who comes after you can write useful tests for. The others, and you're denying maintenance programmers a useful tool. I should have lead with this: the wikipedia article on Dependency injection http://en.wikipedia.org/wiki/Dependency_injection -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to Get the Sub Classes of a Parent Class
2009/10/25 Raymond Irving xwis...@yahoo.com: Hello, Does any know of an optimized solution to get all the subclasses for a parent class? That's not exactly a typical thing to want, although I can see a couple of ways to do it... what exactly are you trying to do, and are you using PHP5.3? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to Get the Sub Classes of a Parent Class
2009/10/25 Raymond Irving xwis...@yahoo.com: I want to automatically initialize a specific sub class when the php page is loaded. I'm looking for a solution for php 5.1+ or anything that's optimized for 5.3 You may be able solve this with a simple class_exists() (pseudo-code ahead): if(class_exists($var)) { $class = new $var; } else { $class = new FourOhFour; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to replace many spaces with one space?
2009/10/25 Jeffry Lunggot jef...@rogon.com.my: Hi, how to replace many spaces in any string of character with one space? $str = preg_replace('/\s\s+/', ' ', $str); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to Delete the parent node, and child nodes/leafs for a db/tbl in php
2009/10/16 bruce bedoug...@earthlink.net: I've got a situation where I have a couple of tables. The relationship between the tables is one of parent/child. I'm trying to figure out the best approach to being able to delete the associated children in the child tbls, of a given parentID in the parentTBL... I've checked into various sites/articles on the 'net.. but i'm not sure how best to accomplish this... I'm using php as the interface language to the test tbls.. Any pointers/articles/test code (code/schema) would be helpful... This is a DB question not a PHP question, plus you haven't told us what database and table type you're using. However, you can either delete the relationship yourself (using PHP code), write a trigger to do it semi-manually, or set your database up properly with a foreign key constraint. Assuming you're using MySQL and your table type supports foreign keys, see http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Insult my code!
2009/10/13 Eric Bauman baum...@livejournal.dk: *sigh* sometimes I really wish PHP allowed one to be a bit more heavy-handed with types (optional real type hinting would be nice). There's a scalar type-hinting patch floating around somewhere, but then your code would only work on machines with that patch. I guess I only ever worried about string (from DB) and int (internal call) as in my specific use I would never be passing a float. You make an excellent point however; I suppose in the interests of completeness, forward compatibility etc. I should take into account more possibilities. Perhaps I should just throw an exception in deposit() etc. if the argument isn't int and worry about converting elsewhere. I can see two choices - either throw an exception in checkInt() if it's passed anything except an int or a string (which is fine - because you've made the assumption explicit) or change the checkInt() so it deals with ints-masquerading-as-floats. Try: function checkInt($x) { return((string)((int)$x) == $x); } Also thanks for the sample TestCase code! I've never really thought about unit testing in PHP, despite doing so in Java etc. Reading about PHPUnit brought me on to phpUnderControl - interesting stuff! Yup. Pretty graphs. That's not the best unit test example to work from, BTW - the manual will give you better advice than I. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Insult my code!
2009/10/11 Eric Bauman baum...@livejournal.dk: As before, please feel free to insult my code. ;-) Any and all feedback is of course most appreciated. I know you're more concerned with structure, but your checkInt() method is arguably buggy/has an un-noted assumption. It accepts ints formatted as ints and strings, but not floats: ?php require_once 'PHPUnit/Framework/TestCase.php'; require_once 'BankModel.php'; class BankModelTest extends PHPUnit_Framework_TestCase { function testSetBalanceAcceptsInts() { $fixture = new BankModel(); $int = 1351236; $this-assertNull( $fixture-setBalance($int) ); } function testSetBalanceAcceptsFloats() { $fixture = new BankModel(); $float = (float)1351236; $this-assertNull( $fixture-setBalance($float) ); } function testSetBalanceAcceptsStrings() { $fixture = new BankModel(); $string = (string)1351236; $this-assertNull( $fixture-setBalance($string) ); } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do YOU set default function/method params?
2009/10/12 Stephan Ebelt s...@shared-files.de: as far as I understood/use it: I try to hardcode as many workable defaults in the vo class as possible (ie. see $subject in the example). Then I create objects by passing result records from the database (arrays) to the constructor. That either returns a object or crashes the application if something is wrong. Optionally I can create objects without any passed-in parameter which will give one with only the defaults set. Depending on the class' definition those may Ok, I'm going to make a case against the use of default values hard-coded within the class here: a) Default values mean more code. The less code you have, the less bugs. Just strip the defaults out, and they'll never cause errors. b) Default values hide missing values. If a value gets mislaid during the build process, the class will still work, kinda, sortof, but it won't behave as expected. Better to exit loudly and let the build manager fix the missing value, rather than try to muddle through on partial data, and fail /really/ impressively further down the road. c) You should store all your config options in the same place. This is simply good practice - it makes life easier for anyone coming after you who knows that /everything/ is in one place. Zend_Config is a nice approach - the Config object parses an ini file, and you pass fragments of the config object to your class constructors. Eg: $conf = new Zend_Config_Ini( 'config/settings.ini', 'live' ); $db = Zend_Db::factory( $conf-application-databasesettings ); d) Default values lead to assumptions. MyClass assumes that DbClass connects to localhost if nothing is passed. This means that MyClass is relying on a feature of DbClass where it doesn't strictly have to, and DbClass is a little bit less of a black box. e) Defaults aren't. What makes sense on one machine (eg a default of 'localhost' for the db) may not make sense on another. Rather than tweak the class defaults to fit the local conditions every time you deploy it, and have dozens of slightly different versions hanging around, just be explicit and push the parameters in from outside. Comments welcome of course, but I've strayed off PHP and into OO design, here. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Insult my code!
2009/10/7 Eric Bauman baum...@livejournal.dk: Any thoughts would be much appreciated! One observation. Model isn't a synonym for Database Table - models can be anything that encapsulates business logic. Requiring all your models to inherit from Model is probably a bad idea. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Output buffering
2009/10/7 Arno Kuhl ak...@telkomsa.net: According to the manual I shouldn't see anything at all when output_buffering is off (or if memory serves me correctly I should see an error about headers already sent or something). Looking at phpinfo confirms the value echoed by the script. Has something changed with output buffering? Use echo ob_get_level() . br/; to find out how many levels of output buffering you are wrapped in. Whether output buffering is set to start automatically, and whether output buffering is on right now are two different things: ob_end_clean(); echo ob_get_level() . br/; echo ini_get('output_buffering') . br/; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Output buffering
2009/10/7 Arno Kuhl ak...@telkomsa.net: Thanks David. After taking another look at the description for ob_start() I began to suspect there was a difference, but the manual doesn't mention anything about it. And the fact they use the same terminolgy for both the settings and the functions is confusing. I can see from tests that the htaccess/ini settings have no obvious effect on the ob functions (maybe buffer size?). My understanding (and it's not 100% clear in the manual) is that the output buffering directive is overloaded - it can be used for both turning output buffering on and setting the size of the output buffer. Quote: ; Output buffering allows you to send header lines (including cookies) even ; after you send body content, at the price of slowing PHP's output layer a ; bit. You can enable output buffering during runtime by calling the output ; buffering functions. You can also enable output buffering for all files by ; setting this directive to On. If you wish to limit the size of the buffer ; to a certain size - you can use a maximum number of bytes instead of 'On', as ; a value for this directive (e.g., output_buffering=4096). output_buffering = 4096 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Insult my code!
2009/10/7 Eric Bauman baum...@livejournal.dk: On 7/10/2009 7:25 PM, David Otton wrote: 2009/10/7 Eric Baumanbaum...@livejournal.dk: Any thoughts would be much appreciated! One observation. Model isn't a synonym for Database Table - models can be anything that encapsulates business logic. Requiring all your models to inherit from Model is probably a bad idea. Thank-you for responding. Out of curiosity, why is this a bad idea? Is it also bad for views controllers? Well, the way MVC has traditionally been approached is that the VC bit is a thin interface skin, concerned with I/O, while the M is the bulk of the program - the bit that does the heavy lifting. (You'll often hear this called Fat Model, Skinny Controller). So you could have a lot of models, that do a lot of disparate stuff - not just database tables. To give you an example, imagine an application that texts people when a new book by their favourite author is coming out. It's going to have models to represent database tables, the Amazon API and an SMS API. If all your controllers assume that all your models inherit from Model, then your code is monolithic and none of it can be reused. http://c2.com/cgi/wiki?InheritanceBreaksEncapsulation Of course, I'm talking about a general-purpose framework here - if all you're ever going to do is CRUD operations on DB tables, then by all means make assumptions about your models. You end up with all your classes tightly coupled, but they're still perfectly fit for purpose. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Insult my code!
2009/10/7 Paul M Foster pa...@quillandmouse.com: I think this is a bit extreme. It really depends on what's in your parent model class. It could be something really simple, but something you don't want to have to rewrite in every model you code. Thinking that Have you got an example of something that is needed by every model that interacts with a general-purpose framework? 1. It keeps me from having to rewrite the same code over and over (inheritance). Inheritance isn't the only mechanism for code-reuse, but it is the most tightly bound. In some situations it may be the appropriate solution, but it does force you into a taxonomy straightjacket. You just need to be aware of that, and pick the appropriate tool for the job. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHPNW09
Is anyone from the list heading to PHPNW this weekend? Saturday: Keynote: The Uncertainty Principle Passing The Joel Test in the PHP world SPL, not a bridge too far Tools and Talent The beauty and the beast – API documentation with phpDocumentor Getting a website out of the door Optimizing Your Frontend Performance Making your life easier: Xdebug Speeding up the snail and making Drupal scale Building an Anti-CMS (and how it’s changed our web team) Introduction to Yii Getting Involved with the PHP Project Integrating Zend Framework and symfony Sunday: Tokens and Lexemes Everything you wanted to know about UTF-8 Intro to OOP with PHP PHP 5.3 – Hot or Not? jQuery http://conference.phpnw.org.uk/phpnw09/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHPNW09
2009/10/6 Ashley Sheridan a...@ashleysheridan.co.uk No, it is a little far out for me. Is there something similar in Londinium? Dozens, probably. Try the PHPLondon guys, and the PHP UK Conference for a start: http://www.phplondon.org/wiki/Main_Page http://www.phpconference.co.uk/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] catch an iconv E_NOTICE
2009/9/24 Tom Worster f...@thefsb.org: but i'd like proceed with default error handling in the branch with the question marks. how can i do that? An error handler that passes through to the previous error handler: ?php error_reporting(E_ALL); function my_error_handler($errno, $errstr, $errfile, $errline) { restore_error_handler(); trigger_error($errstr, $errno); } set_error_handler('my_error_handler', E_ALL); trigger_error('TEST', E_USER_ERROR); You'll lose the file and line, though, because you're actually raising another error with the same message at a new point in the code. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to say inverse your value (to a boolean)?
2009/8/11 Daevid Vincent dae...@daevid.com: NO! For the love of God and all that is holy, don't do that accumulator / mod hack. That's so 1980's. And why make the CPU do all that math for every row... Just do this. It's quick and simple: CSS: .dataRow1 { background-color: #DFDFDF; } .dataRow2 { background-color: #FF; } foreach ($foo_array as $foo) { ?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo ?/td/tr?php } A change request just came in - the interaction designer wants every third line to have a grey background, instead of every second line. No need to initialize $dr as by default PHP will make it a boolean false, then each itteration, it will toggle true/false and substitute the CSS class Um. No. Just no. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHPBB Speed Issues
2009/7/31 Paul Scott psc...@uwc.ac.za: -1. Measure everything. No point implementing a change that slows things down. Implement low-hanging-fruit first (eg a CDN) 0. Optimise your existing setup before adding more layers 1. Cache as much as you can (everything) 2. Minimise HTTP requests 3. Use an opcode cache like APC 4. Use a RAM based cache system like memcacheD and give your db a breather 4a. Cache complete objects, not DB result sets 5. Don't tie up Apache processes with requests for static files (lighttpd/CDN/both) 6. FINALLY, throw more hardware at it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Compare PHP settings of two different servers
2009/7/23 Dave M G mar...@autotelic.com: Is there a way I can take the output of phpinfo() from both servers and do a compare that will tell me what the differences are? Just diff the HTML. WinMerge, Kompare, etc etc. Or probably built into your favourite IDE. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] putenv usage
2009/7/22 Manoj Singh manojsingh2...@gmail.com: Now my question is whether it is fine to use putenv in the production environment? Whether the putenv changes the timezone value globally for all request or for the current request only? The environment variable will only exist for the duration of the current request. - www.php.net/putenv -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_set_contents() do several times?
2009/7/20 Martin Zvarík mzva...@gmail.com: ?php $i = 0; do { $i++; $r = file_put_contents('file.txt', 'content'); } while($r === false $i 3); if ($r === false) die('error'); ? Makes sense? or is it enough to do it just once? Assuming 'content' changes, and this is the cut-down example... $r = file_put_contents('file.txt', 'content', FILE_APPEND); There's a small overhead in opening/closing the file three times instead of one, but I doubt that's going to be an issue for you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: file_set_contents() do several times?
2009/7/20 Martin Zvarík mzva...@gmail.com: 2009/7/20 Martin Zvarík mzva...@gmail.com: ?php $i = 0; do { $i++; $r = file_put_contents('file.txt', 'content'); } while($r === false $i 3); if ($r === false) die('error'); ? I am not appending anything, just ensuring that it will be written (and giving it max. 3 tryes). Ok, don't do that. If it didn't work the first time, it won't work 0.001 seconds later, either. Chances are it will either be a permissions error, or out-of-disc-space. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Exception not being caught
2009/7/15 Weston C west...@gmail.com: ?php class A { } $a = new A(); // Ayn would be proud, right? try { echo a is ,$a,\n; } catch(Exception $e) { echo \nException Caught: ; echo $e, $n; } ? This does not run as expected. I'd think that when the implicit string conversion in the try block hits, the exception would be thrown, caught by the catch block, and relayed. Instead you don't ever see the words exception caught and you get Catchable fatal error: Object of class A could not be converted to string. If it's catchable, why isn't it caught in my example? It's not an exception, it's a fatal error. Fatal errors are caught by error handling functions, not by catch blocks. Consequence of having (at least) two separate error handling mechanisms in the same language. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Object type determined at runtime
2009/7/6 James Colannino ja...@colannino.org Hey everyone. I have a question. Hopefully it's clear, because I'm not sure quite how to ask it. Basically, I have a variety of different objects that a variable can be instantiated as in the same block of code, its type being determined at runtime. I want to be able to do something like this: $object = new $objType(); Where $objType is the type of object, which must be determined at runtime. I'm sure the syntax I have above is incorrect. My question No, you pretty much got it right: class A{ public function e() { echo Hello World; } } $A = 'A'; $a = new $A(); $a-e(); is, is there any way that I can determine the object's type at runtime and do the same type of thing? You're asking a different thing there, but I'll throw it in for completeness: http://uk.php.net/oop5.reflection http://uk.php.net/manual/en/function.get-class.php (BTW, there's a distinction between classes and objects (random link: http://www.felgall.com/obj1.htm)) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function parameter passed by reference with default value to null
2009/7/6 Lupus Michaelis mickael+...@lupusmic.org: I'm happy PHP raises an error on foo(null) ; I'm in trouble when foo() doesn't. The actual question is : why PHP doesn't raise an error ? This functionality (default values for passed-by-reference parameters) was added in PHP5. The problem is that you can't pass literals by reference (which makes sense): function f($a) {} f(45); // error But default values must be literals (which also makes sense): function f($a = $_POST) {} // error So there's some serious impedance mismatch going on there to make both features to work together. Just think of the default value as something I can overwrite, eg: function f($a = 45) { $a = 99; } So it doesn't really matter if it starts off as 45, 'Hello World' or null... it's going to get thrown away at the end of the function's lifetime, anyway. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function parameter passed by reference with default value to null
2009/7/6 Lupus Michaelis mickael+...@lupusmic.org: David Otton a écrit : So there's some serious impedance mismatch going on there to make both features to work together. Just think of the default value as something I can overwrite, eg: Thanks for this smart explanation. It shines my day. np. On reflection, it seems to me that if they were dead-set on default values for pass-by-reference variables, they should have dropped the restriction on passing literals by reference at the same time, and just thrown away the result as happens with default values. Oh well, it's not my language design. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] continue working after finishing up with the http client
2009/5/27 Tom Worster f...@thefsb.org: without getting into whether or not this cache design makes sense, my question in this example is: what options are there for ending the http transition and then continuing on to do the cache update work? You either continue processing then-and-there (exec(), or whatever) or you put the job in queue to be dealt with at your leisure. The queue is the better solution if you're concerned about processor load, as you can prioritise it. The exec() is simpler to implement. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Building an array, kind of?
2008/10/24 Dan Shirah [EMAIL PROTECTED]: How would I go about putting that in a variable to equal 1234,1235,1236,1237,1238,1239 ? Pseudocode: $t = array(); foreach($resultset as $row) $t[] = $row; $t = join(',',$t); -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class constructor overloading
2008/10/23 Alain Roger [EMAIL PROTECTED]: is it possible to overload the class construct(or) ? if yes, how ? class A { function __construct() { echo A; } } class B extends A { function __construct() { echo B; parent::__construct(); } } $B = new B(); -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class constructor overloading
2008/10/23 Alain Roger [EMAIL PROTECTED]: thanks a lot, this is exactly what i needed. if the construct of based class A accept arguments, i guess that construct of class B must have the sames. No, you can change the signature of a method when you overload it. Below, B::__construct() accepts 1 argument while A::__construct() accepts 0 arguments: class A { function __construct() { echo A; } } class B extends A { function __construct( $string ) { echo $string; parent::__construct(); } } $B = new B( B ); If you need to force a certain signature in child classes, you can declare the parent class abstract: abstract class A { abstract function f( $a ); } class B extends A { function f( $a, $b ) // throws an error { echo $a, $b; } } $B = new B(B, C); However, if you declare the constructor as abstract, it will be ignored. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] grab the complete commandline used ...
2008/8/28 Jochem Maas [EMAIL PROTECTED]: I have a feeling I'm out of luck - probably security issues that keep you from doing such a thing as well. I did have the idea of grabbing the PID and then grepping the output of ps via exec() ... that would do it, but I reckon it smells. :-) That won't work. Quote the entire command as a string. Pass it to a shell script that sets an environment variable to that string, then executes the string. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] _SERVER['DOCUMENT_ROOT'] not set?
2008/8/29 Saurabh Agrawal [EMAIL PROTECTED]: In one of the examples, I am supposed to access _SERVER['DOCUMENT_ROOT']. However, when I am seeing its value in the debug stack, I am getting it to be null! Even phpinfo() is showing that this particular variable does not even exist, though there are other _SERVER[''] declarations. What's DocumentRoot set to in your Apache config? (httpd.conf) Check any VirtualHost blocks you might have, too. What's the result of print_r($_SERVER); ? -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] grab the complete commandline used ...
2008/8/29 Jochem Maas [EMAIL PROTECTED]: in what sense won't it work? the complete line is in the output of ps somewhere albeit after wildcard/shell expansion. With the pipe? I'd really like to see an example, beacuse I couldn't coax it out of ps, and it might be handy someday. if life were that simple. it's user X running the php script from the commandline ... I wanna know exactly what he is doing (which is not necessarily the same as what he should be doing). I only really control the php script in question not the context it is run in. You should have said... you are the admin of the machine, right? Patch bash to log user input. Google variations on bash, patch and syslog. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] grab the complete commandline used ...
2008/8/28 Jochem Maas [EMAIL PROTECTED]: anyone know if it's possible to grab the entire commandline that was used to start up a php script on the CLI, an example of what I'm looking to grab from within the script (test.php in this example): php -qC -ddisplay_errors=1 ./test.php -o -d -e [EMAIL PROTECTED] -f ./last.log | grep Exception of course I know what the script name and arguments are but I'd rather like the whole enchilada (php binary and it's args + the pipe to grep). possible? bad idea? down boy? Not possible, I'm afraid. Certainly not portably. The command line is manipulated quite heavily before your script gets run. (eg shell wildcard expansions). A quick Google suggests that it is possible under VMS, but I doubt that's much use to you. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?
2008/8/24 Govinda [EMAIL PROTECTED]: $ThisDir = getcwd()./thumbs; $DirHandle = opendir($ThisDir); if ($DirHandle = opendir($ThisDir)) { echo Directory handle: $DirHandle\n; echo Files:br /hr width=\25\%\ align=\left\ /; while ((false !== ($file = readdir($DirHandle))) 1) { if (true == ($file=.jpg)) { echo $filebr /; } } closedir($DirHandle); } But instead of printing only the name of the file which is equal to .jpg, it seems to actually set the value of $file to .jpg on each iteration of the while loop, so what I get is a list of files all having the same name (.jpg) and their number is equal to the actual number of files in that dir (plus 2 - for the . and .. files). How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'? Hi, you've had a lot of responses to issues in your code snippet. I'm just here to point out - for the sake of the archives, really - that there are at least two more approaches you could take. PHP is one of those languages where there's more than one way to do most things. ?php $path = './thumbs/' . sql_regcase ( '*.jpg' ); foreach ( glob( $path ) as $filename ) { echo {$filename}br/; } You can check the manual for full details, but briefly, sql_regcase() returns a case-insensitive regular expression, and glob() returns an array of filenames that match the path given to it (in this case ./thumbs/*.jpg). ?php $dir = new DirectoryIterator( './thumbs/' ); foreach( $dir as $file ) { if ( preg_match( /jpg$/i, $file-getFilename() ) ) { echo $file-getFilename() . br/; } } In this one, we're iterating over a DirectoryIterator object (http://uk2.php.net/manual/en/class.directoryiterator.php) instead of the output of glob(). RecursiveDirectoryIterator also exists, which allows you to traverse an entire tree, rather than just one directory. You've already been pointed to preg_match(), so I won't explain that one again. -- http://www.otton.org/category/programming/php-tips-tricks/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?
2008/8/25 David Otton [EMAIL PROTECTED]: You can check the manual for full details, but briefly, sql_regcase() returns a case-insensitive regular expression, and glob() returns an array of filenames that match the path given to it (in this case ./thumbs/*.jpg). I should have mentioned that glob() accepts shell wildcard expansions, not regular expressions. But in this case they're similar enough that you can get away with a mix-and-match approach. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] comments function being spammed, how do I stop it?
2008/8/25 Barnaby Walters [EMAIL PROTECTED]: my comments function for my website (at www.waterpigs.co.uk/php/phpTest.php) is being spammed, what would be your sugguestions of a way to deal with it? I was thinking of something to do with searching the strings of comments contained in the database for rude words, etc, but I'm unsure as to how to do it. Akismet. One of the classes for interfacing with it is here: http://www.achingbrain.net/stuff/php/akismet -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Remote File download is very slow
2008/8/25 Shiplu [EMAIL PROTECTED]: Hello folks, I have written a method to download file from remote server. normally those fill will be huge in size. from 1MB to 400MB. I am using fsockopen and curl to download the file. But the problem is its too slow. Very very slow. What happens when you remove the first half of the if(), the bit that relies on fsockopen(), and only use curl? -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Remote File download is very slow
2008/8/25 Shiplu [EMAIL PROTECTED]: Nothing works. I was using curl actually. It was hell slow. Then I added the fsockeopen option. Its slwo too. now I am thinking to add socket_* functions. But If dont know what is the problem how can I resolve it. change scheme may not solve it. :( Ok, lets start by getting some accurate data. Here's a script that downloads a 6Mb MP3: ?php $fp = fopen( temp1.mp3, wb ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, http://gramotunes.com/Life_is_Long.mp3; ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt( $ch, CURLOPT_FILE, $fp ); curl_exec( $ch ); curl_close( $ch ); Save it as download.php, and run the following two commands: time php download.php time wget http://gramotunes.com/Life_is_Long.mp3 I get real0m6.105s and real0m5.927s If your results are about equal, then the problem is not with PHP. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Which Exception to use ....
2008/8/22 Jochem Maas [EMAIL PROTECTED]: still leaves the questions as to what a DomainException and a ErrorException is meant to model. A domain exception is thrown when a value is valid according to its type, but not within the domain of the function that it is being passed to. For example if you had a function that only processed odd numbers, passing it (int)6 would be a domain exception. ErrorExceptions model genuine PHP errors - the mechanism that you manipulate with error_reporting(). You can convert a PHP error to an Exception with set_error_handler(). Your list brings together exceptions from all over PHP which shouldn't really be considered together. For example, many of them are from the SPL. They're supposed to be generic - that's what the SPL is for, it's there to solve a specific class of problems. In that context, those exceptions make complete sense. Other exceptions on your list are only ever meant to be thrown from within PHP itself - they're there for us to catch, not to throw. Take a look at the Zend Framework as an example of best practice in these things. I don't think that throws a single built-in exception (although some of the SPL exceptions might be nice to use, they mostly solve the same class of problems as assert()). -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quick question regarding getcwd() and directory location.
2008/8/23 Ólafur Waage [EMAIL PROTECTED]: Robert, thanks for the reply but i had tried __FILE__ and __DIR__ (which is dirname(__FILE__)) but it doesnt work. And thanks for the reply also Ashley but as i said in my first post, i had tried $_SERVER with limited results If checking the output of phpinfo() doesn't help (and it looks like it won't), I'd suggest starting with REQUEST_URI, then, if you know where your webroot is, you should be able to calculate the path to the target directory (/var/www/example/../test/ in your original example) by gluing bits of path together. Hardly an ideal solution as it needs configuration, but it would work. I think this is really a mod_rewrite problem, as by the time PHP takes over you've lost the information you need. You may have better luck in a forum devoted to mod_rewrite, but I'm not optimistic that it has a what file would have handled this request if mod_rewrite hadn't run parameter. I think you're going to have to build your directory path from the information in the original request and some configuration glue. Good luck (BTW, I initially thought there might be something in mod_autoindex to run a custom script, but it doesn't look like there is.) -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Timing problem, putting PNG into PDF
2008/8/12 Brian Dunning [EMAIL PROTECTED]: I'm using GD to crop save an uploaded image, and then embedding it into a PDF made with FPDI. It works great when the image is small or low-res. When the uploaded file is bigger, more than a couple hundred K or so, it fails. I think that the image is not done writing yet by the time I try to do the $pdf-Image. Any suggestions? Some way to force it to hang out and pause until the image is done writing? It's more likely you're hitting a memory limit in your script. Pare your script down to just the resize action, and turn error reporting on. What function are you calling to do the resize? It shouldn't return until it's finished processing. BTW, ImageMagick produces smoother results than GDLib when resizing. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Number of duplicates in an array?
2008/8/18 tedd [EMAIL PROTECTED]: Anyone have a cool method of finding duplicate items in an array and the number of times they appear? I'm doing it in a way that is probably less than optimum. I want to see how you guys solve it. Hmm. Assuming the following inputs and outputs: $input_array = array( 'one', 'two', 'three', 'one', 'two', 'one' ); $output_array = array( 'one' = 3, 'two' = 2, 'three' = 1 ); $input_array = array( 'one', 'two', 'three', 'one', 'two', 'one' ); $output_array = array(); foreach( $input_array as $input ) { if ( !isset( $output_array[$input] ) ) { $output_array[$input] = 0; } $output_array[$input]++; } Untested code. From a CompSci PoV, input_array is a list while output_array would be better implemented as a binary tree (with the normal caveats about tree balancing). But given that we're working in PHP and your data sets probably aren't that large, this is the good enough solution. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [PHP Header] Right-Click Download in Firefox showing php filename
2008/8/4 Will [EMAIL PROTECTED]: I am trying to have users download a file named 'Setup.msi', however under a PHP file with the sent header information, the default name to $forcename = ApplicationSetup_v1_0.msi; $filename = Setup.msi; header(Content-Type: application/force-download); header(Content-Type: application/octet-stream; name=.$forcename); header(Content-Type: application/octetstream; name=.$forcename); header(Content-Transfer-Encoding: binary); header(Content-Length: .filesize($filename)); @readfile($filename); Try a variation on this: header(Content-Type: application/x-msi); header(Content-Disposition: attachment; filename=\ApplicationSetup_v1_0.msi\; ); header(Content-Transfer-Encoding: binary); header(Content-Length: . filesize('Setup.msi')); readfile('Setup.msi'); http://www.mhonarc.org/~ehood/MIME/rfc2183.txt content-disposition controls what the browser should do with the file you're sending (open it or save it). filename suggests what the file should be saved as on the local system, when downloading as an attachment content-type is the mime-type of the file you're sending -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strcmp($var1, $var2) versus if ($var1 $var2)
2008/5/28 C.R.Vegelin [EMAIL PROTECTED]: $var1 = 01011090; $var2 = 010190; // 2 strings if ($var1 $var2) ECHO var1 var2; else ECHO var1 = var2; echo br /; $r = strcmp ( $var1 , $var2 ); if ($r 0) ECHO var1 var2, br /; 2nd line says: $var1 = $var2 4th line says: $var1 $var2 Implicit type conversion. is a numeric operator, so your strings are silently promoted to integers, where (1011090 10190). strcmp() treats the strings as strings, and orders them in something close to ASCII order (which isn't the same as alphabetical ordering, BTW, and see the comments at www.php.net/strcmp for locale-specific gotchas). PHP's implicit conversions can bite you if you don't understand them. Try this one: $a = 'string'; $b = 0; if ($a==true $b==false $a==$b) { echo ('universe broken'); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SCanning text of PDF documents
2008/5/15 Angelo Zanetti [EMAIL PROTECTED]: A client of ours wants a solution that when a PDF document is uploaded that we use PHP to scan the documents contents and save it in a DB. I know you can do this with normal text documents using the file commands and functions. Is it possible with PDF documents? My feeling is NO, but perhaps someone will prove me wrong. There's a good chance your installation already has pdf2ps and ps2ascii -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Good XML Parser
2008/5/12 Waynn Lue [EMAIL PROTECTED]: What's the best way to pull down XML from a URL? fopen($URL), then using xml_parse? Or should I be using XML_Parser or SimpleXML? XML parsers fall into two general camps - DOM and SAX. DOM parsers represent an entire XML document as a tree, in-memory, when they are first instantiated. They are generally more memory-hungry and take longer to instantiate, but they can answer queries like what is the path to this node or give me the siblings of this node. SAX parsers are stream- or event-based, and are much more lightweight - they parse the XML in a JIT fashion, and can't answer much more than give me the next node. If you just need the data, a SAX parser will probably do everything you need. If you need the tree structure implicit in an XML document, use a DOM parser. Expat, which XML Parser (http://uk3.php.net/manual/en/book.xml.php) is based on, is a SAX parser. DOM XML (http://uk3.php.net/manual/en/book.domxml.php) is, obviously, a DOM parser. I don't know, off the top of my head, which camp SimpleXML falls into. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Good XML Parser
2008/5/12 Waynn Lue [EMAIL PROTECTED]: So if I'm looking to parse certain attributes out of an XML tree, if I use SAX, it seems that I would need to keep track of state internally. E.g., if I have a tree like head a b/b /a a b/b /a /head and say I'm interested in all that's between b underneath any a, I'd need to have a state machine that looked for an a followed by a b. If I'm doing that, though, it seems like I should just start using a DOM parser instead? Yeah, I think you've got it nailed, although your example is simple enough (you're only holding one state value - am I a child of a?) that I'd probably still reflexively reach for the lightweight solution). I use SAX for lightweight hacks, one step up from regexes - I know the information I want is between tag and /tag, and I don't care about the rest of the document. The more I need to navigate the document, the more likely I am to use DOM. I could build my own data structures on top of a SAX parser, but why bother reinventing the wheel? Of course, you have to factor document size into that - parsing a big XML document into a tree can be slow. You might also want to explore XPath (http://uk.php.net/manual/en/function.simplexml-element-xpath.php http://uk.php.net/manual/en/class.domxpath.php)... XPath is to XML as Regexes are to text files. There's a good chance you'll be able to roll all your parsing up into a couple of XPath queries. I probably should have added that simple parsers come in two flavours - Push Parsers and Pull Parsers. I tend to think (lazily) of Push and Pull as variations on SAX, but strictly speaking they are different. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Improving development process / help with developer setup
2008/5/10 robert mena [EMAIL PROTECTED]: I am looking for tips regarding improving the development process. I'll explain my current setup and please feel free to comment. My developers all use windows + eclipse PDT, the workspace is hosted (via samba) in a Linux server with Apache/PHP/MySQL. I am in the process of adopting Unit testing (PHPUnit2) and debug (Xdebug) so I have concerns about how to property use this. For example, in my current setup I'd have to enable SSH so they could run the tests from the command line in the development server, but I am not sure if I could remotely use Xdebug. Your description (specifically, Samba) suggests that you're not using source control. If you want to go for TDD (I don't know that you do, but IMO it's a good direction to move in) I would suggest a three-server setup - dev, staging and live. The dev server(s) are where you work. One per developer. Once you're happy with your code and your tests, you commit your changes to source control. This is where it gets clever. You can use pre- and post-commit hooks to run an automated build process that pushes the changes to a staging server, automatically runs the unit tests, and accepts/rejects the commits based on the test results. You can even lint the code, and reject anything that isn't in the house style. With larger projects, where an entire publish-and-test on each commit becomes impractical, you can just run the build process and unit tests every n hours, and mail out the results. Publishing to the live server is simply a matter of running the build scripts with a different destination. On top of all that, run an issue tracker. /Everything/ goes in the issue tracker, bugs, features, whatever. When you make a commit, that commit should be closing an issue in the issue tracker (via commit hooks again). That way you can track each change that's been made back to its reason. All of this is opinion, of course, there's no Right Way. Just take what's useful to you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Month with leading zeros
2008/5/10 Ron Piggott [EMAIL PROTECTED]: I am wanting to change echo option value=\ . $months[$month] . \; to output the month number, between 01 and 12 --- DATE value m, the month with leading 0's. How do I do this? $months is an array, as I have shown below. Ron ?php $months = array('1' = 'January', '2' = 'February', '3' = 'March', '4' = 'April', '5' = 'May', '6' = 'June', '7' = 'July', '8' = 'August', '9' = 'September', '10' = 'October', '11' = 'November', '12' = 'December'); $current_month = DATE(n); echo SELECT NAME=\order_received_month\\r\n; foreach (range(1, 12) as $month) { echo option value=\ . $months[$month] . \; if ( $month == $current_month ) { echo SELECTED;} echo . $months[$month] . /option\r\n; } ? /select Try this (from memory, untested). for ($i = 1; $i = 12; $i++) { $month = date( 'm', strtotime( 1970-$i-01 )); echo option value=\$i\$month/option; } Or this: printf( %02d, 5 ); However, please consider replacing numeric identifiers for months with textual ones ('M' rather than 'm'). [01] [Apr] [2008] doesn't cause the confusion that [01] [04] [2008] does. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Month with leading zeros
for ($i = 1; $i = 12; $i++) I'm an idiot. for ($i = 1; $i = 12; $i++) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Recursion... Sort of...
2008/5/8 Matt Neimeyer [EMAIL PROTECTED]: Is there a way to tell if a function has been called that has resulted in a call to the same function? debug_backtrace() Can't comment on performance, though. Its an inelegant solution. We have an in-house CRM app that has a function that draws a tabbed panel on a screen... BUT if there are sub-sub-tabbed panels we want to invert the tab colors and panel colors... So... DrawSubTab($Set) - Black on White Content DrawSubTab($Set) - White on Black Content DrawSubTab($Set) - Black on White Content DrawSubTab($Set) - Black on White Content Etc... Nested? You may be able to do this in pure CSS, without keeping a depth counter at all. I suppose I could rewrite EVERY call to the function with a recursion count like DrawSubTab($Set,$DepthCount+1) but that would be a MASSIVE commit... whereas if the function can determine itself... All that It's an easy change. function DrawSubTable($Set, $DepthCount = 0) { [..] DrawSubTable($Set, $DepthCount + 1); [..] } By providing a default value, all the calls to DrawSubTable() can remain unchanged. You just have to modify its own calls to itself. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to create accessible by PHP
2008/5/3 Todd Cary [EMAIL PROTECTED]: Are there any examples of creating a dll that can be placed in the dll directory of php that can be accessed by php? My language would be Delphi, however an example in C would suffice. Custom PHP extensions. I don't know of any Delphi-specific examples, but this link might give you a starting point: http://uk.php.net/manual/en/internals2.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Assigning functions
2008/5/2 Philip Thompson [EMAIL PROTECTED]: Hi all. I have several classes. Within each class, a new class is called. Is there a way to assign a function in a *deeper* class to be called in the first class? Example to follow.. ?php class A { function __construct () { $this-b = new B (); // I want to do the following. This does not work, of course. $this-doSomething = $this-b-c-doSomething; } } class B { function __construct () { $this-c = new C (); } } class C { function __construct () { } function doSomething () { echo ¡Hi!; } } $a = new A (); // Instead of doing this, $a-b-c-doSomething(); // I want to do this. $a-doSomething(); // ¡Hi! ? Basically, it's just to shorten the line to access a particular function.. But, is it possible?! Inheritance - http://uk.php.net/extends class A { function methodOfA() {} } class B extends A {} B::methodOfA(); (use sparingly - too much inheritance results in a tightly-coupled hierarchy of classes, which are brittle and hard to re-use). Or simply express the method in the interface of the exposed class: class A { function methodOfA() {} } class B { function methodOfA() { A::methodOfA(); } } b::methodOfA(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] disappearing array?
On Thu, 20 Sep 2007 12:58:28 -0600, you wrote: I am not sure what the heck is going with this but here is my problem. I am trying to validate the contents of an array, then determine if the errors are with the array or another form submitted variable. The problem is after the code validates the array and other form variables using an if statement, I then try to determine if the error is in the array but for some reason the contents of the array disappear. Weird. Any help is appreciated. Very hard to suggest anything from the snippet presented, as it can't be run without the supporting classes (ValidateStrings and whatever $fix is supposed to be), and it won't parse; the // comment on the end of line 9 borks it, and the if () on line 21 is missing its closing brace. If I assume one run-on if() statement and add the closing brace, I'd say that this looks weird: if( $fix-ValArray( $_POST['add_order_items'] === -1 ) ) { $errors['add_order_array'] = $erlink; } In your snippet ValArray() appears to be a function, rather than a method of $fix. I suggest adding error_reporting(E_ALL); to the top of the script and letting us know what the output is, then try to put together a minimal example that can actually be run (even if you have to fake a ValidateStrings class that always returns -1) and still shows your error. Plus some general suggestions, feel free to ignore... I think you're using || where you mean to use in that run-on if() statement. You're saying IF (NOT Integer OR NOT Paragraph OR NOT Money) which will always evaluate to true. Unless your ValidateStrings class is holding some kind of state data internally, it may be a good candidate for a static class. ValidateStrings::ValidateParagraph() is a bit verbose, how about just Validate::Integer() Validate::Paragraph() etc. In PHP, it's more typical to use true/false for success failure, rather than returning -1 on failure, something like: if (!Validate::Integer($value) !Validate::Paragraph($value)) { /* failure */ } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Run script every 30 seconds
On Mon, 30 Oct 2006 21:26:29 +0300, Ahmad Al-Twaijiry wrote: The right way to do this, as others have mentioned, is with a daemon. Having said that... is it possible to link the script to my php interface (the one that the users is using it) and if the php interface page will run the script (IN background) if it didn't run for the last 30 seconds ? I see this is very hard and almost impossible , what do you think ? http://www.webcron.org/ However, an admin on a shared host may (quite rightly) kick you for wasting shared resources. A script that has to be run every 30 seconds sounds like it's covering for a bad design decision to me. Can you tell us more about what you're trying to accomplish? We might be able to find a more elegant solution. PS: also I need to make sure no more than 1 process of the script is running :) Locking. At its simplest, have your script create a dummy file when it first runs, and delete it when it exits. If the file already exists, then you know that a copy of your script is already running, so you exit. (Include a timeout in case the script dies halfway through - if the file is more than 5 minutes old, run anyway). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Removing an aspect of a variable...
On Tue, 6 Jun 2006 08:52:46 +0100, Robin Vickery wrote: On 06/06/06, Rob W. [EMAIL PROTECTED] wrote: Say I have a variable setting an ip address of 192.168.100.0 I want to be able to remove the last to chr's of that variable ie: .0 What would be my best solution to do that? Remove the last two characters of a string? $shorterString = substr($string, 0, -2); Whether that's really what you want to be doing with an IP address is up to you. substr will remove the last two characters from a string, as mentioned above. If you want to remove the last byte from an IP address (which could be .0, .10, or .100) I would suggest: $ip = 192.168.100.0; $ip = explode ('.', $ip); array_pop ($ip); $ip = implode ('.', $ip); With PHP 5.1 and up, explode accepts a negative limit, which would simplify things. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cannot read variables
On Tue, 6 Jun 2006 10:36:12 +0300, you wrote: I just set up a test box for PHP/MySQL on a WinXP box and now I'm having trouble with variables passed to browser from a link. For example I have a link that outputs this: http://localhost/index.php?team=CF10b. Now the CF10b cannot be user in the code like it should. I turned to Register Globals on in the php.ini but that didn't help. Any ideas? Most likely you didn't turn RG on (typo? wrong php.ini?), or didn't restart. Try: print_r ($_POST); print_r ($_GET); print_r ($_REQUEST); to see if your variable is being passed. If it is, PHP isn't set up as you want it. If it isn't, there's something more fundamental wrong. -- http://www.otton.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP 4.3.11, call_user_func and instances of classes
A bit of an oddity, this. There's some example code attached which illustrates my problem. I am attempting to call a method of an instance of an class from outside that instance, using call_user_func(). What's happening is that my attempt to call array ($this, 'AddOne') is silently being rewritten into a call to array ('Test', 'Addone') in other words, instead of calling $test-AddOne I'm calling Test::Addone. Thus, my expected output: Add:1,Add:2,Add:3,Subtract:2,Subtract:1,Subtract:0, becomes Add:1,Add:1,Add:1,Subtract:-1,Subtract:-1,Subtract:-1, So, my question is twofold: a) How can I accomplish this? b) Why is PHP silently modifying my code to mean something I didn't write, rather than throwing up an error? ?php $addition = $subtraction = null; class Test { var $x; function Test () { global $addition, $subtraction; $this-x = 0; $addition = array ($this, 'AddOne'); $subtraction = array ($this, 'SubtractOne'); doMath('+'); doMath('+'); doMath('+'); doMath('-'); doMath('-'); doMath('-'); } function AddOne () { $this-x++; echo (Add:.$this-x.,); } function SubtractOne () { $this-x--; echo (Subtract:.$this-x.,); } } function doMath($choice) { global $addition, $subtraction; switch ($choice) { case '+': call_user_func ($addition); break; case '-': call_user_func ($subtraction); break; } } $test = new Test(); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sort by string length...
On Tue, 21 Dec 2004 16:18:52 -0500 (EST), you wrote: Any idea how to sort an array by string length? You write a function that compares two strings (A and B), and returns 0 if len(A) == len(B), -1 if len(A) len(B) or +1 if len(A) len(B). function compare_by_length ($a, $b) { $la = strlen ($a); $lb = strlen ($b); if ($la == $lb) return (0); return ($a $b) ? -1 : 1; } Then, you pass the array to be sorted and the comparison function to one of the u*sort() functions: usort ($array, 'compare_by_length'); (Caution: untested code. Also, consider what happens when you pass a jagged array to usort()). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Letter incrementing
On Thu, 18 Mar 2004 15:16:34 +0200, you wrote: But I need to do a $variable = B; and then do a $variable++ that will result in $variable == C for ($i = 0; $i 26; $i++) { echo (chr($i + ord('A'))); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] diskusage
On Mon, 16 Feb 2004 15:17:52 -0500, you wrote: Chakravarthy Cuddapah wrote: In php I want to know space used (du) by user on a remote system. Can anyone pls tell me how this can be done. Just call du through exec(). He said remote system, which I read to mean on the client[?]. In that case, it can't be done. Security. http://uk2.php.net/manual/en/function.disk-free-space.php will give you disc free space in a portable way (PHP = 4.1). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about php forwarding to javascript
On Sun, 15 Feb 2004 07:52:11 +0100 (CET), you wrote: Could be missing the point here because your question is quite vague. However... I am using a web page that uses the following php code to display the contents of a dynamically update webpage: ?php include(http://.../source.xls); ? Is it possible to forward the contents of the code to a javascript? eg if the file source.xls contains the text help me is it possible to send that text to a javascript? I am quite stuck here so any help would be greatly appreciated. source.xls just contains a bit of text, right? And you want that to end up in a Javascript variable? First, I'd use file_get_contents() or file() to get the contents of source.xls into a PHP array. $source = file_get_contents ('http://.../source.xls'); Next, you have to remember that Javascript is just text, the same as HTML. So you can embed $source into a Javascript block in the same way as you would embed it into HTML. script language=Javascript function doAlert () { var source = ? echo ($source) ?; alert (source); } /script a href='javascript:doAlert()'Click Me/a Apologies for any mistakes in the Javascript, but I'm sure you get the idea. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ODBC with SQL Server
On Fri, 13 Feb 2004 12:30:42 +0100, you wrote: I have a connectoin ODBC with a SQL Server database. A table has a field of type 'nvarchar'. This field contains japanese characters. How can I read these japanese characteres? When I read (with: select name from data) only read '?' character. I've come across this recently when talking to MySQL from a Windows application. ODBC didn't like transferring 8-bit data - BLOB and TEXT fields end up as strings of ?. On Windows, you have to open a seperate stream object (ADO = 2.5) to recover the binary data. How that translates to the ODBC library used by MySQL I have no idea... odbc_binmode() may help, possibly. Have you considered just using the mssql_* library? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calling cgi post form from within php
On Sat, 10 Jan 2004 13:46:19 -0500, you wrote: does anyone know how to call a cgi script and pass along a post-form from within php? http://pear.php.net/package/HTTP_Request There are others, of course. But this will let you make a POST request. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Headers and sessions in php .cgi
On Sat, 10 Jan 2004 17:44:18 +0100 (MET), you wrote: I have a problem setting my headers right with php running as .cgi. I have to specify a Content-type for the cgi file to work. But how should I do both that and start a session? I have a few options: #! /usr/local/bin/php ?php session_start(); print 'Content-type: text/html' . \n\n; This way $_SESSION['count'] stays unset even though I say $_SESSION['count'] = 1; in my program. To swap the two lines won't work because I heard \n\n terminates the header portion. Anyway, here goes: Stupid question: Have you tried header ('Content-type: text/html'); I'm pretty sure it will work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if(NANC 0) - always evaluates TRUE...
On Tue, 6 Jan 2004 10:57:52 -0800, you wrote: ...no matter what follows the NANC...seems like a bug. if(NA 0) { print(err 1\n); } if(NAN 0) { print(err 2\n); } if(NANC 0) { print(err 3\n); } if (NANC 0) { echo (one); } else { echo (two); } outputs two here, as expected. PHP 4.3.2 over Win2000. Maybe you're seeing a side-effect of a Not A Number magic value being intelligently-evaluated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Alternate way of e-mailing in PHP
On Mon, 05 Jan 2004 01:38:09 -0500, you wrote: I've been getting data format errors from Sendmail when trying to send automatic e-mails from my websites recently, and as I can't find a fix for Quick questions: what does sendmail_path in php.ini look like? Where is the data format error message being created? My /guess/ is that your local copy of sendmail is using the wrong FQDN and so your email is being rejected by the next machine in the chain. Have you changed anything in /etc/hosts or your DNS recently? But in that case... the code you show below probably wouldn't work either. Odd. Maybe you could ask the guys in comp.mail.sendmail... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Unlinking files.
On Tue, 23 Dec 2003 19:08:28 -0800 (PST), you wrote: How can I unlink files in a directory that are, for example older than 1 hour? `find /path/to/dir -cmin +60 -type f -print0 | xargs -0 rm -f`; Alternatively, for cross-platformness user opendir() and readdir() to iterate over the directory, stat() or filemtime() to grab the last-modified time of the file, and unlink() to remove files where ($last_modified time() - 3600). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Security Question
On Thu, 18 Dec 2003 10:43:14 -0500, you wrote: I'm trying to develop a secure web based application and my only tools are php, mysql, and a SSL connection. Does anyone know of any good references for this kind of development? What I really need to do is to make sure that given users only gain access to the parts of the application they are given rights to. I'm not sure if I need to pass their user information along from page to page or if I should set a cookie or whatever else would be appropriate. Read up about sessions. Essentially, a session is a random token which is sent to the client (normally as a cookie), and is associated with a collection of data server-side. You can safely store sensitive data (userids, privilege levels, etc) in the session because they never leave the server. http://www.php.net/manual/en/ref.session.php I also want people to be bounced back to the login page if they enter a direct URL to part of the application without logging in first, and I also want people to be able to log out. include() a file at the top of every page that checks for the existence of a valid session. If no session is present, use header(Location:) to bounce the user back to the login page and exit(). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] new set of eyes?
On Sat, 06 Dec 2003 11:38:18 -0700, you wrote: I think I am loosing my mind this afternoon... could someone review this snippit and tell me why it isn't working? $sql = mysql_query(SELECT $i FROM $table WHERE $i = $i,$db)or die(mysql_error()); while($b = mysql_fetch_array($sql)) { while($ar = current($b) != 0) { $v = array(); list($v) = explode(},$ar); } print_r($v); } I am hoping to get something like array([0]=first row of data[1]=second row of data) Your code doesn't have any context, so I can't be sure whether you're doing something very smart or very dumb with the SQL statement. The explode() is kinda weird, too. Try running this: ? $sql = SELECT $i FROM $table WHERE $i = $i; echo ($sql); $rs = mysql_query ($sql, $db) or die (mysql_error ()); $result = array(); while ($row = mysql_fetch_array ($rs)) { $result[] = $row; } print_r ($result); ? and let us know how close it comes. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Max Upload FIle Size
On Fri, 05 Dec 2003 13:41:03 +0300, you wrote: Steve Vernon wrote: I have search google, and PHP but I cannot find properly how to set the maximum post upload size as 200Kb? Amazing what you can find in the manual these days http://www.php.net/manual/en/configuration.directives.php#ini.post-max-size You snipped the important bit of the question: Do I use 200K or 200KB for post_max_size? Which that page doesn't answer. Steve: the answer, from memory, is K - but set it to both and test it. Or just set it to 102400. Guido: you're probably running into the max file size problem with your bitmap. The above link should help you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for help :how to detect norton client through php socket
On Thu, 4 Dec 2003 15:39:30 +0800, you wrote: how can i detect whether norton antivirus client are installed on the hosts through php socket ? Why would you want to? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File - Success Warning Message
On Thu, 4 Dec 2003 01:54:31 -0800 (PST), you wrote: Warning: file(http://webmail.juicemarketing.net;) - Success in /me notes this is a pyramid scam site Don't know about the rest of you... but there are some people I'd prefer /not/ to do free consultancy for. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with references
On Thu, 4 Dec 2003 11:16:10 -, you wrote: I wonder if there is a simple techique to help me here. I wish to return 2 references to objects from a function. The following code describes what I want to do but obviously will not work (and I understand why): function Test ($P1, $P2) { $Object = new Thing(); $P1 = $Object; $P2 = $Object-Property; } More generally is there a technique I can use for setting a referenced variable to be a reference? Ok, the third line of that function is really weird. You're returning the object anyway, so why would you want to return a property of the object? It breaks encapsulation. To return more than one item... have you considered simply returning an array? function f() { return (array (7, 5)); } list ($a, $b) = f(); I can't really see a benefit to passing in $P1 and $P2 at all, let alone by reference... maybe you could go into more detail about what you're trying to do? Why do you need to return a reference to the object, rather than the object itself? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] open rtf in IE
On Thu, 4 Dec 2003 12:48:45 +0100, you wrote: I generate and save a rtf file with php in my MySQL db. Is it possible to open this file in IE? Probably not; I doubt IE understands RTF documents. You're probably asking how to make IE pass the document over to Word, though. Try variations on header (Content-type: text/rtf); header (Content-Disposition: attachment; filename=myfile.rtf); header (Content-type: application/msword); These may not be exactly the attributes you want... read http://www.faqs.org/rfcs/rfc2183 and experiment. Maybe inline rather than attachment would do it; I'm not really sure. Most people want to stop IE embedding Word, rather than encourage it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Premature end of script headers: php.exe
On Thu, 4 Dec 2003 13:17:57 +0100 , you wrote: I have a problem. When I start my PHP script, I get message Premature end of script headers: php.exe. How can I solve this problem? Run from the command line, or via a webserver? IIS or Apache? CGI or Apache module? Do all scripts throw the error, or just some? What about an empty script? What error code is the webserver returning? What do your error logs show? (My guess is that Apache is complaining that PHP is misconfigured or can't be found - maybe a bad ScriptAlias or Action line in httpd.conf. But you're not giving us much to work with here.) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What do you say to someone who says...
On Thu, 4 Dec 2003 15:16:06 -, you wrote: What do you say to someone who says: PHP is just a kiddie language? (Source: http://www.dhtmlcentral.com/forums/topic.asp?TOPIC_ID=19373) PHP is currently my strongest development language and it annoys me that it is a much less bankable skillset than .NET and Java. How long do you think it's going to take to get respect? Will it ever happen? PHP is a language designed for a limited problem domain (HTML processing), with a gentle learning curve and missing a lot of modern syntax. These can be strengths as well as weaknesses, of course - it all depends on the problem you're trying to solve. However, these attributes do make it a kiddie language (and I'm not using that in an especially pejorative sense) when compared to languages with other design goals. We're just fortunate that most web problems are kiddie problems, too. (It's foolish to get into blind religious wars over languages, so I won't take this any further, but it's also foolish to be wilfully ignorant of the strengths and weaknesses of the tools you use.) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with references
On Thu, 4 Dec 2003 09:58:09 -0800, you wrote: David Otton [EMAIL PROTECTED] on Thursday, December 04, 2003 3:43 AM said: function f() { return (array (7, 5)); } list ($a, $b) = f(); Hey cool! I never knew about that. Yeah, compared with returning a pointer to an array of pointers to structs... well, scripting languages make you lazy :) But without some feedback, I have no idea whether it solved his problem or not :( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with $_POST[] and header();
On Tue, 2 Dec 2003 10:26:08 -, you wrote: if(!mysql_query($query)){ $error = Could not complete query; header(Location: file.php?error=$error); exit; } The Location: header requires an absolute URI. See RFC 2616, 14.30 However in file.php I have included $_POST[] variables sent from a previous page using the following method foreach ($_POST as $key = $value) { echo input type=\hidden\ name=\.$key.\ value=\.$value.\; } But if there is a problem with the input the $_POST[] values are not resent, is there a way to do this? Pass them as part of a GET, or store them in a session (you may need to include the session ID as part of the URI). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to split a string of numbers into segments.
On Tue, 02 Dec 2003 13:14:20 +, you wrote: Is there an easy, non expensive way to do the perl-equivalent of: $date=20031202; ($year, $month, $day) = ($date =~ /(\d{4})(\d{2})(\d{2})/; I looked through the preg_* functions online, but couldn't see anything to help me. Am I stuck with substr() :P ? list() springs to mind list ($a, $b, $c) = preg_split (/* mumble mumble */); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php