Re: [PHP] PHPDoc way to describe the magic getter/setters [SOLVED]
On Wed, Sep 25, 2013 at 4:31 PM, Daevid Vincent dae...@daevid.com wrote: Then I randomly stumbled upon this PHPDoc @ method tag and my whole world is brighter today than it has been for the past, oh let's say DECADE! Yes, @method and @property are very handy. Out of curiosity, since you're providing magic getters and setters, why not use __get and __set instead of __call with matching on get_xxx and set_xxx? This would allow using the simpler (and IMHO much more expressive and PHP-ish) forms $obj-foo = $obj-bar + 5; Peace, David
Re: [PHP] PHP Dependency Injector
On Thu, Sep 5, 2013 at 1:40 PM, Juan Sebastian Scatularo sebastianscatul...@gmail.com wrote: Thanks Sorin, I will do that and I will have more care the next time. You can also check out Pimple [1] by the creator of the Symfony Framework. Peace, David [1] http://pimple.sensiolabs.org/
Re: [PHP] Static utility class?
On Wed, Sep 4, 2013 at 12:25 PM, Micky Hulse mickyhulse.li...@gmail.comwrote: I want to have a utility class that contain utility methods which should have the option of being called multiple times on a page. ... To put it another way, is there any reason why I would not want to use the above code? The main problem caused by static methods is testability. Mocking or stubbing a static method requires using a PHP extension and ensuring that the original is reset whether the test passes or fails. As long as your utility methods don't perform actions you want to avoid during tests, this is fine. Good examples for a utility class are string-processing functions such as parsing and formatting, trimming and/or normalizing empty string to null, etc. You want tests to work against these methods directly since there's no need to avoid the work. You'll want to avoid static methods whenever you want to be able to fix the behavior (stubbing) to test scenarios in the class under test. An example is anything hitting a database or external service. In order to test that your downloader sends the correct warning email to the sysadmin when a REST call fails, you need to be able to force the REST call to fail. This is easy to do when you plug in an instance implementing the API because you can give it an implementation/mock that fails for all calls. I can't say if what you're thinking of will make a good utility class since the code you posted is fake. If you post some examples of methods you want to make static, we can give you pointers on which are good candidates and which are best left to instance methods. Peace, David
[PHP] Re: Permissions
Ethan Rosenberg wrote: Dear List - Tried to run the program, that we have been discussing, and received a 403 error. rosenberg:/var/www# ls -la StoreInventory.php -rwxrwxrw- 1 ethan ethan 4188 Aug 26 20:26 StoreInventory.php rosenberg:/var# ls -ld www drwxrwxrw- 37 ethan ethan 20480 Aug 26 20:26 www I had set the S bit [probably a nasty mistake] and I thought I was able to remove the bit. [it doesn't show above] How do I extricate myself from the hole into which I have planted myself? TIA Ethan This is in no way a php question, as the same result will happen no matter what you ask apache to serve from that directory. You have the directory permissions set to 776 not 777. -- Cheers David Robley Steal this tagline and I'll tie-dye your cat! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Permissions
Ashley Sheridan wrote: On Tue, 2013-08-27 at 16:16 +0930, David Robley wrote: Ethan Rosenberg wrote: Dear List - Tried to run the program, that we have been discussing, and received a 403 error. rosenberg:/var/www# ls -la StoreInventory.php -rwxrwxrw- 1 ethan ethan 4188 Aug 26 20:26 StoreInventory.php rosenberg:/var# ls -ld www drwxrwxrw- 37 ethan ethan 20480 Aug 26 20:26 www I had set the S bit [probably a nasty mistake] and I thought I was able to remove the bit. [it doesn't show above] How do I extricate myself from the hole into which I have planted myself? TIA Ethan This is in no way a php question, as the same result will happen no matter what you ask apache to serve from that directory. You have the directory permissions set to 776 not 777. -- Cheers David Robley Steal this tagline and I'll tie-dye your cat! 776 won't matter in the case of a directory, as the last bit is for the eXecute permissions, which aren't applicable to a directory. What I beg to differ here. If the x bit isn't set on a directory, that will prevent scanning of the directory; in this case apache will be prevented from scanning the directory and will return a 403. It's possible that this is an SELinux issue, which adds an extra layer of permissions over files. To see what those permissions are, use the -Z flag for ls. Also, check the SELinux logs (assuming that it's running and it is causing a problem) to see if it brings up anything. It's typically found on RedHat-based distros. Thanks, Ash http://www.ashleysheridan.co.uk -- Cheers David Robley Artificial Intelligence is no match for natural stupidity. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] exec and system do not work
Ethan Rosenberg wrote: On 08/26/2013 11:36 AM, ma...@behnke.biz wrote: Tamara Temple tamouse.li...@gmail.com hat am 26. August 2013 um 08:33 geschrieben: On Aug 25, 2013, at 10:41 PM, Ethan Rosenberg erosenb...@hygeiabiomedical.com wrote: Dear List - I'm lost on this one - This works - $out = system(ls -l ,$retvals); printf(%s, $out); This does - echo exec(ls -l); Please show the output of the directory listing. Please us ls -la This does not - if( !file_exists(/var/www/orders.txt)); { $out = system(touch /var/www/orders.txt, $ret); Maybe you don't have write permissions on the folder? $out2 = system(chmod 766 /var/www/orders.txt, $ret); echo 'file2br /'; echo file_exists(/var/www/orders.txt); } and this does not - if( !file_exists(/var/www/orders.txt)); { exec(touch /var/www/orders.txt); exec(chmod 766 /var/www/orders.txt); echo 'file2br /'; echo file_exists(/var/www/orders.txt); } Ethan When you say does not work, can you show what is actually not working? I believe the exec and system functions are likely working just fine, but that the commands you've passed to them may not be. -- Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel.: 0174 / 9722336 e-Mail: ma...@behnke.biz Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.biz Tamara - Please show the output of the directory listing. Please us ls -la echo exec('ls -la orders.txt'); -rw-rw-rw- 1 ethan ethan 43 Aug 25 23:50 orders.txt Maybe you don't have write permissions on the folder? If I perform the touch and chmod from the command line, everything works. When you say does not work, can you show what is actually not working? I believe the exec and system functions are likely working just fine, but that the commands you've passed to them may not be. Here are my commands. if( !file_exists(/var/www/orders.txt)); { echo system(touch /var/www/orders.txt, $ret); echo system(chmod 766 /var/www/orders.txt, $ret); echo 'file2br /'; echo file_exists(/var/www/orders.txt); } If I now try a ls from the command line, the return is cannot access /var/www/orders.txt: No such file or directory The ls -la works because the file was created from the command line. TIA Ethan Note that touch and chmod don't return any output, so echoing the result of a system call for those commands will give an empty string. You should be checking the values of $ret for each execution of system to see whether the command was successful or not - the return status of the executed command will be written to this variable. I'd guess that touch is returning 13 - permission denied. if( !file_exists(/var/www/orders.txt)) { system(touch /var/www/orders.txt, $ret1); echo 'touch returned '.$ret1.'br /'; system(chmod 766 /var/www/orders.txt, $ret2); echo 'chmod returned ' .$ret2.'br /'; echo 'file2br /'; echo file_exists(/var/www/orders.txt); } Check the permissions for directory /var/www; you'll probably find it is writable by the user you log on as, but not by the user that apache/php runs as, which is often www - a user with limited privileges. As other(s) have pointed out, there are php functions to do what you want without introducing the possible insecurities involved with system et al. -- Cheers David Robley Don't try to pull the wool over my eyes, Tom said sheepishly. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] exec and system do not work
Ethan Rosenberg, PhD wrote: Ethan Rosenberg, PhD /Pres/CEO/ *Hygeia Biomedical Research, Inc* 2 Cameo Ridge Road Monsey, NY 10952 T: 845 352-3908 F: 845 352-7566 erosenb...@hygeiabiomedical.com On 08/26/2013 07:33 PM, David Robley wrote: Ethan Rosenberg wrote: On 08/26/2013 11:36 AM, ma...@behnke.biz wrote: Tamara Temple tamouse.li...@gmail.com hat am 26. August 2013 um 08:33 geschrieben: On Aug 25, 2013, at 10:41 PM, Ethan Rosenberg erosenb...@hygeiabiomedical.com wrote: Dear List - I'm lost on this one - This works - $out = system(ls -l ,$retvals); printf(%s, $out); This does - echo exec(ls -l); Please show the output of the directory listing. Please us ls -la This does not - if( !file_exists(/var/www/orders.txt)); { $out = system(touch /var/www/orders.txt, $ret); Maybe you don't have write permissions on the folder? $out2 = system(chmod 766 /var/www/orders.txt, $ret); echo 'file2br /'; echo file_exists(/var/www/orders.txt); } and this does not - if( !file_exists(/var/www/orders.txt)); { exec(touch /var/www/orders.txt); exec(chmod 766 /var/www/orders.txt); echo 'file2br /'; echo file_exists(/var/www/orders.txt); } Ethan When you say does not work, can you show what is actually not working? I believe the exec and system functions are likely working just fine, but that the commands you've passed to them may not be. -- Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel.: 0174 / 9722336 e-Mail: ma...@behnke.biz Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.biz Tamara - Please show the output of the directory listing. Please us ls -la echo exec('ls -la orders.txt'); -rw-rw-rw- 1 ethan ethan 43 Aug 25 23:50 orders.txt Maybe you don't have write permissions on the folder? If I perform the touch and chmod from the command line, everything works. When you say does not work, can you show what is actually not working? I believe the exec and system functions are likely working just fine, but that the commands you've passed to them may not be. Here are my commands. if( !file_exists(/var/www/orders.txt)); { echo system(touch /var/www/orders.txt, $ret); echo system(chmod 766 /var/www/orders.txt, $ret); echo 'file2br /'; echo file_exists(/var/www/orders.txt); } If I now try a ls from the command line, the return is cannot access /var/www/orders.txt: No such file or directory The ls -la works because the file was created from the command line. TIA Ethan Note that touch and chmod don't return any output, so echoing the result of a system call for those commands will give an empty string. You should be checking the values of $ret for each execution of system to see whether the command was successful or not - the return status of the executed command will be written to this variable. I'd guess that touch is returning 13 - permission denied. if( !file_exists(/var/www/orders.txt)) { system(touch /var/www/orders.txt, $ret1); echo 'touch returned '.$ret1.'br /'; system(chmod 766 /var/www/orders.txt, $ret2); echo 'chmod returned ' .$ret2.'br /'; echo 'file2br /'; echo file_exists(/var/www/orders.txt); } Check the permissions for directory /var/www; you'll probably find it is writable by the user you log on as, but not by the user that apache/php runs as, which is often www - a user with limited privileges. As other(s) have pointed out, there are php functions to do what you want without introducing the possible insecurities involved with system et al. David - touch returned 1 /chmod returned 1 Non-zero return value indicates an error; touch failed and as a result there is no file to chmod, hence chmod also failed. rosenberg:/var/www# ls orders.txt ls: cannot access orders.txt: No such file or directory rosenberg:/var# ls -ld www drwxr-xr-x 37 ethan ethan 20480 Aug 26 20:15 www /var/www is only writeable by the user ethan -- Cheers David Robley INTERLACE: To tie two boots together. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP vs JAVA
On Thu, Aug 22, 2013 at 12:29 AM, Sebastian Krebs krebs@gmail.comwrote: Actually I think .. is quite error-prone, because it is hard to distinguish from . or _ on the _first_ glance, which makes the get quickly through the code. [1] I surround all operators except member access (. and -) with spaces, so that wouldn't be a problem for me. I thought there was an older language that used .., but all I can find now is Lua which was developed in the early nineties. So . is maybe not the best choice, but also remember when it was introduced: That was decades ago. That time it was (probably ;)) the best choice and nowadays I don't think it is too bad at all, beside that _other_ languages use it for other purposes now ;) C introduced . as the field access operator for structs in the early seventies, C++ kept it for object access, and Java adopted it in the early nineties. C's use of pointers required a way to access members through a pointer, and I suppose KR thought - looked like following a pointer (I agree). Since PHP was modeled on Perl and wouldn't implement objects or structs for another decade, it adopted . for string concatenation. It works fine, and I don't have too much trouble bouncing back-and-forth. I honestly would have preferred . to be overloaded when the left hand side was an object. In the rare cases that you want to convert an object to a string to be concatenated with the RHS, you can always cast it to string, use strval(), or call __toString() manually. But I'm not staging any protests over the use of -. :) Eclipse' code-completion and debugger never worked for me well (and most of the time: at all). It became slower and less responsive with every release. That was the reason I decided to leave it and I don't regret it :) I agree about the slowness, and until this latest release I've always left autocompletion manual (ctrl + space). They did something with Kepler to speed it up drastically, so much so I have it turned on with every keypress. However, it's a little too aggressive in providing choices. Typing null which is a Java keyword as in PHP, it will insert nullValue() which is a method from Hamcrest. :( After a couple weeks of this, I think I'll be switching it back to manual activation. I can type quickly enough that I only need it when I'm not sure of a method name. NetBeans, while not as good with refactoring and plugin support, is still zippier than Eclipse. And my short time with the JetBrains products found them to be fast as well. Eclipse's PHP support via PDT is not nearly as good as NetBeans, and no doubt PHPStorm beats them both. Peace, David
Re: [PHP] Re: PHP vs JAVA
On Wed, Aug 21, 2013 at 7:56 PM, Curtis Maurand cur...@maurand.com wrote: Sebastian Krebs wrote: Actually the problem is, that the dot . is already in use. With $foo.bar() you cannot tell, if you want to call the method bar() on the object $foo, or if you want to concatenate the value of $foo to the result of the function bar(). There is no other way around this than a different operator for method calls. I didn't think of that. It seems to me there could be an easier operator than - which sometimes will make me stop and look at what keys I'm trying to hit. Just a thought. I forgot about the concatenation operator which is + in Java/C# The PHP language developers were pretty stuck. Because of automatic string-to-numeric-conversion, they couldn't use + for string concatenation. Sadly, they chose . rather than .. which I believe one or two other languages use. If they had, . would have been available once objects rolled around in PHP 4/5. I suspect they chose - since that's used in C and C++ to dereference a pointer. Ever tried the jetbrains products? :D (No, they don't pay me) I have not, but it looks interesting. I'll have to try it. Those are very good products which have had a strong following for a decade. The free IDE NetBeans also has quite good support for both Java and PHP, and the latest beta version provides a web project that provides front- and back-end debugging of PHP + JavaScript. You can be stepping through JS code and hit an AJAX call and then seamlessly step through the PHP code that handles it. I use NetBeans for PHP/HTML/JS (though I am evaluating JetBrains' PHPStorm now) and Eclipse for Java. You can't beat Eclipse's refactoring support in a free tool, though I think NetBeans is close to catching up. I would bet IntelliJ IDEA for Java by JetBrains is on par at least. Peace, David
Re: [PHP] PHP vs JAVA
On Tue, Aug 20, 2013 at 10:43 AM, Tedd Sperling t...@sperling.com wrote: On Aug 20, 2013, at 10:36 AM, Liam l...@3sharpltd.com wrote: You do realise you are on a PHP based user subscription, so the vast majority will go with PHP, so you will get a one sided argument. Regards, Liam I realize that many, maybe the majority, will be bias. HOWEVER -- there are professionals on this list that do know and it is to them I am asking. Remember, I am also asking for supporting documentation of their view. The people who respond with just their opinion are doing just that -- there is no support. My nature is to seek the truth regardless of my bias. Cheers, tedd ___ tedd sperling t...@sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP vs JAVA
On Tue, Aug 20, 2013 at 10:56 AM, David OBrien dgobr...@gmail.com wrote: On Tue, Aug 20, 2013 at 10:43 AM, Tedd Sperling t...@sperling.com wrote: On Aug 20, 2013, at 10:36 AM, Liam l...@3sharpltd.com wrote: You do realise you are on a PHP based user subscription, so the vast majority will go with PHP, so you will get a one sided argument. Regards, Liam I realize that many, maybe the majority, will be bias. HOWEVER -- there are professionals on this list that do know and it is to them I am asking. Remember, I am also asking for supporting documentation of their view. The people who respond with just their opinion are doing just that -- there is no support. My nature is to seek the truth regardless of my bias. Cheers, tedd ___ tedd sperling t...@sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php If your looking for popularity... http://w3techs.com/technologies/overview/programming_language/all
[PHP] Re: How to upstream code changes to php community
Shahina Rabbani wrote: Hi, I have done some modifications to the php source code and i tested it with php bench and I observed some improvement. I wanted to upstream these code changes to PHP community. I searched the wed but i didnt find proper guide to upstream the code to php. Please help me by providing the information how to upstream my code changes to php source code community. Thanks, Shahina Rabbani Start with https://github.com/php/php- src/blob/master/README.SUBMITTING_PATCH which is linked from the Community menu item on the PHP home page. -- Cheers David Robley Enter any 11-digit prime number to continue... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP5 OOP: Abstract classes, multiple inheritance and constructors
There's no way to bypass an overridden method using parent, but you could add an abstract method that Child would implement. class Parent function __construct() { $this-foo = $this-getFoo(); } abstract function getFoo(); } David
Re: [PHP] What is the name of the pattern that will ...
Hi Richard, On Thu, Jun 13, 2013 at 10:16 AM, Richard Quadling rquadl...@gmail.comwrote: I'm building a class which needs to have certain methods called by the subclass, but the subclass can extend but not obscure/override the behaviour. This is the Template Method pattern, though in this case you could use a Strategy where the specific authentication implementation is in a separate class that gets injected into the Auth class. As for your example there a a few things I would change. * The template method that the subclass must implement should not be declared by an interface. Interfaces are for declaring public contracts. You can simply declare an abstract, protected method in Auth. This is the contract that every subclass must fulfill. * I would avoid reference variables as you've indicated. If you don't want to build a data-holder class yet, simply return an array for now. While you cannot enforce the return type at parse time, they should be verified with unit tests. Unit tests are critical with dynamic languages like PHP and Python since runtime is the only way to verify behavior. Otherwise, your example is spot on, though the name AuthRequestMade implies the request has already been made yet I think from your description that this method should *make* the actual request. Here's how I would write it with the above in place. class Auth { public function MakeAuthRequest() { // before $this-MakeAuthRequestImpl(); // Adding Impl suffix is a common convention // after } /** * Make the actual authentication request. * * @return array Must contain keys state and message to hold the result */ protected abstract function MakeAuthRequestImpl(); } Peace, David
Re: [PHP] Binding object instances to static closures
On Fri, May 31, 2013 at 10:54 AM, Nathaniel Higgins n...@nath.is wrote: Is it possible to bind an instance to a static closure, or to create a non-static closure inside of a static class method? PHP doesn't have a method to do this. In JavaScript you can use jQuery's var func = $.proxy(function () { ... }, object); In fact, you cannot use $this inside a closure at all (unless 5.4 has added a way that I haven't seen yet). You can get around that by declaring a local variable to hold a reference to the instance to use with use. It looks strange here because you're also passing in $testInstance for the comparison. ?php class TestClass { public static function testMethod() { $testInstance = new TestClass(); $closure = $testInstance-createClosure($testInstance); call_user_func($closure); // should be true } private function createClosure($testInstance) { $self = $this; return function() use ($self, $testInstance) { return $self === $testInstance; } } } TestClass::testMethod(); Peace, David
Re: [PHP] Binding object instances to static closures
Thanks Nathaniel for the clarification about 5.4. We are still on 5.3 (and that only recently), so 5.4 is a ways off in our production systems. However, I'll read up on this since it may be useful in offline tools. On Fri, May 31, 2013 at 11:52 AM, Nick Whiting nwhit...@xstudiosinc.comwrote: TestClass::testMethod(function($param){ var_dump($this === $param); }); I get why closures created inside static methods cannot be bound to an instance . . . but those created *outside* an object method entirely *can* be bound? That makes no sense! And yet it works. David
[PHP] Re: Include/Require limit?
Julian Wanke wrote: Hi, I use the pretty large Library PHP Image Workshop (http://phpimageworkshop.com/) at my project. It is about 75,5 KB. Everything works fine but if I try to include a 15 KB file with country codes, it fails. With the other files I easily get over 100 KB inclusion size, so my question; Is there a size limitation for include? Best regards Do you get an error message? Try removing the header() in the image output and see what happens. -- Cheers David Robley PARANOID:Paying MORE for Surge-Protectors than Computers -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: need some regex help to strip out // comments but not http:// urls
On Wed, May 29, 2013 at 10:20 AM, Matijn Woudt tijn...@gmail.com wrote: It is possible to write a whole parser as a single regex, being it terribly long and complex. While regular expressions are often used in the lexer--the part that scans the input stream and breaks it up into meaningful tokens like { keyword: function } { operator: + } and { identifier: $foo } that form the building blocks of the language--they aren't combined into a single expression. Instead, a lexer generator is used to build a state machine that switches the active expressions to check based on the previous tokens and context. Each expression recognizes a different type of token, and many times these aren't even regular expressions. The second stage--combining tokens based on the rules of the grammar--is more complex and beyond the abilities of regular expressions. There are plenty of books on the subject and tools [1] to build the pieces such as Lex, Yacc, Flex, and Bison. Someone even asked this question on Stack Overflow [2] a few years ago. And I'm sure if you look you can find someone that did a masters thesis proving that regular expressions cannot handle a context-free grammar. And finally I leave you with Jeff Atwood's article about (not) parsing HTML with regex. [3] Peace, David [1] http://dinosaur.compilertools.net/ [2] http://stackoverflow.com/questions/3487089/are-regular-expressions-used-to-build-parsers [3] http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
Re: [PHP] need some regex help to strip out // comments but not http:// urls
Hi Daevid, On Tue, May 28, 2013 at 2:17 PM, Daevid Vincent dae...@daevid.com wrote: I'm adding some minification to our cache.class.php . . . We have been using a native jsmin extension [1] which does a lot more without any trouble for over two years now. It's much faster than the equivalent PHP solution and is probably tested by a lot more people than a home-grown version. You might want to check it out before going too far down this path. Good luck, David [1] http://www.ypass.net/software/php_jsmin/
Re: [PHP] need some regex help to strip out // comments but not http:// urls
Hi Daevid, On Tue, May 28, 2013 at 2:40 PM, Daevid Vincent dae...@daevid.com wrote: I appreciate the pointer, but our files, like many people, is a mixture of HTML, PHP and JS in one file. This jsmin appears to only work on .js files right? Also, everything else works great in our minifing method, just this edge case. My bad. We moved all our JS and CSS to external files for this very reason and created a plugin to combine and minify everything needed by each page into a unique file. While it does cause some duplication across pages, it means that every page loads exactly one JS and CSS file each. For your situation, I don't know a regular expression that will work in all cases. David
[PHP] Re: Doing something wrong?
Lester Caine wrote: I've got a new machine set up with SUSE12.3 but while it has PHP5.4, Apache is still stuck at 2.2, so I've downloaded and built 2.4.4 and PHP5.4.15 along with the modules I need but I'm having trouble actually getting it to load the 'Additional' .ini files. phpinfo is showing the change of location of the php.ini file, but nothing for the 'Scan this dir for additional .ini files' while the Configure shows '--with-config-file-scan-dir=/opt/apache2/conf/php5.d' What am I missing? It's working on the other machines and loading all the extra modules happily. Did you make clean after reconfiguring before re-compiling php? According to https://bugs.php.net/bug.php?id=63611 that may be a cause. -- Cheers David Robley An ulcer is what you get mountain climbing over molehills. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about session_id() and session_start()
On Mon, May 20, 2013 at 4:14 PM, Tim Schofield t...@weberpafrica.com wrote: Matijn There are well over half a million lines of source code in PHP. It seems a little unhelpful to tell someone to go and read half a million lines of C when you could just tell them the answer? Thanks Tim Course View Towers, Plot 21 Yusuf Lule Road, Kampala T +256 (0) 312 314 418 M +256 (0) 752 963 325 www.weberpafrica.com Twitter: @TimSchofield2 Blog: http://weberpafrica.blogspot.co.uk On May 20, 2013 6:24 PM, Matijn Woudt tijn...@gmail.com wrote: On Mon, May 20, 2013 at 5:33 AM, 孟远涛 yuantao.m...@gmail.com wrote: I find the Note in PHP document. http://www.php.net/manual/en/function.session-id.php Note: When using session cookies, specifying an id for session_id() will always send a new cookie when session_start() is called, regardless if the current session id is identical to the one being set. I feel puzzled about this feature. Even if the current session id is identical to the one one being set, session_start will send a new cookie. I want to know why session_start behave in this way. Forgive my poor English. Thanks in advance. You will find the answer in the PHP source code. If you don't want this to happen, check if the current session id matches with the value you want to set it to, and don't set if they match. - Matijn I guess it would be to help prevent session hijacks like explained here http://stackoverflow.com/questions/12233406/preventing-session-hijacking
Re: [PHP] Question about session_id() and session_start()
On May 20, 2013 8:45 PM, Matijn Woudt tijn...@gmail.com wrote: On Mon, May 20, 2013 at 10:46 PM, David OBrien dgobr...@gmail.com wrote: On Mon, May 20, 2013 at 4:14 PM, Tim Schofield t...@weberpafrica.com wrote: Matijn There are well over half a million lines of source code in PHP. It seems a little unhelpful to tell someone to go and read half a million lines of C when you could just tell them the answer? Thanks Tim Course View Towers, Plot 21 Yusuf Lule Road, Kampala T +256 (0) 312 314 418 M +256 (0) 752 963 325 www.weberpafrica.com Twitter: @TimSchofield2 Blog: http://weberpafrica.blogspot.co.uk On May 20, 2013 6:24 PM, Matijn Woudt tijn...@gmail.com wrote: On Mon, May 20, 2013 at 5:33 AM, 孟远涛 yuantao.m...@gmail.com wrote: I find the Note in PHP document. http://www.php.net/manual/en/function.session-id.php Note: When using session cookies, specifying an id for session_id() will always send a new cookie when session_start() is called, regardless if the current session id is identical to the one being set. I feel puzzled about this feature. Even if the current session id is identical to the one one being set, session_start will send a new cookie. I want to know why session_start behave in this way. Forgive my poor English. Thanks in advance. You will find the answer in the PHP source code. If you don't want this to happen, check if the current session id matches with the value you want to set it to, and don't set if they match. - Matijn I guess it would be to help prevent session hijacks like explained here http://stackoverflow.com/questions/12233406/preventing-session-hijacking How would it help preventing session hijacking if it was sending the a new cookie with the same session id? - Matijn I was thinking if I was sitting in a cafe and someone was sniffing and tried to use my session info they would get a new session id where I would still have my original one so they wouldn't be able to hijack mine trying to reuse the same id I have since php would generate a new one No?
Re: [PHP] A Good OOP Tutorial/Read?
On Fri, May 17, 2013 at 7:04 AM, Tedd Sperling tedd.sperl...@gmail.comwrote: To me there is no difference between an abstract class (without method declarations) and an interface. The key difference in OO languages that do not allow multiple inheritance is that you can always add an interface to an existing class but you can only mix in an abstract class if your class doesn't extend another. Let's say you want to define the contract for a UserDataAccessObject with query and CRUD methods. If you make it an abstract class, I cannot implement that contract using my AbstractMysqlDao base class. With an interface, I can do class MysqlUserDao extends AbstractMysqlDao implements UserDataAccessObject Being a dynamic language, PHP allows you to fulfill a contract without using interfaces at all. You can call findUserByLogin() on any object--even those that don't declare that interface via __call(). However, you won't be able to pass your objects to methods that use parameter type hinting. This is where interfaces really shine, and they become more important as your project grows in complexity. They are certainly *not* required to make good use of OOP, especially in PHP/Python/Ruby. However, I view an interface as a statement (a contract) where IF you want someone to use your code you outline the methods you require them to flesh-out in their code -- but I would like to see a simple example of that. Interfaces come in handy when implementing the visitor and observer patterns. Simple example are always contrived, but here's mine: interface Engine { function orderFuel(Store $store); function setSpeed($mph); } class SteamEngine implements Engine { function orderFuel(Store $store) { $store-order('coal', 1000, WeightUnit::POUND); } function setSpeed($mph) { if ($mph = 80) { throw new InvalidArgumentException('Cannot exceed 80mph'); } $this-loadFuel(...); } } class MrFusion implements Engine { function orderFuel(Store $store) { $store-order('aluminum can'); $store-order('banana peel'); } function setSpeed($mph) { if ($mph = 88 empty($this-destinationTime)) { throw new IllegalStateException('Must set desired time travel destination'); } $this-adjustThrottle($mph - $this-speed); } } You could make Engine an abstract class, but that would reduce your users' choice. David
Re: [PHP]
On Wed, May 8, 2013 at 1:22 PM, Daniel Brown danbr...@php.net wrote: On Wed, May 8, 2013 at 1:14 PM, Tedd Sperling tedd.sperl...@gmail.com wrote: PS: PHP + Produced by Horses Ponies. ? You got too much time on your hands Daniel. And yes, I just made up the word acronymize. That would be reverse acronymization :)
Re: [PHP] ODBC
On Mon, May 6, 2013 at 3:32 PM, georg georg.chamb...@telia.com wrote: Hi, Id like to get ODBC connection to SQL from PHP going. Ive done that on XP, but now Im switching to Linux (Fedora). My impression in that the connecting part is per the DB designers responsibility. Im using Mimer-SQL, but cant find any information on how to set up ODBC for that. Any advice welcome. BR georg http://developer.mimer.com/howto/howto_57.htm
Re: [PHP] Updated PHP breaks processing-intense Procedure
On Wed, Apr 24, 2013 at 5:09 PM, Ken Kixmoeller phph...@comcast.net wrote: Hey - -- I have a huge screen -- to make it simple for the user, it does 100s of calls to MySQL and has 1,000s (literally) of POST variables. We have done extensive research and see that upgrading from php 5.1.6-27 to 5.1.6-39 is the thing that caused it to break. All other issues (Apache, PHP and MySQL configuration and Versions) have been methodically ruled out. Anybody experience this? Heard of it? Suggest a repair (other than changing my screen)? *** Please don't tell me to redesign the screen -- this may come, but now is an urgent situation.*** Worked fine in prior versions for the last 3 years. Thanks, Ken Looks like they fixed the bug that allowed that to work... php-common-5.1.6-32.el5.x86_64http://linuxsoft.cern.ch/cern/slc5X/x86_64/yum/updates/php-common-5.1.6-32.el5.x86_64.rpm [153 KiB]*Changelog* by Joe Orton (2012-02-02): - add security fix for CVE-2012-0830 (#786756) http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-0830
Re: [PHP] Updated PHP breaks processing-intense Procedure
On Wed, Apr 24, 2013 at 5:14 PM, David OBrien dgobr...@gmail.com wrote: On Wed, Apr 24, 2013 at 5:09 PM, Ken Kixmoeller phph...@comcast.netwrote: Hey - -- I have a huge screen -- to make it simple for the user, it does 100s of calls to MySQL and has 1,000s (literally) of POST variables. We have done extensive research and see that upgrading from php 5.1.6-27 to 5.1.6-39 is the thing that caused it to break. All other issues (Apache, PHP and MySQL configuration and Versions) have been methodically ruled out. Anybody experience this? Heard of it? Suggest a repair (other than changing my screen)? *** Please don't tell me to redesign the screen -- this may come, but now is an urgent situation.*** Worked fine in prior versions for the last 3 years. Thanks, Ken Looks like they fixed the bug that allowed that to work... php-common-5.1.6-32.el5.x86_64http://linuxsoft.cern.ch/cern/slc5X/x86_64/yum/updates/php-common-5.1.6-32.el5.x86_64.rpm [153 KiB] *Changelog* by Joe Orton (2012-02-02): - add security fix for CVE-2012-0830 (#786756) http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-0830 *I looked around google some more and found there is a hard limit of 1000 post variables in 5.1.6* After weeks of using it, a problem was reported about just one function of the app that would sometimes return a blank screen. It took me hours of debugging (read: echo) to figure out what's going on, digging through some old PHP code (fun!): It appeared that only 1000 post variables arrived on the server. (Well, 1006 actually, but 2 were added by PHP, and that sounded like a PHP-style limitation of 1000.) A quick google lookup revealed that PHP introduced a new feature where it would limit the number of post variables. For safety reasons. The variable is called max_input_vars with a default of 1000. PHP states that this feature was introduced in 5.3.9, but I'm running 5.1.6 and the limit is enforced. Because the server is for production, it was running with on-screen warnings turned off. PHP says that it prints a warning and cuts. For me, that's a real WTF. A post request should be processed as all-or-nothing. It should instead refuse the request completely. But for a technology named personal home page the priorities are different.
Re: [PHP] mysql_connect noob question
Not meaning to beat the proverbial dead horse I am developing a web portal that has to display the tables in the DB via a form/script. The web page has a login with user and password. Right now I am just trying to connect. This for a commercial app - the client wants both an API connect via PHP and a web portal in which they can login from a web page and view the tables in the DB. Right now I am just trying to get the form/PHP interaction to work. This sounds like a very good use statement for http://www.phpmyadmin.net/http://www.phpmyadmin.net/home_page/ You can set it for http auth in the config ... they enter a mysql username and password and they only see the databases and tables you want them to see Might be easier than reinventing the wheel and stressing all of us :)
Re: [PHP] mysql_connect noob question
On Sun, Apr 21, 2013 at 6:01 PM, Glob Design Info i...@globdesign.comwrote: One other thing I noted in the FAQ was this: Dots in incoming variable names Typically, PHP does not alter the names of variables when they are passed into a script. However, it should be noted that the dot (period, full stop) is not a valid character in a PHP variable name. For the reason, look at it: ?php $varname.ext; /* invalid variable name */ ? Now, what the parser sees is a variable named $varname, followed by the string concatenation operator, followed by the barestring (i.e. unquoted string which doesn't match any known key or reserved words) 'ext'. Obviously, this doesn't have the intended result. For this reason, it is important to note that PHP will automatically replace any dots in incoming variable names with underscores. I should note my user name in this case *is* an email address, however the dots in that address are *not* being converted to underscores as mentioned (at least not visibly). it's says variable NAMES not variable contents
Re: [PHP] mysql_connect noob question
I should note my user name in this case *is* an email address, however the dots in that address are *not* being converted to underscores as mentioned (at least not visibly). I just created a free account there and the email says my username is dgobr...@gmail.com but I connected to it from sqlyog and a php page by using JUST dgobrien ?php $host = instance44364.db.xeround.com:3924; if ( $_REQUEST['Submit'] ) { $conn = mysql_connect( $host, $_REQUEST['username'], $_REQUEST['password'] ) or die( mysql_error() ); if ($conn) { mysql_select_db(uwharrie) or die( mysql_error() ); echo Connectedbr; } } ?form id='login' action='index.php' method='post' accept-charset='UTF-8' legendLogin/legend input type='hidden' name='submitted' id='submitted' value='1'/ label for='username' UserName*:/label input type='text' name='username' id='username' value='dgobrien' maxlength=50 / label for='password' Password*:/label input type='password' name='password' id='password' maxlength=50 value='mm' / input type='submit' name='Submit' value='Submit' / /form
Re: [PHP] mysql_connect noob question
In fact using the @gmail.com part added on gives me the same error as the OP I think their welcome email needs tweaking.. try it without the domain added on On Sun, Apr 21, 2013 at 6:56 PM, David OBrien dgobr...@gmail.com wrote: I should note my user name in this case *is* an email address, however the dots in that address are *not* being converted to underscores as mentioned (at least not visibly). I just created a free account there and the email says my username is dgobr...@gmail.com but I connected to it from sqlyog and a php page by using JUST dgobrien ?php $host = instance44364.db.xeround.com:3924; if ( $_REQUEST['Submit'] ) { $conn = mysql_connect( $host, $_REQUEST['username'], $_REQUEST['password'] ) or die( mysql_error() ); if ($conn) { mysql_select_db(uwharrie) or die( mysql_error() ); echo Connectedbr; } } ?form id='login' action='index.php' method='post' accept-charset='UTF-8' legendLogin/legend input type='hidden' name='submitted' id='submitted' value='1'/ label for='username' UserName*:/label input type='text' name='username' id='username' value='dgobrien' maxlength=50 / label for='password' Password*:/label input type='password' name='password' id='password' maxlength=50 value='mm' / input type='submit' name='Submit' value='Submit' / /form
Re: [PHP] Re: mysql_connect noob question
Glob Design Info wrote: On 4/21/13 3:27 PM, Stuart Dallas wrote: On 21 Apr 2013, at 20:29, Glob Design Info i...@globdesign.com wrote: If that is the case then why does logging in with exactly the same params from a UNIX shell work fine? Command line login supposedly would be adding the @localhost or @IP_address as well but isn't. Only when I pass the variables to the script is that happening. What makes you so sure it's not? It is. I promise you it is. You're not seeing it because you're not getting an error logging in. Do it on the command line again, but use a username that doesn't exist and you will see the host it's adding in the error message. Indeed you are correct: Last login: Sun Apr 21 15:41:10 on ttys000 iMac-333:~ glob$ sudo mysql --host=instance43490.db.xeround.com --port=8904 --user=fakeuser --password=somepassword Password: Warning: Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'fakeuser'@'ip70-162-142-180.ph.ph.cox.net' (using password: YES) iMac-333:~ glob$ I am doing exactly as you stated: mysql_connect('localhost', $_POST['username'], $_POST['password']); Except that I am first storing $_POST['username'] in local $user and $_POST['password'] in local $pass first and then passing those to mysql_connect. And I am connecting to a remote server, not localhost. Side note: why are you putting them in other variables first when you're only going to use them in that one place? It's a waste of memory. It's a minor niggle but it's a pet hate of mine. I am using them in other places - printing them on the response page to see their values/show the user who logged in, etc. I have already documented both the exact HTML and PHP code in this thread and so see no need to post it elsewhere. And you're saying that when, instead of using $_POST variables you hard-code the username and password in the script it work? I doubt it. I can assure you it does. However, I may have found the problem: the port. As a security measure the BaaS provider appears to have changed MySQL to a non-standard port. So On the command line: sudo mysql --host=instance43490.db.xeround.com --port=8904 --user=realuser --password=realpass WORKS perfectly - entering the MySQL Monitor. However, on the same host, same command line: sudo mysql --host=instance43490.db.xeround.com:8904 --user=realuser --password=realpass Does NOT work - returning an error that the host is not found. So it appears to be the port, which begs the obvious question: is there a way to tell mysql_connect() to use a different port? Yes - please see the documentation page for mysql_connect, in particular the Server parameters part. SNIP I assume you have taken notice of the warnings in the documentation about deprecation of the mysql_ functions in favour of mysqli_ or PDO. -- Cheers David Robley Multitasking: Reading in the bathroom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect noob question
$form_user = $_POST[ 'user' ]; $form_pass = $_POST[ 'password' ]; # Connect to remote DB $LINK = mysql_connect( $host, $form_user, $form_pass ); And yes, my $host param is correct. Have you tried $LINK = mysql_connect( $host, $form_user, $form_pass ); just for the heck of it?
Re: [PHP] mysql_connect noob question
Glob Design Info wrote: Sorry. The error displayed is: *Warning*: mysql_connect() [function.mysql-connect http://localhost/wservices/function.mysql-connect]: Access denied for user 'user'@'ip70-162-142-180.ph.ph.cox.net' (using password: YES) in */Library/WebServer/Documents/wservices/connect.php* on line *29* (But with the real user name, not just 'user') Thanks, On 4/19/13 3:28 PM, tamouse mailing lists wrote: On Fri, Apr 19, 2013 at 3:43 PM, Glob Design Info i...@globdesign.com wrote: I know this has probably been answered already. When I pass a user name and password from a form to my PHP script and then pass those to mysql_connect it doesn't connect. When I paste those exact same values into mysql_connect as string literals it works. Can anyone tell me why this happens? I know the strings are identical to the literals I try in a test but they don't work when submitted via form. $form_user = $_POST[ 'user' ]; $form_pass = $_POST[ 'password' ]; # Connect to remote DB $LINK = mysql_connect( $host, $form_user, $form_pass ); Please show the error you are getting from the mysql_connect And yes, my $host param is correct. Thanks, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php First guess is that you don't have privileges for 'user'@'ip70-162-142-180.ph.ph.cox.net', but you may have privileges for 'user'. And, what are you using for the $host value? If the script and mysql are on the same server, it shouldn't need to be anything other than 'localhost'. -- Cheers David Robley A man's best friend is his dogma. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need a tool to minimize HTML before storing in memecache
On Wed, Apr 17, 2013 at 5:52 PM, Daevid Vincent dae...@daevid.com wrote: We do a lot with caching and storing in memecached as well as local copies so as to not hit the cache pool over the network and we have found some great tools to minimize our javascript and our css, and now we'd like to compress our HTML in these cache slabs. Anyone know of a good tool or even regex magic that I can call from PHP to compress/minimize the giant string web page before I store it in the cache? It's not quite as simple as stripping white space b/c obviously there are spaces between attributes in tags that need to be preserved, but also in the words/text on the page. I could strip out newlines I suppose, but then do I run into any issues in other ways? In any event, it seems like someone would have solved this by now before I go re-inventing the wheel. d. I used this a while ago to do what you are asking... I modified it to my needs https://github.com/stevenvachon/html-minify/
Re: [PHP] Re: Is BBCode Installed
Hi Stephen, I just tried installing the PECL extension, but it failed to build on PHP 5.4.6-1ubuntu1.2. I see Xdebug in the phpinfo output, and I assume other PECL extensions will show up there once installed. Good luck! David
[PHP] Re: Is BBCode Installed
Stephen wrote: I ran phpinfo() on my host and searched for BBCode. Not found. Does this mean that the extension is not installed? If not, how can I tell? Thanks BBCode isn't a php extension, but may be implemented using php or other languages. See http://www.bbcode.org/ for more info. -- Cheers David Robley Some people are afraid of heights. I'm afraid of widths -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Is BBCode Installed
Stephen wrote: On 13-04-10 10:59 PM, David Robley wrote: I ran phpinfo() on my host and searched for BBCode. Not found. Does this mean that the extension is not installed? If not, how can I tell? Thanks BBCode isn't a php extension, but may be implemented using php or other languages. See http://www.bbcode.org/ for more info. Thank you for replying, but: http://php.net/manual/en/book.bbcode.php Introduction This extension aims to help parse BBCode text in order to convert it to HTML or another markup language. It uses one pass parsing and provides great speed improvement over the common approach based on regular expressions. Further more, it helps provide valid HTML by reordering open / close tags and by automatically closing unclosed tags. That appears to be a PECL extension, not 'core' php and more info on installing can be found at http://www.php.net/manual/en/install.pecl.php. Not having used PECL extensions, I can't say whether they are reflected in phpinfo() output. -- Cheers David Robley SCUD : Sure Could Use Directions -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is there a PHP based authentication library?
On Mon, Apr 1, 2013 at 5:26 PM, Mark mark...@gmail.com wrote: Hi, I stumbled upon this payment library: http://ci-merchant.org/ which abstracts the different payment backends away and exposes a new easy to use interface for the app developer to use. Thus making it very easy to use different payment providers. I was wondering if something like that is also existing for authentication? For example, in authentication you have quite a few different ones: - Mozilla Persona - openid - facebook connect - google (openid?) - use/pass based authentication (a.k.a. the self made version that every dev begins with) - oauth - twitter connect - etc... Is there such a library in existence? I'm especially looking for one with mozilla persona implemented. Kind regards, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php https://github.com/openid/php-openid
Re: [PHP] application level variable file
On Fri, Mar 22, 2013 at 10:26 AM, Stuart Dallas stu...@3ft9.com wrote: On 22 Mar 2013, at 14:22, inu...@gmail.com wrote: I am very new to the PHP application and would like to create a new project. I would like to have a file to save my application level variable and functions. I would like to know does PHP have any default file name and file path for this file like Web.config file for ASP.Net and Application.cfm for ColdFusion? You can in the php.ini file use this http://php.net/manual/en/ini.core.php#ini.auto-prepend-file *auto_prepend_file* stringhttp://www.php.net/manual/en/language.types.string.php Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the requirehttp://www.php.net/manual/en/function.require.php function, so include_path http://www.php.net/manual/en/ini.core.php#ini.include-path is used. The special value *none* disables auto-prepending.
Re: [PHP] actually HTML again; resizeing images
On Mar 17, 2013 12:28 PM, Stuart Dallas stu...@3ft9.com wrote: On 17 Mar 2013, at 13:22, georg georg.chamb...@telia.com wrote: Anyone knows a good reading about how and when images displayd with HTML tags are re-sized ? Not entirely sure what you mean, but a downloaded image will be resized when it needs to be shown in different dimensions to the actual image, whether that's due to width and height attributes on an img tag, or CSS styles, or whatever. The specific algorithm used (which I'm guessing is what you mean by how is up to the browser and cannot be controlled. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Unless you use something like treesaver
[PHP] php gd extension with cPanel
Hello, I'm hoping there's an easy fix for this. I've got a centos server machine 6.4 I believe with cPanel running on it. I need to enable the gd extension, both the gd and gd-devel rpm packages are installed, but php is not, that is showing up in a package list. It is however installed as it's gone through cPanel. It does not however have the php-gd extension. I am wondering if there's an easy way to get this extension working? I do not want to have to recompile the whole php to do this. Thanks. Dave. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone ang...@italian-getaways.comwrote: I ran across if(array_key_exists) and it seems to work. How does that differ from if(isset($states[$state]))? Hi Angela, isset() will return false for an array key 'foo' mapped to a null value whereas array_key_exists() will return true. The latter asks Is this key in the array? whereas isset() adds and is its value not null? While isset() is every-so-slightly faster, this should not be a concern. Use whichever makes sense for the context here. Since you don't stick null values into the array, I prefer the isset() form because the syntax reads better to me. Peace, David
Re: FW: [PHP] Accessing Files Outside the Web Root
Dale H. Cook wrote: At 05:04 PM 3/13/2013, Dan McCullough wrote : Web bots can ignore the robots.txt file, most scrapers would. and at 05:06 PM 3/13/2013, Marc Guay wrote: These don't sound like robots that would respect a txt file to me. Dan and Marc are correct. Although I used the terms spiders and pirates I believe that the correct term, as employed by Dan, is scrapers, and that twerm might be applied to either the robot or the site which displays its results. One blogger has called scrapers the arterial plaque of the Internet. I need to implement a solution that allows humans to access my files but prevents scrapers from accessing them. I will undoubtedly have to implement some type of challenge-and-response in the system (such as a captcha), but as long as those files are stored below the web root a scraper that has a valid URL can probably grab them. That is part of what the public in public_html implies. One of the reasons why this irks me is that the scrapers are all commercial sites, but they haven't offered me a piece of the action for the use of my files. My domain is an entirely non-commercial domain, and I provide free hosting for other non-commercial genealogical works, primarily pages that are part of the USGenWeb Project, which is perhaps the largest of all non-commercial genealogical projects. readfile() is probably where you want to start, in conjunction with a captcha or similar -- Cheers David Robley Catholic (n.) A cat with a drinking problem. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
On Wed, Mar 13, 2013 at 5:10 PM, Sebastian Krebs krebs@gmail.comwrote: Because 'null' is the representation of nothing array_key_exists() and isset() can be treated as semantically equivalent. As I said, these functions return different results for null values. It won't matter for Angela since she isn't storing null in the array, though. Peace, David
Re: [PHP] Mystery foreach error
Angela Barone wrote: I think I figured it out. ?php $states = array( 'AL' = array( '350','351','352','353', ), 'AK' = array( '995','996','997','998','999', ), 'AZ' = array( '850','851','852','853','854', ), 'WI' = array( '530','531','532', ), 'WY' = array( '820','821','822','823','824', ), ); $zip = 35261; $state = 'XX'; $zip_short = substr($zip, 0, 3); foreach ($states[$state] as $zip_prefix) { if ($zip_prefix == $zip_short) { echo State = $state; } else { echo 'no'; } } ? Running this script, I got the same error as before. If $state is a known state abbreviation in the array, everything is fine, but if someone was to enter, say 'XX' like I did above or leave it blank, then the error is produced. I placed an if statement around the foreach loop to test for that and I'll keep an eye on it. Thank you for getting me to look at the array again, which led me to look at the State. Angela Presumably there is a fixed list of State - those are US states? - so why not provide a drop down list of the possible choices? -- Cheers David Robley I need to be careful not to add too much water, Tom said with great concentration. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does Scope-Resolution Operator Always Follow 'parent'?
Hi Eric, On Sun, Mar 10, 2013 at 8:21 PM, Eric James Michael Ritz lobbyjo...@gmail.com wrote: I have a question about the `parent` keyword: is there any valid situation where it can appear without the `::` operator following? I wouldn't have thought it possible, but I just found one case with PHP 5.4 where it can appear as the keyword without a trailing ::. Apparently you can use it to instantiate the parent class just as you can with new self. class Foo { } class Bar extends Foo { public function foo() { return new parent; } } I think you'll be safe if you can highlight it only when preceded by new or followed by ::. David
Re: [PHP] Not counting my own page visits
Angela Barone wrote: On Mar 4, 2013, at 11:33 AM, Ashley Sheridan wrote: You can manually write a cookie on your machine, or use a special script that only you visit that contains a setcookie() call (it only need be set once). From there on, you can check the $_COOKIES super global for the presence of your cookie. I don't know why, but I can't get cookies to work. Here's a script I'm calling from my browser: ?php $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; $cookie = setcookie('test2', '123' , time()+60*60*24*30, '/', $domain); ? !DOCTYPE html html lang=en head meta charset=utf-8 / titleTest Page/title /head body ?php echo 'Cookie is: '.$_COOKIE[$cookie].br; ? ?php echo 'Domain is: '.$domain.br; ? /body /html The domain is being displayed but the cookie is not. There's no cookie in the browser prefs, either. What am I doing wrong? Angela Misunderstanding what $cookie contains? It is a boolean, i.e. it will be true or false depending on whether the cookie was set or not. To echo the contents of a cookie, you need to use the cookie name, viz ?php echo 'Cookie is: '.$_COOKIE['test2'].br; ? -- Cheers David Robley Oxymoron: Sisterly Love. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] parsing select multiple=multiple
tamouse mailing lists wrote: On Mon, Feb 18, 2013 at 6:54 PM, John Taylor-Johnston john.taylor-johns...@cegepsherbrooke.qc.ca wrote: I am capable with select name=DPRpriority. (I suppose I did it correctly? :p ) But I haven't the first clue how to parse a select multiple and multiply select name=DPRtype. Would anyone give me a couple of clues please? :) Thanks, John Priority: select name=DPRpriority form=DPRform option value=1 ?php if ($_POST[DPRpriority] == 1) {echo selected;} ?1/option option value=2 ?php if ($_POST[DPRpriority] == 2) {echo selected;} ?2/option option value=3 ?php if ($_POST[DPRpriority] == 3) {echo selected;} ?3/option option value=4 ?php if (empty($_POST[DPRpriority])) {echo selected;} if ($_POST[DPRpriority] == 4) {echo selected;} ?4/option /select select multiple=multiple name=DPRtype form=DPRform option value=1. Crimes Against Persons1. Crimes Against Persons/option option value=2. Disturbances2. Disturbances/option option value=3. Assistance / Medical3. Assistance / Medical/option option value=4. Crimes Against Property4. Crimes Against Property/option option value=5. Accidents / Traffic Problems5. Accidents / Traffic Problems/option option value=6. Suspicious Circumstances6. Suspicious Circumstances/option option value=7. Morality / Drugs7. Morality / Drugs/option option value=8. Miscellaneous Service8. Miscellaneous Service/option option value=9. Alarms9. Alarms/option /select -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Do test this, but I think all that's required is you make the name an array: select name=DPRpriority[] form=DPRform More info at http://www.php.net/manual/en/language.variables.external.php (search for multiple) and http://www.php.net/manual/en/faq.html.php#faq.html.select-multiple -- Cheers David Robley Know what I hate? I hate rhetorical questions! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Newbie is trying to set up OOP With PHP and MySQL or MySQLi database class (using CRUD)
dealTek wrote: Thanks for all the help folks, PHP-light-PDO-Class ok well I found this... https://github.com/poplax/PHP-light-PDO-Class But it does not seem to recognize the port - I put the port as 8889 but keeps saying can't connect port 3306 Warning: PDO::__construct() [pdo.--construct]: [2002] Connection refused (trying to connect via tcp://127.0.0.1:3306) in /Users/revdave/Sites/php-fool/pdo3/PHP-light-PDO-Class- master/class.lpdo.php on line 33 Connection failed: SQLSTATE[HY000] [2002] Connection refused BTW: I tried to add the port a few places but it didn't work.. How do we fix this? -- config.php ?php $config = array(); $config['Database'] = array(); $config['Database']['dbtype'] = 'mysql'; $config['Database']['dbname'] = 'tester'; $config['Database']['host'] = '127.0.0.1'; $config['Database']['port'] = 8889; $config['Database']['username'] = 'root'; $config['Database']['password'] = 'root'; $config['Database']['charset'] = 'utf8'; ? Change host to localhost - your mysql may be configured not to accept requests via tcp. === class.lpdo.php SNIP -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- Cheers David Robley My karma ran over my dogma -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Late static binding behaves differently in PHP 5.3 and PHP 5.4
Hi Keven, First, I don't see any late static binding being used here. LSB only applies when you access a static member using the static keyword within a class method. This code uses static properties but accesses them directly without going through class methods. Here's an example of LSB: class Foo { static $my_var = 'The Foo'; static function dump() { echo static::$my_var . \n;// Use Foo's or Bar's depending on what appears before ::dump() } } class Bar extends Foo { static $my_var = 'The Bar'; } Bar::dump();// The Bar Foo::dump();// The Foo Here Foo::dump() uses LSB to pick the source of $my_var. That being said, what you're seeing does look like a change (or bug) in how PHP accesses constants. Given that it is order-dependent, my guess is that 5.4 introduced a bug that causes Bar to push its constant up into Foo. The strange thing is that the constant is compiled into the class, and since Bar extends Foo I would expect Foo to be compiled first regardless of the order in which you access the static variable later. David
Re: [PHP] Boolean type forced on string assignment inside if statement
On Thu, Jan 3, 2013 at 11:49 AM, Marc Guay marc.g...@gmail.com wrote: Hi John, I just ran this: if (($a = foo) || ($b = bar)){ echo $a.br /.$b; } and it only spat out foo so I'm guessing things have changed. :) Marc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php From what I understood about || is once it sees a true the whole statement is regarded as true so nothing else following matters so PHP ignores everything in the conditional after it evaluates as true... and once it sees a false the whole statement is regarded as false so nothing else following matters again even the docs say short circuiting is used :) http://php.net/manual/en/language.operators.logical.php
Re: [PHP] Noobie starting to learn OOP for databases needs help
On Sun, Dec 16, 2012 at 2:08 PM, Matijn Woudt tijn...@gmail.com wrote: On Sun, Dec 16, 2012 at 4:38 PM, dealTek deal...@gmail.com wrote: Hi all, Noobie starting to learn oop for databases from here: https://github.com/JeffreyWay/PHP-MySQL-Database-Class/blob/master/MysqlDb.php I've got lots working but have a few issues: 1 - after an insert I'd like to get the id of the new record and I'm not sure how to get that... mysql_insert_id (depricated?) or mysqli_insert_id() (I am using mySql 5.3) not sure where to add this... (most likely in MysqlDb.php but I don't know where or how...) http://de.php.net/manual/en/function.mysql-insert-id.php try SELECT LAST_INSERT_ID(); it should give you the id of the last inserted row (on a connection basis). 2 - how does one do aggrigate select queries like SELECT SUM(price) FROM mytable ... what I tried seemed to fail... Please show is exact query that failes, and give the error it returns. And if anyone can point to some good OOP training URL's I'd appreciate it. Thanks in advance for any assistance... Note sure what OOP has to do with MySQL, but I'd say google for PHP OOP and there's plenty of good stuff available. - Matijn I'd do select sum(price) as price that way the column name returned is price and not a derived column name
Re: [PHP] Session ?
On Sat, Dec 8, 2012 at 12:10 PM, Jim Giner jim.gi...@albanyhandball.comwrote: On 12/8/2012 11:41 AM, Jim Giner wrote: On 12/8/2012 11:04 AM, Daniel Brown wrote: You can pass the session ID and reactivate the session that way, sure. Not pretty, and it does lead to security considerations, but it would work. OK - I've done this in script 1: if (isset($_REQUEST['sess'])) $sess_id = $_REQUEST['sess']; else $sess_id = ''; if ($sess_id '') { session_start($sess_id); $errmsg .= started sess id is: $sess_id ; } else { session_start(); $errmsg .= started new sess ; } Then my process creates a Session array and calls script 2 In script 2 I have: if (isset($_GET['sess']) $_GET['sess'] '') { $sess_id = $_GET['sess']; session_start($sess_id); $errmsg .= started sess $sess_id ; } else { session_start(); $sess_id = session_id(); $errmsg = started NEW sess with id of $sess_id ; } My $errmsg shows me the same sess id in both scripts, and it would appear that I have managed to pass my session across the sub-domains. But when script 2 attempts to access the contents of the Session array created in script 1 it doesn't find it. What am I not doing? Forgot to mention that when I do header(...) to go to script 2 that I do append the session id to my url Same on the return from script 2 back to script 1. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I know i'm late to the party here but I had to do something similar I used something similar to http://www.nczonline.net/blog/2010/09/07/learning-from-xauth-cross-domain-localstorage/ ie storing the session state in html localstorage objects then using the methods in that link to read them thru iframes on the other domain...
[PHP] Re: PDO mysql Connection issue
ad...@buskirkgraphics.com wrote: I am having a PDO mysql connection issue I cant explain. On server server1.mydomain.com I have a test script ?php $pdo = new PDO('mysql:host=171.16.23.44;dbname=test', 'user','password'); ? 171.16.23.44 is by an A record called server2.mydoamin.com they are 2 different servers. This script returns an error: ERROR: Access denied for user 'user'@'server1.mydomain.com' (using password: YES) I find this ODD because that is not the server i am connecting TO but FROM. Why would the PDO connection be referring back to its own localhost instead of the intended domain. I have tried this by fully qualified domain name, same thing. I have ensured the route does exist on the connecting server. I have ensured there is no local reference to the domain name/IP back to its self. I log into 171.16.23.44 and there is NO record of the failed attempt. I validate the user has remote access rights. I validate there is not a firewall rule blocking the host/port/you name it. I telnet from the server to the destination via port 3306 it connects. BTW (171.16.23.44) IS FAKE I AM USING THE IP AS AN EXAMPLE HERE. Any clue as to WHY the host parameter is not setting or is it setting and something else is wrong? You are attempting a connection by u...@server1.mydomain.com This request is made to the mysql server on host server2.mydomain.com which responds with the error that access is denied for the user named 'user' on host server1.mydomain.com The most likely problem is that on server2.mydomain.com you do not have mysql privileges for u...@server1.mydomain.com -- Cheers David Robley People in the passing lane that don't pass will be shot. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] cron job problem
On Tue, Oct 23, 2012 at 5:31 PM, Daniel Brown danbr...@php.net wrote: On Tue, Oct 23, 2012 at 5:34 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: Crontab is the daemon which runs cron jobs, and some distros have set up special files called cron.daily (or daily.cron I don't recall), cron.hourly, etc to make it easier to schedule jobs. Quick clarification and correction here: The cron *daemon* is crond, while the *script* that is batch-processed by cron is called the crontab. When it is executed, it is referred to as a cron job. That said, Ash is right about the rest. Different OS flavors (BSD, Linux, UNIX, SunOS/Solaris, HP-UX, et cetera) often use different path and file standards. Linux, in general, uses a command `crontab` which opens the local user's environment-configured editor to modify the user's crontab in the spool. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php script runs ntp updates server time script runs again?
Re: [PHP] Wrong time being displayed by PHP!
On Tue, Oct 16, 2012 at 2:02 PM, Richard S. Crawford rich...@underpope.comwrote: The value of date.timezone in php.ini is set to America/Los_Angeles. The local time is 11:02 a.m. Yet the output of date(h:i a e) is: 02:02 pm America/Los_Angeles which is three hours ahead of the real time. Why is this? What's going on? -- Sláinte, Richard S. Crawford (rich...@underpope.com) http://www.underpope.com Twitter: http://twitter.com/underpope Facebook: http://www.facebook.com/underpope Google+: http://gplus.to/underpope the clock on the server is wrong?
Re: [PHP] foreach
On Tuesday, October 16, 2012 09:46:26 AM you wrote: Here's what I ended up with after you gave me the advise: $result = mysql_query(SELECT * FROM items); $rows = array(); while($row = mysql_fetch_array($result)) $rows[] = $row; foreach($rows as $row){ $product = $row['product']; $price = $row['price']; echo $product ; echo $price ; $justright = 0; $toohigh = 5; //I was going to use this to check if the price was too high just so I could use an elseif in the exercise, but I realized that it would only work if the if() evaluated to false, which would be impossible. Ahhh pizz on it, it was fun anyway! :- ) if($justright = $price){ echo Not bad. I'll buy it.br /; } else echo Too expensive I'm going home LOL ; } It's a dumb script that makes no sense but I had a blast doing this. When things start coming together like this, it gets so gratifying. :-) -- David M. David, Just putting this out there, but the use of a foreach() loop here, is redundant... You are putting your query results into an array, and then looping through them after with the foreach(), instead of just using the while loop to loop through them initially... so you're doing the same thing, twice, just using the foreach() after the while. One thing I was always told when I was learning c++ (my teacher was anal, and always forced us to try and be more efficient), using = uses more cpu cycles, than or , so when you're checking 0 = 0.1 true, false, you could exchange your check to be 0 0.1 false, else true... This is what I like to hear. It's stuff like this this that I haven't found in a text book. Even when Bastian said $row is a pointer. Ah Yes! That helped tremendously. Also, setting the variable $product and $price, with the value from the database $row['product'], would be less cycles than to just echo the $row['product']... Hehehehe who said I wanted this exercise to be easy? LMBO That is just some $0.02... I wouldn't personally create more code, just to try something out... use the right function for the job, write less code than needed (sometimes, a little more code for readability is better though), and most importantly... have fun. I appreciate your feedback and it's conversations like this that help the most. One thing I do, is my coding and bracing style is something that Tedd Sperling doesn't like (there have been many discussions about bracing styles), I keep my braces all in line, and always use them in my if()s... ie: If($yourmom == $hot) { Echo MILF!; } Else { Echo Pass.; } And I do this for readability, so I can see if I forgot a brace somewhere, and also, I always know that there are braces (with a 4space indentation, or tab stops set at 4 space) I have Kate set up to create auto brackets so I'll never forget to close one and I have lines on the left hand side that connect each open bracket to it's corresponding close bracket. Any open end lines means I'm missing something. 1 more point, doing multiline comments, use /* insert comment here */ and not just //, and with that, I use inline comments with #, but that is just me. That long comment I made about the variable I didn't use was actually typed in the e-mail in my reply to Bastian and wasn't in the code. If it was in the code I would have used /* */ Overall though, I am glad to see you're learning, and having fun doing so... Thanks. The whole purpose of me doing this was to get to play with foreach() and I've been down with while for a while.. LMBO it was just too easy to use while and I was trying to force myself to keep thinking. When Bastian pointed out that $row was a pointer, just that little bit of info changed the whole course of how I was thinking. I was thinking $row was an array with all the results in it and with his little bit of info and knowing I wanted to play around with foreach() I just stuck to whatever came up and this is what the result was... :-) Alot of times I need to be reminded. Like hey! that's a CONSTANT not a $variable!! -- David M.
Re: RES: [PHP] foreach
On Tuesday, October 16, 2012 11:02:18 AM Samuel Lopes Grigolato wrote: There is some cases that more code (and more cycles) is a good thing. For example, a multi-layer architecture (like presentation, business and data access) is more cpu-intensive than a single page doing everything in an entangled procedural style, but is far more easy to evolve! As Steven said, you need to use the right tool for the job. If you're going to write some cryptographic API for mission-critical applications, or a network protocol for games with extreme bandwidth demands, every = matters, otherwise, better to stick with readability and separation of concerns. Cheers, Samuel. -Mensagem original- De: Steven Staples [mailto:sstap...@mnsi.net] Enviada em: terça-feira, 16 de outubro de 2012 10:46 Para: 'David McGlone'; 'Bastien'; 'PHP-GENERAL' Assunto: RE: [PHP] foreach Here's what I ended up with after you gave me the advise: $result = mysql_query(SELECT * FROM items); $rows = array(); while($row = mysql_fetch_array($result)) $rows[] = $row; foreach($rows as $row){ $product = $row['product']; $price = $row['price']; echo $product ; echo $price ; $justright = 0; $toohigh = 5; //I was going to use this to check if the price was too high just so I could use an elseif in the exercise, but I realized that it would only work if the if() evaluated to false, which would be impossible. Ahhh pizz on it, it was fun anyway! :- ) if($justright = $price){ echo Not bad. I'll buy it.br /; } else echo Too expensive I'm going home LOL ; } It's a dumb script that makes no sense but I had a blast doing this. When things start coming together like this, it gets so gratifying. :-) : -- David M. David, Just putting this out there, but the use of a foreach() loop here, is redundant... You are putting your query results into an array, and then looping through them after with the foreach(), instead of just using the while loop to loop through them initially... so you're doing the same thing, twice, just using the foreach() after the while. One thing I was always told when I was learning c++ (my teacher was anal, and always forced us to try and be more efficient), using = uses more cpu cycles, than or , so when you're checking 0 = 0.1 true, false, you could exchange your check to be 0 0.1 false, else true... Also, setting the variable $product and $price, with the value from the database $row['product'], would be less cycles than to just echo the $row['product']... That is just some $0.02... I wouldn't personally create more code, just to try something out... use the right function for the job, write less code than needed (sometimes, a little more code for readability is better though), and most importantly... have fun. One thing I do, is my coding and bracing style is something that Tedd Sperling doesn't like (there have been many discussions about bracing styles), I keep my braces all in line, and always use them in my if()s... ie: If($yourmom == $hot) { Echo MILF!; } Else { Echo Pass.; } And I do this for readability, so I can see if I forgot a brace somewhere, and also, I always know that there are braces (with a 4space indentation, or tab stops set at 4 space) 1 more point, doing multiline comments, use /* insert comment here */ and not just //, and with that, I use inline comments with #, but that is just me. Overall though, I am glad to see you're learning, and having fun doing so... +1 Great advise from both of you and very appreciated. -- David M.
[PHP] foreach
I've been sitting here playing around with foreach() and I'm wondering why I am getting these results. here's what I've been fooling around with. the code has no perticular meaning, but I noticed if the script fails, I get the sentence Too expensive I'm going home LOL 6 times because there are 6 words in the sentence. I also have a database that looks like this: product_id product price 1 Milk2.59 2 bread 1.05 And when $row is equal to 0 the output I get is 1 1 Milk Milk 2.59 2.59 Which is printed to the screen according to how many rows are in the db I belive. So my question is why this behavior? I was expecting something like a while loop. -- David M.
Re: [PHP] foreach
On Monday, October 15, 2012 08:21:23 PM you wrote: Bastien Koert On 2012-10-15, at 8:16 PM, David McGlone da...@dmcentral.net wrote: I've been sitting here playing around with foreach() and I'm wondering why I am getting these results. here's what I've been fooling around with. the code has no perticular meaning, but I noticed if the script fails, I get the sentence Too expensive I'm going home LOL 6 times because there are 6 words in the sentence. I also have a database that looks like this: product_idproductprice 1Milk2.59 2bread1.05 And when $row is equal to 0 the output I get is 1 1 Milk Milk 2.59 2.59 Which is printed to the screen according to how many rows are in the db I belive. So my question is why this behavior? I was expecting something like a while loop. Dave, Foreach is an iterator over an array. Your $row is a pointer to a db result set. If you were to pass the $row result set to the foreach as an array, you'd get what you think you should Www.php.net/foreach Thanks Bastien. Heres what I started with: $result = mysql_query(SELECT * FROM items); $row = mysql_fetch_array($result); foreach($row as $rows){ $row = 0; if($row == 0){ echo $rows; } else{ echo Too expensive I'm going home LOL; } } Here's what I ended up with after you gave me the advise: $result = mysql_query(SELECT * FROM items); $rows = array(); while($row = mysql_fetch_array($result)) $rows[] = $row; foreach($rows as $row){ $product = $row['product']; $price = $row['price']; echo $product ; echo $price ; $justright = 0; $toohigh = 5; //I was going to use this to check if the price was too high just so I could use an elseif in the exercise, but I realized that it would only work if the if() evaluated to false, which would be impossible. Ahhh pizz on it, it was fun anyway! :-) if($justright = $price){ echo Not bad. I'll buy it.br /; } else echo Too expensive I'm going home LOL ; } It's a dumb script that makes no sense but I had a blast doing this. When things start coming together like this, it gets so gratifying. :-) -- David M.
Re: [PHP] appreciation
On Thursday, October 11, 2012 11:10:46 PM tamouse mailing lists wrote: On Thu, Oct 11, 2012 at 8:02 PM, David McGlone da...@dmcentral.net wrote: Dear everybody :-) I wanted to thank everyone for helping me out on the stuff that I had been trying to do in the last couple weeks. I know I was unorganized, confused, flustered and burnt out. But after all the feedback, and getting a swift kick in the arse from Jim and Govinda telling me not to let anyone intimidate me, and quite a few other good points, I went back to my original plan and used opendir. After I got this down and understood it, It made me realize how glob worked and I wrote the same thing using glob as I did with opendir. I feel good about this and what's even better, I killed 2 birds with 1 stone.. LOL Anyway, I just wanted to let everyone know I appreciated all the feedback. :-) !-- using opendir-- $page = $_SERVER['PHP_SELF']; //directories $dirBase = images/property_pics; //get album $get_the_album = $_GET['album']; if (!$get_the_album){ echo p /Select an album:p /; $handle = opendir($dirBase); while(($file = readdir($handle)) !==FALSE){ if(is_dir($dirBase./.$file) $file != . $file != ..){ echo a href='$page?album=$file'$file/abr /; } } closedir($handle); } else{ if(!is_dir($dirBase./.$get_the_album) || strtr($get_the_album, .) !=NULL || strtr($get_the_album, \\) !=NULL){ echo Album does not exist.; } else { // echo $get_the_album; $handle = opendir($dirBase. / . @$get_the_album); while(($file = readdir($handle)) !== FALSE){ if ($file != . $file != ..){ echo div id='imageStack'a href='$dirBase/$get_the_album/$file' rel='lightbox[image]'img src=$dirBase/$get_the_album/$file height='150' width='150'/abr //div; } } closedir($handle); } } !--end of using opendir-- !start of using glob-- function myglob(){ $result = mysql_query(SELECT * FROM properties); while($row = mysql_fetch_array($result)){ $MLS_No = $row['MLS_No']; } $images = glob('images/property_pics/' .$MLS_No.'/*'); foreach ($images as $image){ echo div id='imageStack'a href='$image' rel='lightbox[MLS_No]'img src='$image' width='200' height='200'/a/div; } } !--end of using glob-- -- David M. Hi, David, glad you're sticking with it. I don't understand what you're trying to do here, though: if(!is_dir($dirBase./.$get_the_album) || strtr($get_the_album, .) !=NULL || strtr($get_the_album, \\) !=NULL){ echo Album does not exist.; } It's suposed to be strstr. This was an attempt to make sure that nobody could get into any directories lower than the directory that contained the image folders. Funny thing is it was still working with my typos. There probably is a better way to do it, but by breaking it down is how I was able to understand it. anyway I fixed it and It should look like this: if(!is_dir($dirBase./.$get_the_album) || strstr($get_the_album, .) !=NULL || strstr($get_the_album, /) !=NULL || strstr($get_the_album, \\) !=NULL){ echo Album does not exist.; } echo Album does not exist.; } PHP function strtr takes 2 or 3 arguments, but if only supplying a simple string for argument 2, you *must* supply a string for argument 3 as well. When I try this: $ php -r '$s = strtr(a string,.); var_dump($s);' This is the result: PHP Warning: strtr(): The second argument is not an array in Command line code on line 1 PHP Stack trace: PHP 1. {main}() Command line code:0 PHP 2. strtr() Command line code:1 bool(false) which indicates the strtr function call failed. What is it you want to do there? Are to trying to see if $get_the_album contains a . or a backslash? If so, you will want to use some sort of search or match facility, not the character substitution function of strtr. If so, something like this will work instead: if ( ! is_dir($dirBase./.$get_the_album) // this is not a directory || ! strpos($get_the_album, '.') // directory name does not contain a period || ! strpos($get_the_album, '\') // directory name does not contain a backslash ) { echo Album does not exist.; } If that isn't what you want to do, could you provide a simple sentence (not code) of what you want to do there? Later when I get home from work about 1, I am going to run your example so I can see the differences. -- David M.
[PHP] appreciation
Dear everybody :-) I wanted to thank everyone for helping me out on the stuff that I had been trying to do in the last couple weeks. I know I was unorganized, confused, flustered and burnt out. But after all the feedback, and getting a swift kick in the arse from Jim and Govinda telling me not to let anyone intimidate me, and quite a few other good points, I went back to my original plan and used opendir. After I got this down and understood it, It made me realize how glob worked and I wrote the same thing using glob as I did with opendir. I feel good about this and what's even better, I killed 2 birds with 1 stone.. LOL Anyway, I just wanted to let everyone know I appreciated all the feedback. :-) !-- using opendir-- $page = $_SERVER['PHP_SELF']; //directories $dirBase = images/property_pics; //get album $get_the_album = $_GET['album']; if (!$get_the_album){ echo p /Select an album:p /; $handle = opendir($dirBase); while(($file = readdir($handle)) !==FALSE){ if(is_dir($dirBase./.$file) $file != . $file != ..){ echo a href='$page?album=$file'$file/abr /; } } closedir($handle); } else{ if(!is_dir($dirBase./.$get_the_album) || strtr($get_the_album, .) !=NULL || strtr($get_the_album, \\) !=NULL){ echo Album does not exist.; } else { // echo $get_the_album; $handle = opendir($dirBase. / . @$get_the_album); while(($file = readdir($handle)) !== FALSE){ if ($file != . $file != ..){ echo div id='imageStack'a href='$dirBase/$get_the_album/$file' rel='lightbox[image]'img src=$dirBase/$get_the_album/$file height='150' width='150'/abr //div; } } closedir($handle); } } !--end of using opendir-- !start of using glob-- function myglob(){ $result = mysql_query(SELECT * FROM properties); while($row = mysql_fetch_array($result)){ $MLS_No = $row['MLS_No']; } $images = glob('images/property_pics/' .$MLS_No.'/*'); foreach ($images as $image){ echo div id='imageStack'a href='$image' rel='lightbox[MLS_No]'img src='$image' width='200' height='200'/a/div; } } !--end of using glob-- -- David M.
Re: [PHP] Re: limiting
somewhere else, which means he'll probably repeat the mistakes that have been mentioned here. Oh, well you can only help those who ask for it, and only if they know what to do with it. I doubt he's gone for good. Looking at the archives[1], he shows up once in a few months with some random question (making same mistakes over again). So if he's gone now, he'll probably show up in a few months. [1] http://marc.info/?a=12566756423r=1w=2 I'm not gone, I just quit posting on this subject, because things got so twisted along the way, that everyone is now perceiving me to not know the slightest thing about PHP and being someone I'm not! In my very original post on this series, I was using opendir and someone had suggested using glob. Well I didn't know much about glob, because of course I hadn't got that far yet, but since someone else had backed up the suggestion from the original poster I was dumb enough to jump forward to the unknown and cause myself to get confused and flustered and my train of thought blew right out the window! But, I'm the kind of person that doesn't give up! I was determined to figure out how to get glob to work for what I was trying to do because it was suggested by people who KNOW what they are doing and I KNOW they know what they are doing! I kept telling myself glob is the answer, so really there's no reason to be SMUG about it! I should have went back to using opendir, but if I did that, someone would be on my ass about that sooner or later, harping at me that they showed me how to use glob! To top it off, I started dabbling and trying to learn PHP, back somewhere around early 2000 or 2001 and by that time I had my 2nd child on the way, but by 2002 I had had 3 kids born in '99, 2000 and 2002. So I had to put what I wanted to do on hold until here about a year ago, some things have changed since then in the PHP world and I'm pushing 45 years old and my brain isn't as sharp as it was 20 years ago! So, yes I got confused, and I didn't know much about return because I hadn't used it yet but that doesn't give anyone the right to judge me on that basis! With that said, I just may leave the list. After all if this is all I'm going to get out of it, it's not worth it! -- David M.
Fwd: Re: [PHP] Re: limiting
-- Forwarded Message -- Subject: Re: [PHP] Re: limiting Date: Wednesday, October 10, 2012, 02:03:57 PM From: David McGlone da...@dmcentral.net To: jim.gi...@albanyhandball.com On Wednesday, October 10, 2012 01:31:58 PM Jim Giner wrote: On 10/10/2012 1:19 PM, David McGlone wrote: With that said, I just may leave the list. After all if this is all I'm going to get out of it, it's not worth it! -- David M. This list has given you some very good advice, much of it from others. It may not have solved your understanding of 'glob' (which is just another function - how could it alone mess up your project?) At first is was going to be a project, because I thought that would help keep focus, but once I was introduced to glob it went from being a project, to a function to just plain code. I turned all my attention to glob and that little bit of code that I completely forgot I was trying keep focus by keeping it a project. but it has felt your pain and offered you some ways to get up to speed. Don't leave - take the advice with the sentiment it was given and learn. This list is all about learning. Just don't tackle the Tour de France until you get your training wheels off! :) Your advise was not what bothered me, it was way off base to say the least. What bothered me was the judgement that was cast upon me because I didn't understand return very well and when that came up, it added to my confusion and frusturation of trying to use glob which wasn't even my plan in the first place. BTW - in any of your other computer languages didn't they utilize a 'return' statement? PHP's is no different. back in like '85, I learned Pascal that's the only language I learned and I don't recall if it used return. -- David M. - -- David M.
Re: [PHP] Re: limiting
On Wednesday, October 10, 2012 07:36:00 PM Tim Streater wrote: On 10 Oct 2012 at 19:17, David McGlone da...@dmcentral.net wrote: BTW - in any of your other computer languages didn't they utilize a 'return' statement? PHP's is no different. back in like '85, I learned Pascal that's the only language I learned and I don't recall if it used return. Mmmm. There's the problem. Pascal doesn't *have* a return statement. In Pascal, implicitly, you return when execution reaches the end of a function. In fact the same is true of PHP and JavaScript, but in those languages you can return early just by saying return. IMO, this is a major limitation of Pascal. I use returns wherever I feel like it - if I detect there's nothing more for the function to do, I return. Purists object to this; they say you should enter a function at one place and leave at one place. Well, that's a point of view. But more often that not it just leads to convoluted code in order to achieve that. The one time I *had* to use Pascal as that was the only option, I simply put a 999: label at the end of the function and did goto 999 wherever I wanted to do a return. Simples! goto was the thing that got on my nerves. Even to this day I hate that word with a passion. -- David M.
Re: [PHP] Re: limiting
On Tuesday, October 09, 2012 12:18:06 PM Jim Giner wrote: On 10/8/2012 11:11 PM, David McGlone wrote: Hi all, is there any other way to limit this code to only displaying 1 image other than using return. When I use return, I can't get the other images to display in lightbox, but when I use echo, all 5 of the images will correctly display in lightbox, but they are also displaying on the page. $result = mysql_query(SELECT * FROM properties); $row = mysql_fetch_array($result); $matches = glob('images/property_pics/212006966/' .$prefix. '*'); foreach($matches as $match){ echo a href=$match rel='lightbox[$matches]' /img src = $match/a; I'm not even sure if this is possible, but thought I'd ask before I scrapped the idea. I've been at this code since last thursday trying to learn as much as I can about it and I just keep going in circles and I'm starting to feel like glob() is what is limiting me. I've tried various code blocks with things like where(), str_repeat, basename, scandir, sort etc with no luck. :-/ I hate to sound condescending, but you are showing some serious deficiencies in your programming ability. I have to say that you are tackling some very complex processes without the basic understanding of programming that one needs. What I base this opinion on is that since you first revealed your lack of understanding of Return and echo in php, you have spent another 3 days and STILL don't understand? Really? I was afraid when I first posted that question, it would give that impression. I've known what echo does, but not very much about return. Also a part of me has always wondered when I'm studying code from things like wordpress I don't think I have seen any echo statements. If I did it was very very few. (hint: why I asked about templeting systems about a month ago.) As for the code above - once again it looks like you have posted a re-typing of some code you have tried to execute. I say that because you have a query and a fetch of one record of the results THAT HAS NOTHING TO DO WITH THE REST OF THE CODE! The query is geting a number out of the database and putting the value in $prefix. Also - you have an array being used as part of the Rel tag? What's up with that? (I think you meant to use $match - but that further verifies that this is NOT the code you ran.) I tried using $match and $matches because I got confused there for a bit and changed it. Finally - the code is (from your description) doing exactly what it is designed to do (the running code that is). It sure is, and I found out what my whole problem was this morning before I went to work. My problem was lightbox was not putting all the images in $match. but I never suspected it until Matijn and Marco, posted an example of code and It turned my attention to the piece of code... put a bunch of images in a folder and try running the code. You'll see what I'm talking about. All the (repeated) echo statements are going to put something on your web page. Yes I was getting stuff on the page, and then when I'd try and build onto the idea, and things broke, I'd try something else, and something else, until finally I'm all confused with it. for example I'd forget to terminate something and get a blank screen and imediately suspect it was the new code I introduced. After the millionith time I started realizing when I get a blank screen, I forgot my semicolon at the end of a line somewhere. The question you have is (apparently) how to hide them, since I believe Lightbox is going to have to have them present in order to do its thing. That's part of it. the other part is that lighbox is supposed to do that automatically and it should, and that's another reason I was getting confused. like I said earlier run the code and you'll see what I'm saying. And so - in parting - I think you need to develop some html knowledge to facilitate that hiding part and some immediate skills in the general area of programming and learning to locate and read the right manuals. Glob is the least of your concerns. Yes - I'm being rough (I say this to you David as well as the rest of the community that is still interested in this post) but somebody has to make you realize that you are seriously in over your head and don't even know it. I've said it many times, I am doing this to try and further my knowledge in PHP and get past the basic echoing of variables and strings, and this is nothing more than practice. Have you read a book on php and perhaps one on CSS to help with your hiding problem? (BTW - that last was a hint.) I've read plenty of PHP books I own at least 5 and ALL of them I've read hardly ever explain anything at all. They just throw some code in there and say this is what it does and gives a picture of the finished product. Total waste of my money! Also, how am I going to learn PHP if I've
[PHP] limiting
Hi all, is there any other way to limit this code to only displaying 1 image other than using return. When I use return, I can't get the other images to display in lightbox, but when I use echo, all 5 of the images will correctly display in lightbox, but they are also displaying on the page. $result = mysql_query(SELECT * FROM properties); $row = mysql_fetch_array($result); $matches = glob('images/property_pics/212006966/' .$prefix. '*'); foreach($matches as $match){ echo a href=$match rel='lightbox[$matches]' /img src = $match/a; I'm not even sure if this is possible, but thought I'd ask before I scrapped the idea. I've been at this code since last thursday trying to learn as much as I can about it and I just keep going in circles and I'm starting to feel like glob() is what is limiting me. I've tried various code blocks with things like where(), str_repeat, basename, scandir, sort etc with no luck. :-/ -- David M.
Re: [PHP] Re: building upon the code RE: Differences
On Thursday, October 04, 2012 10:41:17 PM Jim Giner wrote: On 10/4/2012 10:15 PM, David McGlone wrote: I hope I'm not being a pest. I've played with the return and echo so much today I've finally realized I'm going in circles. But I can say I understand it more than ever. Now whats on my mind is breaking out of this circle and doing more with this code. What I am trying to do now is instead of having ALL the images display, I want to try and group them by their name. If I were using SQL I'd simply use a where clause and be done with it, but I'm not sure what would acomplish the same thing or similiar to a where clause in php. I dont' see how a where clause in sql provides you with a result that organizes the images by name. All the images I have that go together have the same name. 12345_1.jpg 12345_2.jpg 12345_3.jpg So by using a where clause in a MySQL select statement and some php, I'd be able to grab the result set with the same name. -- David M.
Re: [PHP] Re: building upon the code RE: Differences
On Thursday, October 04, 2012 11:37:06 PM Bastien Koert wrote: On Thu, Oct 4, 2012 at 10:41 PM, Jim Giner jim.gi...@albanyhandball.com wrote: On 10/4/2012 10:15 PM, David McGlone wrote: I hope I'm not being a pest. I've played with the return and echo so much today I've finally realized I'm going in circles. But I can say I understand it more than ever. Now whats on my mind is breaking out of this circle and doing more with this code. What I am trying to do now is instead of having ALL the images display, I want to try and group them by their name. If I were using SQL I'd simply use a where clause and be done with it, but I'm not sure what would acomplish the same thing or similiar to a where clause in php. I dont' see how a where clause in sql provides you with a result that organizes the images by name. Read the images into an array and then sort the array...glob() gives you that array so use one of the many sort functions as you like to get the order you want Thanks. I'll try this today and see what I can do. -- David M.
Re: [PHP] Re: Differences
On Thursday, October 04, 2012 06:06:50 PM Jim Giner wrote: On 10/3/2012 8:48 PM, David McGlone wrote: Hi everyone, I have been playing around with some code the list helped me with a while back and I'm not grasping the concept between return and echo and the PHP manual doesn't answer this, unless I'm missing something. There is an example at the very bottom of PHP's return manual, but it's confusing. So now I'm left wondering why return will only give me the first result in an array, but echo will give me all the results of the array. Using stuart's example he had sent me a while back I've messed around with it and modified it to better understand it: function filename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); foreach($matches as $filename){ return $filename; } } echo completeImageFilename($row['MLS_No']); With the above code I only get the first image of each picture name, but when I change return to echo, it groups and displays all the pics that have the same picture name. -- David M. I've read thru 9 responses to the OP and not one of you mentioned that the code presented is problematic in itself. Very forgiving, but perhaps someone should have suggested that he post actual code when looking for help in the future, and not some typing that is supposed to represent the problem. In this case, Im looking for the function he called completeImageFilename :):) Uh Oh, we're in trouble ;-) Sorry about that Jim, I accidently typed the wrong function name. Here's the corrected code. Everybody's answer was spot on and I learned a great deal about return and echo. :-) function completeImageFilename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); foreach($matches as $filename){ return $filename; } } echo completeImageFilename($row['MLS_No']); -- David M.
[PHP] building upon the code RE: Differences
I hope I'm not being a pest. I've played with the return and echo so much today I've finally realized I'm going in circles. But I can say I understand it more than ever. Now whats on my mind is breaking out of this circle and doing more with this code. What I am trying to do now is instead of having ALL the images display, I want to try and group them by their name. If I were using SQL I'd simply use a where clause and be done with it, but I'm not sure what would acomplish the same thing or similiar to a where clause in php. -- David M.
[PHP] Differences
Hi everyone, I have been playing around with some code the list helped me with a while back and I'm not grasping the concept between return and echo and the PHP manual doesn't answer this, unless I'm missing something. There is an example at the very bottom of PHP's return manual, but it's confusing. So now I'm left wondering why return will only give me the first result in an array, but echo will give me all the results of the array. Using stuart's example he had sent me a while back I've messed around with it and modified it to better understand it: function filename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); foreach($matches as $filename){ return $filename; } } echo completeImageFilename($row['MLS_No']); With the above code I only get the first image of each picture name, but when I change return to echo, it groups and displays all the pics that have the same picture name. -- David M.
Re: [PHP] Differences
On Wednesday, October 03, 2012 08:55:29 PM admin wrote: Hi everyone, I have been playing around with some code the list helped me with a while back and I'm not grasping the concept between return and echo and the PHP manual doesn't answer this, unless I'm missing something. There is an example at the very bottom of PHP's return manual, but it's confusing. So now I'm left wondering why return will only give me the first result in an array, but echo will give me all the results of the array. Using stuart's example he had sent me a while back I've messed around with it and modified it to better understand it: function filename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); foreach($matches as $filename){ return $filename; } } echo completeImageFilename($row['MLS_No']); With the above code I only get the first image of each picture name, but when I change return to echo, it groups and displays all the pics that have the same picture name. -- David M. The first loop and return is all you will get. Put the information into an array and return the array once the array is built. I think I understand what your saying, but what I don't understand is that when I leave the current code intact and replace return $filename with echo $filename in the function, all the images display. Is this intended behavior between return and echo or is it just bad code on my part? -- David M.
Re: [PHP] Differences
On Thursday, October 04, 2012 03:01:12 AM Timmy Sjöstedt wrote: Hi David, A return statement will immediately halt execution of the current function and return to where it was called. In your case, the foreach loop will execute once and find a return statement, and thus halting execution of the function and returning only the first filename. echo() is simply another function call (except it's a language construct and not a function) and will not halt execution as return does. That's what I was looking for. What you want to do is something like: $filenames = array(); foreach ($matches as $filename) { $filenames[] = $filename; } return $filenames; // this is now an array containing all the filenames I see where I wasn't thinking correctly. I thought that $filename had already contained all the results. But this is rather unneccesary, as $matches already is an array and contains everything you need. Thus all you have to do is: return $matches; I had thought this also, and tried this but didn't get any results. probably because I did something wrong somewhere else and didn't realize it. Which in turn can be shortened to: function filename($prefix) { return glob('images/property_pics/'. $prefix .'*'); } I'll mess around with this and see what I can learn.. David M. Happy Thursday! Timmy On 2012-10-04 02:48, David McGlone wrote: Hi everyone, I have been playing around with some code the list helped me with a while back and I'm not grasping the concept between return and echo and the PHP manual doesn't answer this, unless I'm missing something. There is an example at the very bottom of PHP's return manual, but it's confusing. So now I'm left wondering why return will only give me the first result in an array, but echo will give me all the results of the array. Using stuart's example he had sent me a while back I've messed around with it and modified it to better understand it: function filename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); foreach($matches as $filename){ return $filename; } } echo completeImageFilename($row['MLS_No']); With the above code I only get the first image of each picture name, but when I change return to echo, it groups and displays all the pics that have the same picture name. -- David M. -- David M.
Re: [PHP] Differences
On Wednesday, October 03, 2012 10:01:50 PM James wrote: All of the images are displaying because you're simply instructing the function to print out each file found with your call to glob(). The glob() function returns an indexed array containing files found in the path you specified, or an empty array if no files were found or false if glob() failed. When I say print I'm referring to you using the echo language construct, however, print is also another language construct. Therefore using echo in your function allows the foreach loop to continue iterating through the array of files returned by glob(). Replacing that echo with the return, the function ones one iteration in the foreach loop and stops, returning that value. In your case, the function is returning index 0 of the array returned by glob(). Make more sense? Absolutely. I also think I learned that return can also work like echo if the code is written correctly. David McGlone da...@dmcentral.net wrote: On Wednesday, October 03, 2012 08:55:29 PM admin wrote: Hi everyone, I have been playing around with some code the list helped me with a while back and I'm not grasping the concept between return and echo and the PHP manual doesn't answer this, unless I'm missing something. There is an example at the very bottom of PHP's return manual, but it's confusing. So now I'm left wondering why return will only give me the first result in an array, but echo will give me all the results of the array. Using stuart's example he had sent me a while back I've messed around with it and modified it to better understand it: function filename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); foreach($matches as $filename){ return $filename; } } echo completeImageFilename($row['MLS_No']); With the above code I only get the first image of each picture name, but when I change return to echo, it groups and displays all the pics that have the same picture name. -- David M. The first loop and return is all you will get. Put the information into an array and return the array once the array is built. I think I understand what your saying, but what I don't understand is that when I leave the current code intact and replace return $filename with echo $filename in the function, all the images display. Is this intended behavior between return and echo or is it just bad code on my part? David M. -- David M.
Re: [PHP] Static constructor support
On Wed, Sep 26, 2012 at 2:29 PM, Yves Goergen nospam.l...@unclassified.dewrote: How do other languages than C# call that? :-) Java has static initializers which work the same way: they are executed when the class is first loaded and before any code can make use of the class. David
Re: [PHP] Joining a team, where no wiki or docs are available
On Mon, Sep 24, 2012 at 3:06 PM, Daevid Vincent dae...@daevid.com wrote: And for the love of [insert deity of your choice here] not EVERYTHING has to be OOP. Use the best tool for the job!! Nothing pisses me off more than having to instantiate a new class just to do some simple method that a standard function would do. If you want to be organized, use static methods then where appropriate, but don't avoid functions just because some book told you that OOP is the king $hit. I'll never forget my first experience with a full blown Zend framework application. There were about 13 files and around 15k lines of code included to display one line of text in the header where just a simple echo would have sufficed.
Re: [PHP] Bounce messages
On Friday, September 21, 2012 11:31:36 PM Lester Caine wrote: Ashley Sheridan wrote: On 09/21/2012 12:40 AM, Lester Caine wrote: I know that the php list are one of the 'reply to sender' email handling camp rather than reply to list. I can cope with that now and handle the multiple reply address problem this end so I ONLY reply to list. BUT is there no way of cleaning up the bounce emails we all get when posting to the list(s)? ( Waits to delete all the bounce messages for this post :) ) Doing a little checking on your IP address, I have found that your mail server IP is listed on a black list. Check the link below. http://mxtoolbox.com/SuperTool.aspx?action=blacklist%3a213.123.20.127 This could be the source of your bounce messages. Well that is BT Internet ;) Not a lot I can do about that ... I sporadically get a lot of messages that appear as bounces where people on the list filter out replies and make you sign up to some web service to prove you're a real person. Is that the sort of bounce you're talking about? Yes ... I posted a reply earlier, and got three 'spam' warnings as well as the copy of my post. Actually it's not as bad as it has been ... I was expecting a few more after I posted the comment. And Yes tamouse ... it's having to replace a block of return addresses with just the list address to tidy things up. A long list of addresses can build up when everyone uses 'reply all' where as many other lists just need 'reply' so nowadays I only use reply - and hopefully remember to change to the the list address :) I use reply to mailing list in Kontact. -- David M. David's Webhosting and consulting.
Re: [PHP] Highlight Search Results
On Tue, Sep 18, 2012 at 8:36 AM, Floyd Resler fres...@adex-intl.com wrote: I want to highlight the word searched in search results. I know I can use str_ireplace to do a case insensitive search and replace. However, is there an easy way to maintain the case of the word found when I do the replace? Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php function highlight($haystack,$needle) { $haystack=preg_replace(/($needle)/i,span style='font-weight:bold'\${1}/span,$haystack); return $haystack; }
Re: [PHP] a little trickery
On Sunday, September 09, 2012 03:02:17 PM Stuart Dallas wrote: On 9 Sep 2012, at 04:19, David McGlone da...@dmcentral.net wrote: On Saturday, September 08, 2012 03:49:27 PM you wrote: On 8 Sep 2012, at 15:35, David McGlone da...@dmcentral.net wrote: I have a function that reads a directory and gets all the file names of images, and I am wondering if it's possible to concatinate this function withint an image tag. Here's an example I tried. function pictures() { $dir = 'images/property_pics/'; $file = array(); if(is_dir($dir)){ if($open = opendir($dir)){ while (($file = readdir($open)) !== false $file !== .) { $names = substr($file, 9, 20); echo $names; } } closedir($handle); } } $rs = $pager-paginate(); if(!$rs) die(mysql_error()); while($row = mysql_fetch_assoc($rs)) { echo div id='record'; echo span; echo im src = images/$row[$MSL_No]pictures(); What I am trying to do is get the last part of an image name, because I know the $MSL_No is always a 9 character name which matches the image name in but in the database, the last bit of characters are not there so I'm trying to take the last characters of the image name and concatinate them to each image name.. Wow this is harder to explain that I thought. Here's an example In the DB I have a row MSL_No and the contents is: 123456789 In my images folder I have an image named 123456789_R13_1.jpg My goal: get the MSL_No out of the DB and concatenate anything after it so I would end up with the whole image name.. I hope this all made sense. :-/ Is there just one image in the folder that starts with the 9 digit number? In that case it's dead simple (untested code): ?php function completeImageFilename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); return $matches[0]; } echo 'img src='.completeImageFilename($row['MSL_No']).' /'; ? If you need to extract more than one image filename you should be able to modify that pretty easily. YEOW! LOL I looked at this and I'm very stumped on 1 thing. How in the world did you get $prefix to contain the image name without first assigning it to $prefix? I understand the rest, but. Holy smokes, that's blown my mind. :-/ I really can't tell whether you're being sarcastic, so I'll assume you're not. Sorry about that. No sarcasm here. I was so taken aback on how different your code was. I thought I was never going to understand the way you did it vs the way I tried. Sorry about that. Read about function arguments: http://php.net/functions.arguments Thanks. I'll go read it now. :-) -- Regards David M.
[PHP] a little trickery
I have a function that reads a directory and gets all the file names of images, and I am wondering if it's possible to concatinate this function withint an image tag. Here's an example I tried. function pictures() { $dir = 'images/property_pics/'; $file = array(); if(is_dir($dir)){ if($open = opendir($dir)){ while (($file = readdir($open)) !== false $file !== .) { $names = substr($file, 9, 20); echo $names; } } closedir($handle); } } $rs = $pager-paginate(); if(!$rs) die(mysql_error()); while($row = mysql_fetch_assoc($rs)) { echo div id='record'; echo span; echo im src = images/$row[$MSL_No]pictures(); What I am trying to do is get the last part of an image name, because I know the $MSL_No is always a 9 character name which matches the image name in but in the database, the last bit of characters are not there so I'm trying to take the last characters of the image name and concatinate them to each image name.. Wow this is harder to explain that I thought. Here's an example In the DB I have a row MSL_No and the contents is: 123456789 In my images folder I have an image named 123456789_R13_1.jpg My goal: get the MSL_No out of the DB and concatenate anything after it so I would end up with the whole image name.. I hope this all made sense. :-/ -- Regards David M.
Re: [PHP] a little trickery
On Saturday, September 08, 2012 03:49:27 PM you wrote: On 8 Sep 2012, at 15:35, David McGlone da...@dmcentral.net wrote: I have a function that reads a directory and gets all the file names of images, and I am wondering if it's possible to concatinate this function withint an image tag. Here's an example I tried. function pictures() { $dir = 'images/property_pics/'; $file = array(); if(is_dir($dir)){ if($open = opendir($dir)){ while (($file = readdir($open)) !== false $file !== .) { $names = substr($file, 9, 20); echo $names; } } closedir($handle); } } $rs = $pager-paginate(); if(!$rs) die(mysql_error()); while($row = mysql_fetch_assoc($rs)) { echo div id='record'; echo span; echo im src = images/$row[$MSL_No]pictures(); What I am trying to do is get the last part of an image name, because I know the $MSL_No is always a 9 character name which matches the image name in but in the database, the last bit of characters are not there so I'm trying to take the last characters of the image name and concatinate them to each image name.. Wow this is harder to explain that I thought. Here's an example In the DB I have a row MSL_No and the contents is: 123456789 In my images folder I have an image named 123456789_R13_1.jpg My goal: get the MSL_No out of the DB and concatenate anything after it so I would end up with the whole image name.. I hope this all made sense. :-/ Is there just one image in the folder that starts with the 9 digit number? In that case it's dead simple (untested code): ?php function completeImageFilename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); return $matches[0]; } echo 'img src='.completeImageFilename($row['MSL_No']).' /'; ? If you need to extract more than one image filename you should be able to modify that pretty easily. YEOW! LOL I looked at this and I'm very stumped on 1 thing. How in the world did you get $prefix to contain the image name without first assigning it to $prefix? I understand the rest, but. Holy smokes, that's blown my mind. :-/ -- Regards David M.
Re: [PHP] a little trickery
On Saturday, September 08, 2012 11:19:29 PM David McGlone wrote: On Saturday, September 08, 2012 03:49:27 PM you wrote: ?php function completeImageFilename($prefix) { $matches = glob('images/property_pics/'.$prefix.'*'); return $matches[0]; } echo 'img src='.completeImageFilename($row['MSL_No']).' /'; ? If you need to extract more than one image filename you should be able to modify that pretty easily. YEOW! LOL I looked at this and I'm very stumped on 1 thing. How in the world did you get $prefix to contain the image name without first assigning it to $prefix? I understand the rest, but. Holy smokes, that's blown my mind. I read about glob() on php.net before I replied, but I believe now it's registering. From what I understand glob works just like opendir() but does everything all in just 1 function. so in your code I realize you passed the variable $prefix into glob, along with the path to the files. This put the path images/property_pics/ and each image name from glob into $prefix you then assigne the value of $glob to $matches. Sound about right? :-) -- Regards David M.
Re: [PHP] array.sorting.php
On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: Hi, Sorting question. http://www.php.net/manual/en/**array.sorting.phphttp://www.php.net/manual/en/array.sorting.php I'm using ksort, which sorts like this. I don't want to use strolower. Is there a function/switch in one of the sort functions where I could get another aphabetical sort? http://www.php.net/manual/en/**array.sorting.phphttp://www.php.net/manual/en/array.sorting.phphas a lot of options. I,m not sure which one I should choose. This is what I get: LABRADOR CITY LACOSTA LARGE Labrador Labrador City Labrador Sea Lacosta Large labrador labrador sea lacosta large This is what I want: LABRADOR Labrador labrador LABRADOR CITY Labrador City Labrador Sea labrador sea LACOSTA Lacosta lacosta LARGE Large large -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php natsort natcasesort
Re: [PHP] load rtf file
On Mon, Sep 3, 2012 at 12:56 PM, Matijn Woudt tijn...@gmail.com wrote: On Mon, Sep 3, 2012 at 5:24 PM, Tedd Sperling t...@sperling.com wrote: On Sep 3, 2012, at 1:23 AM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: I have a big giant RTF file. I could convert it to plain text. BUT can PHP do it for me? Hell, even M$ can't do it! I have tons of old Word RFT files that were orphaned by the installation of a newer of M$ Word. The upgrade actually deleted older versions of Word and then would not open the older files because of security concerns (they were create by an older version, duh). It was a nightmare -- as a result, I lost years of business correspondence. Now I make z text version of every document I write. If I wanted to get those old files back, I will have to set up an older computer, reinstall the older version of Word and then transfer those files, convert them to text, and bring them back. That's a lot of work because I trusted M$ to respect older files, but they don't. In short, don't trust M$. Cheers, tedd Either they don't have respect to the older files, or they just don't understand how the format works.. The same goes for opening '97-'03 files in Word 2010 version, sometimes it's also all messed up. Just a side note tedd, couldn't you just open those RTF files with wordpad? IIRC it supports RTF and plain text (even in Win7) - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I found this http://webcheatsheet.com/php/reading_the_clean_text_from_rtf.php
[PHP] templeting
Does anyone use any templeting system for any projects? If so what would anyone recommend? I looked at Code Ignitor, but it seems the templeting system is optional and left out by default. -- Regards David M.
Re: [PHP] templeting
On Sep 3, 2012 9:15 PM, David McGlone da...@dmcentral.net wrote: Does anyone use any templeting system for any projects? If so what would anyone recommend? I looked at Code Ignitor, but it seems the templeting system is optional and left out by default. -- Regards David M. I use smarty
Re: [PHP] templeting
On Monday, September 03, 2012 09:45:23 PM David OBrien wrote: On Sep 3, 2012 9:15 PM, David McGlone da...@dmcentral.net wrote: Does anyone use any templeting system for any projects? If so what would anyone recommend? I looked at Code Ignitor, but it seems the templeting system is optional and left out by default. I use smarty I've used smarty in the past and was thinking about that, but PEAR is absolete anymore and I don't really know of a good replacement. :-/ -- Regards David M.
Re: [PHP] include selectively or globally?
On Tue, Aug 28, 2012 at 4:39 AM, Matijn Woudt tijn...@gmail.com wrote: First of all, I believe [A] PHP is smart enough to not generate bytecode for functions that are not used in the current file. Think about the fact that you can write a function with errors, which will run fine until you call the function. [B] (except for syntax errors). [B] negates [A]. PHP must either parse the file into opcodes or load them from APC and further execute the top-level opcodes. That means defining functions (not calling them unless called directly), constants, global variables, classes, etc. No amount of measuring is required to tell me that doing X vs. not doing X in this case clearly takes longer. Now, is that time significant enough to warrant the extra logic required? In my case, absolutely. We organize our library into many classes in multiple files. By using an autoloader, we simply don't need to think about it. Include bootstrap.php which sets up the autoloader and include paths. Done. In the case with a single 50k library file that is used on 10% of the pages, I'd absolutely require_once it only in the pages that need it without measuring the performance. It's so trivial to maintain that single include in individual pages that the gain on 90% of the pages is not worth delving deeper. Peace, David
Re: [PHP] include selectively or globally?
On Tue, Aug 28, 2012 at 12:11 PM, Matijn Woudt tijn...@gmail.com wrote: On Tue, Aug 28, 2012 at 6:55 PM, David Harkness davi...@highgearmedia.com wrote: On Tue, Aug 28, 2012 at 4:39 AM, Matijn Woudt tijn...@gmail.com wrote: First of all, I believe [A] PHP is smart enough to not generate bytecode for functions that are not used in the current file. Think about the fact that you can write a function with errors, which will run fine until you call the function. [B] (except for syntax errors). [B] negates [A]. PHP must either parse the file into opcodes or load them from APC and further execute the top-level opcodes. That means defining functions (not calling them unless called directly), constants, global variables, classes, etc. [B] does not negate [A]. There's a difference between parsing the syntax and defining functions, classes constants and globals, and generating bytecode. In a 'normal' file I guess syntax definitions are only about 5% of the total contents, the rest can be ignored until being called. I won't claim a deep understanding of the PHP internals, but I have enough experience with varied compiled and interpreted languages and using PHP and APC that I'm confident that the process to include a file involves: 1. Load the opcodes A. Either read the file from disk and parse the PHP into opcodes, or B. Load the cached opcodes from APC. 2. Execute the top-level opcodes Any syntax errors--even those in unreachable code blocks--will cause the script to fail parsing. For example, if (false) { function foo() { SYNTAX ERROR! } } will cause the parse to fail even though the function cannot logically be defined. PHP doesn't even get that far. PHP Parse error: syntax error, unexpected T_STRING in php shell code on line 3 When answering this question, please approach the matter strictly from a caching/performance point of view, not from a convenience point of view just to avoid that the discussion shifts to a programming style and the do's and don'ts. While out of convenience you might be tempted to include the file in every script, when considering performance alone you should include the file only in those scripts that will make use of its contents. Peace, David
Re: [PHP] Dynamic Content thoughts
On Fri, Aug 24, 2012 at 11:16 AM, Jim Lucas li...@cmsws.com wrote: On 08/24/2012 08:01 AM, tamouse mailing lists wrote: OT Reply -- just frustrated with the way email screws up program listings. It's a royal pain to have to strip out code and then put it in an editor and tidy it up just to be able to make heads or tails out of something. There are lots of code pasting sites around, but that breaks up the continuity of the list archive. No solution, just frustrated This list does allow attachments, but that breaks things too, because they are not shown on archive web sites. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php In gmail if I see something is totally screwed up visually I click the little dropdown where you'd select reply to all and then choose show original... It shows the source of the email in monospaced font so if looks like it was meant to
Re: [PHP] mysqlnd and mysqli as shared extensions?
On Mon, Aug 20, 2012 at 10:20 AM, Lester Caine les...@lsces.co.uk wrote: Can mysqlnd be built as a shared module? make test is telling me the resulting .so is not a valid Warning: PHP Startup: Invalid library (maybe not a PHP library) 'mysqlnd.so' in Unknown on line 0 I'm still on PHP5.4.3 on that machine as I've not had time to upgrade as yet. It's running my own PHP sites without a problem via Firebird. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.**ukhttp://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php there was a bugfix in the 5.3 changelog mysqlnd: Fixed bug #55609 http://bugs.php.net/55609 (mysqlnd cannot be built shared). (Johannes) and I see this in the 5.4.0 ext/mysql, mysqli and pdo_mysql now use mysqlnd by default.
Re: [PHP] Display Array Tree as Menu - Can't figure out how to find depth with something over 2 levels
On Thu, Aug 16, 2012 at 12:40 PM, Tristan sunnrun...@gmail.com wrote: I can't for the life of me figure out how to find the depth of the array that I'm looping through to output tabs or indentations to the display for each depth. The entries also have section postition if you can figure out how to include that within each depth of the results I will buy you a case of beer. I was hoping to do something like... foreach($trees as $tree){ if($tree['current_depth'] == 0){ echo $tree['menu_item']; } else if($tree['current_depth'] == 1){ echo 'indentation'.$tree['menu_item']; } else if($tree['current_depth'] == 2){ echo 'indentation - indentation'.$tree['menu_item']; } } Or maybe even like this... foreach($trees as $tree){ // output nbsp; the amount of times current_depth equals echo str_repeat(nbsp;, $tree['current_depth']) } I have my $tree structure as: [16] = Array ( [section_id] = 21 [section_parent_id] = 0 [section_pos] = 30 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 35 [children] = Array ( [0] = Array ( [section_id] = 38 [section_parent_id] = 21 [section_pos] = 31 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 35 [children] = Array ( [0] = Array ( [section_id] = 39 [section_parent_id] = 38 [section_pos] = 32 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 35 ) [1] = Array ( [section_id] = 40 [section_parent_id] = 38 [section_pos] = 33 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 35 ) ) [19] = Array ( [section_id] = 26 [section_parent_id] = 0 [section_pos] = 45 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 55 [children] = Array ( [0] = Array ( [section_id] = 27 [section_parent_id] = 26 [section_pos] = 46 [section_name] = Newsletters Intro [has_order] = 0 [section_has_hierarchy] = 1 [total_entries] = 1 ) ) ) maybe something like this in the foreach if parent = 0 then level = 0; if haschilden is true increment level;
Re: [PHP] Two ways to obtain an object property
On Wed, Aug 15, 2012 at 1:28 AM, phplist phpl...@myword.co.uk wrote: I can have a User object method getSubscriberStatus() which sets $this-isASubscriber. But to use this I would have to run the method just before the if statement. Or I could have a method isASubscriber() which returns the result, meaning the if statement should be if ($crntUser-isASubscriber()) {...} I assume that the decision isn't really about using a property versus a method but that determining the value of the property is costly. For these cases I add an internal private property to save the result of the costly computation and initialize it on the first call to the accessor method. class User { private $_isSubscriber = null; public function isSubscriber() { if ($this-_isSubscriber === null) { $this-_isSubscriber = ... call database or whatever takes so long ... } return $this-_isSubscriber; } } If this isn't the case and you really just want to know which API is nicer, any of the replies so far are acceptable. I favor accessor methods because it's easier to change the implementation without having to change all the places you access it. Peace, David
Re: [PHP] PHP session variables
On Wed, Aug 8, 2012 at 8:24 AM, Ansry User 01 yrsna.res...@gmail.comwrote: I am setting the _SESSION variables in one of my file, but whenever I leave the php page session variables are not accessible. As always, post some code demonstrating what you're doing. Help us help you! :) David
Re: [PHP] Mac 10.7 Install/Copy fresh PHP over Pre-Installed PHP
On Mon, Jul 30, 2012 at 10:21 AM, JeffPGMT jeffp...@gmail.com wrote: Tamara, I said dll, but that was only my ignorant/windows reference to a system lib/bin file. I followed a blog post (bitly'ed below); I got as far as un-tar'ing and make was not available. I have other stacks Xampp (beta for Mac not for production) and is used by many folks w/out issue, however this is a production system, hence my wonderment frustration as to why IMAP was removed by Apple and not a dev box for me to install 3rd party tools and have an issue with our IT. I also considered MAMP or FastStack, however that meant there are two installs of both Apache PHP. I did a test and put the preinstalled stuff on port 8080. But, I thought, It's a server OS, why not use what came installed? And that was one of my original questions alluding to perhaps IMAP was installed but turned off at some not so obvious point just waiting to be restored. I originally sent the following as a PM to TR Shaw... The OS is 10.7 Lion Server! (I'm really emphisising server, because when I presented my situation to our IT and a call to Apple I was told that it was there! By the end of the call Apple said, sorry (after a nearly 20min hold, suppose he asked someone more experienced) and my IT said, hey let's just try the new 10.8 maybe that will fix it? I realized I was dealing with an very experienced Mac IT person who really didn't know. I read the instructions on adding c-client 2007, but make is an invalid cmd, apparently that's pulled by Apple too; is there a way to add php_IMAP w/out? I got as far as downloading un-tar, but failed at make osx...filename... http://bit.ly/JWre51 TRShaw: What/Where/Why is the path /etc/intl ? I'm not familiar w/Mac, what are steps 3 4? And lastly I'm reluctant to install XCode or MacPorts because, I'm not IT and this is not a dev box. I think that these are the responsibility of IT, who manages the server desktops network. I really just want to drop my program in and run away :) JeffPGMT TR Shaw ts...@oitc.com wrote in message news:c512aca8-a6ed-45e9-873f-c0e72dd9e...@oitc.com... Actually, adding extensions (even normally bundled ones) to the stock Snow Leopard PHP is quite easy: 1) Download the source tarball of php and unpack it 2) cd into ext/name_of_the_extension (like ext/intl in your case) 3) run phpize 4) run ./configure with appropriate flags 5) make install Then you just enable the freshly built .so file in your php.ini and you are done. On Jul 28, 2012, at 12:25 AM, Tamara Temple wrote: JeffPGMT jeffp...@gmail.com wrote: Please correct me if I'm wrong and IMAP is available (maybe a known config issue?) Mac OSX 10.7, Using the pre-installed Apache Php, IMAP is not installed, pulled out my Apple for this server OS. I don't know if it is, but something below seems very odd to me: $ php -v PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_imap.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_imap.dll, 9): image not found in Unknown on line 0 I might be wrong here on 10.7, as I haven't even migrated off 10.5, but, I've never seen a .dll file on a mac -- they're windows dynamic link libraries. I think somehow things are little messed up there... Someone has suggested installing MAMP, which is a much better solution in general that what Apple supplies. The issue is knowing which you're running at any point in time, which for most things, MAMP will handle correctly. But it may not be the case for command line execution as you've shown above. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I just installed the latest MAMP on my MacMini running Mt. Lion ... imap is installed and enabled by default It also includes 3 versions of php out of the box Davids-Mac-mini:~ dgobrien$ ls /Applications/MAMP/bin/php/ php5.2.17/ php5.3.14/ php5.4.4/ Davids-Mac-mini:~ dgobrien$ /Applications/MAMP/bin/php/php5.4.4/bin/php-cgi -m [PHP Modules] bcmath bz2 calendar cgi-fcgi Core ctype curl date dom ereg exif fileinfo filter ftp gd gettext hash iconv imap json ldap libxml mbstring mcrypt mysql mysqli openssl pcre PDO pdo_mysql pdo_pgsql pdo_sqlite pgsql Phar posix Reflection session SimpleXML soap sockets SPL sqlite3 standard tokenizer XCache xml xmlreader xmlwriter xsl yaz zip zlib [Zend Modules] XCache Should be trivial to add that executable to your path for command line stuff
Re: [PHP] Regex
On Fri, Jul 27, 2012 at 10:16 AM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: Simon Dániel simondan...@gmail.com wrote: #[0-9a-zA-Z,\.]# You should escape out that period as it will match any character otherwise The dot only matches a period inside a character class [...]. David
Re: [PHP] Re: Regex
On Fri, Jul 27, 2012 at 11:43 AM, Al n...@ridersite.org wrote: %[\w\d,.]% \w will match digits so \d isn't necessary, but it will also match underscores which isn't desired. David