Re: [PHP] 304 Not Modified header not working within a class
Camilo Sperberg wrote: Hi list, my first message here :) To the point: I'm programming a class that takes several CSS files, parses, compresses and saves into a cache file. However, I would like to go a step further and also use the browser cache, handling the 304 and 200 header types myself. Now, what is the problem? If I do it within a function, there is absolutely no problem, everything works like a charm. However, when I implement that same concept into my class, there is no way I can send a 304 Not Modified header, when the data is *over* ~100 bytes. Hi Camilo For what it is worth I have implemented cacheing in a class and for me the 304 not modified header gets sent fine ... some example headers output is below together with the relevant code snippet.. // See if client sent a page modified header to see if we can // just send a not modified header instead if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == self::$_gmmodtime) { header('HTTP/1.1 304 Not Modified'); return null; } if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == self::$_etag) { header('HTTP/1.1 304 Not Modified'); return null; } HTTP/1.x 304 Not Modified Date: Wed, 20 Jan 2010 07:21:32 GMT Server: Apache/2.2.11 (Ubuntu) Connection: Keep-Alive Keep-Alive: timeout=5, max=1000 Etag: 444fbd9951f540ec1b6928db864c10dc Expires: Sun, 24 Jan 2010 06:16:06 GMT Cache-Control: public, must-revalidate Vary: Accept-Encoding I hope it helps.. Regards Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] copy() method on objects
Paul M Foster wrote: [snip] There are cases where I strictly want a *copy* of $a stored in $b. In cases like this, I supply $a's class with a copy() method, and call it like this: $b = $a->copy(); Is this reasonable, or do people have a better/more correct way to do this? Paul http://fr.php.net/clone hth rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP Application Structre
On 10/05/2010 18:17, Ashley Sheridan wrote: It makes sense sometimes to have different files for different sections of a website. For example, blog.php, gallery.php, cart.php could deal with the blog, gallery and shopping cart sections for an artists website. Yes, it could all be achieved with one script handling everything, but sometimes when the areas of the site differ greatly, it results in a lot of extra code to deal with pulling in the right template and content parts. I've always favoured only including the code a page needs rather than a huge amount of stuff that it doesn't. this isn't necessarily true - the architecture I've developed uses a single dispatch script (works fine with the mod rewrite option 2 scenario as well) - this script does general checks/security/filters etc then simply determines what page/function the user wants from the request ($_GET/$_POST parameter) and passes control to the specific handler via including the relevant controller module. The controller module is responsible for which template is required and loads up specific classes needed to process the request etc so each module just loads its own stuff and nothing else so there's no overhead. This method also has a small extra benefit that the web server document root just has a very simple 2 liner script instead a myriad of php scripts... if the webserver is misconfigured then someone who sees the source code doesn't get to see much.. Just my 0.02 Euros Cheers Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] var_dump( (0 == 'heading') ) == TRUE ?!
On 15/05/2010 03:19, Daevid Vincent wrote: Can someone explain why an integer 0 compared to a string evaluates to boolean true?? var_dump( (0 == 'heading') ); Yet, var_dump( (1 == 'heading') ); Is FALSE. WTF? I would expect the 0 one to be FALSE too. http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion IMO this is a pretty well known gotcha of PHP - you need to use === to check type as well as value Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Security Issue
On 07/06/2010 20:00, Igor Escobar wrote: PHP Injection is the technical name given to a security hole in PHP applications. When this gap there is a hacker can do with an external code that is interpreted as an inner code as if the code included was more a part of the script. // my code... // my code... include ('http:///externalhackscript.txt'); //my code... //my code.. can you not switch off remote file includes in php.ini? This will stop include/require from a remote host.. i.e. /allow_url_include = Off in php.ini HTH Rich / -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with DATE 2010-10-31
On 12/10/2010 11:52, Rado Oršula wrote: I do not know good English. In the attached source code. Here is erroneous statement: date: 2010-10-31 00:00:00 date+*0*h: 2010-10-31 *00*:00:00 date+*1*h: 2010-10-31 *01*:00:00 *date+2h: 2010-10-31 02:00:00 <<< date+3h: 2010-10-31 02:00:00 <<<* date+*4*h: 2010-10-31 *03*:00:00 [snip] probably at that time the Daylight Savings Time change kicks in ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: strtotime
On 17/10/2010 21:34, John Taylor-Johnston wrote: Yaay, I'm 45 now :). Here is another nifty piece of code I found. How does this work? What is 31556926? number of seconds in a year...? Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Possible foreach bug; seeking advice to isolate the problem
On 20/10/2010 05:47, Jonathan Sachs wrote: I've got a script which originally contained the following piece of code: foreach ( $objs as $obj ) { do_some_stuff($obj); } When I tested it, I found that on every iteration of the loop the last element of $objs was assigned the value of the current element. I was able to step through the loop and watch this happening, element by element. Are you are using a 'referencing' foreach? i.e. foreach ($objs as &$obj) { do_some_stuff($obj); } or is the above code a direct lift from your script? Referencing foreach statements can cause problems as the reference to the last array entry is persistent after the foreach loop has terminated so any further foreach statements on the same array will overwrite the previous reference which is still pointing to the last item. Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML to Array
On 10/03/2013 11:47, Karl DeSaulniers wrote: Hi Guys, I am hoping someone can guide me or help me fix this issue. I have been lost in the code for some time now. I am trying to get the attributes of an xml node. I have this code: [snip] this may help -> http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing I do admit I haven't the foggiest idea what I am doing here, so I am noobing out here on how this php function is really working. I got it off php.net and am trying to implement it in my code. Without my addition it works well except it doesn't grab any attributes which I need in order for my script to work properly. Any ideas on what I am doing wrong? TIA, HTH rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable type - conversion/checking
On 15/03/2013 22:00, Ashley Sheridan wrote: On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote: For my money, `is_numeric()` does just what I want. The thing is, is_numeric() will not check if a string is a valid int, but any valid number, including a float. For something like this, wouldn't a regex be better? if(preg_match('/^\-?\d+$/', $string)) echo int I'm late in on this thread so apologies if I have missed something here .. but wouldn't is_int() do what the OP wants? rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP] PHP is Zero
On 13/06/2013 11:44, BUSCHKE Daniel wrote: Hi, thanks for your answer. Especially the answer "42" made me laughing :) My "Why" questions should be understand as "Why must it be like that" questions. On 13/06/13 08:59, BUSCHKE Daniel wrote: 5. Thats a bug I have opend: https://bugs.php.net/bug.php?id=51739 where I also had the same problems because "8315e839da08e2a7afe6dd12ec58245d" was converted into float(INF) by throwing everything starting from "da08.." away. That's a very different proposition, and probably has more to do with word size: float is 32-bit, so only the first 32 bits are used and if anything else is found the conversion falls back to INF. To handle really big integers like 8315e839da08e2a7afe6dd12ec58245d you probably need a more specialist library (or language) For me it is not. PHP throws things away during conversion. In my opinion a language (compiler, interpreter whatever) should not do that. Never ever! Either it is able to convert the value or it is not. What about of returning "null" instead of "0" if the conversion is not perfect? So intval('F') could return NULL and intval('0') could return 0. Regards Daniel I think you will have to live with this or use another language for development - IMO it will never change because of the massive BC break that would be produced by changing the type juggling behaviour... of course you could always post an RFC to the dev/internals list if you want to take this further... good luck with that! Cheers Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to extract php source code from joomla
On 23/07/2013 16:54, Yoinier Hernandez Nieves wrote: El 22/07/13 15:49, elk dolk escribió: Thank you for the quick response ! What I am trying to do : I have to complete two university projects for my professor ! project One : Make an online shop and must use the following components in it Shopping cart, Catalog of products, payment gateway , user login and user activity log . You can use Prestashop, Magento, Oscommerce, etc, and modify at you're needed. IMO do NOT use Oscommerce (or the ZenCart fork for that matter) ... unless you want a lesson in how not to write an application in PHP... the code and architecture is (well it was the last time I had the dubious pleasure of working with it...) truly awful Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ambiguous?
On 09/08/2013 14:00, Karl-Arne Gjersøyen wrote: 1) query foreach($varenr_inn_pa_lager as $vnr){ include('../../tilkobling.php'); $sql = "SELECT * FROM exan,dynamit WHERE varenr = '$vnr' LIMIT 1"; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); 2) Result: Column 'varenr' in where clause is ambiguous 3) Tables in MySQL database mysql> SELECT * FROM exan; ++-+---+--+--+-+ | leverandor | valgt_lager | un_nr | varenavn | varenr | kg_pa_lager | ++-+---+--+--+-+ mysql> SELECT * FROM dynamit; ++-+---++---+-++-+ | leverandor | valgt_lager | type | dim_mm | un_nr | varenavn| varenr | kg_pa_lager | ++-+---++---+-++-+ 4) My question: What means with "ambiguous" here? Thanks. Karl a field named 'varenr' exists in both tables - your sql query needs to specify from which table you are selecting the data. foreach($varenr_inn_pa_lager as $vnr){ include('../../tilkobling.php'); $sql = "SELECT * FROM exan,dynamit WHERE varenr = '$vnr' LIMIT do you really need to include the file 'tilkobling.php' repeatedly for each iteration over $varenr_inn_pa_lager?? Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $_POST variable
On 11/03/2011 20:28, Danny wrote: Hi guys, I have a form that has a long list of radio-bottons inside of it. The radio-buttons are dynamically created via php and MySQL. Here is an example of one of the radio buttons: " value="0"> " value="1"> Now, when I submit this form to another page for processing, how would I "catch" the above radio-button's $_POST name since I do not know the name, only that it starts with "radio_" ? foreach ($_POST as $k => $v) { if (substr($k,0,6) == 'radio_') { echo 'Name is -> ',$k,''; // Do stuff... } } HTH Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: $_POST variable
You could use foreach to iterate through the post variables until you encounter a match: foreach ($_POST as $key => $value){ if (substr($key, 0, 6) == "radio_") { $buttonName = $key; $buttonValue = 4value; break 2; } } I haven't tried the above code, but I hope someone will correct my efforts if I'm wrong. given your code example -> 'break 2;' -- s/b just 'break;' ... 'break 2;' is to exit the outer loop of a nested loop which is not the case here. Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP/ Soap issue
I am hoping there's a SOAP expert on the list as this is driving me mad and Google doesn't come up with much help ... I am trying to build a fairly simple web service in SOAP -- the client sends a string SKU to query a product catalogue database and receives product pricing data - I am using a WSDL file which validates OK ... anyway I keep getting this error:- SOAP-ERROR: Encoding: object has no 'name' property The PHP code is below:- $client = new SoapClient('http://example.com/catalogue.wsdl',array('trace' => 1,'exceptions' => 0)); $sku = '12345'; $client->getProduct($sku); I can post the wsdl file contents if necessary. Hoping someone can help point me in the right direction! TIA Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/ Soap issue
On 01/09/2011 14:07, Louis Huppenbauer wrote: I think it would be best if you could provide us with the .wsdl (and possibly with the server-code). Thanks for the quick response Louis.. WSDL http://example.com/catalogue.wsdl"; xmlns="http://schemas.xmlsoap.org/wsdl/"; xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"; xmlns:tns="http://example.com/catalogue.wsdl"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsd1="http://example.com/schema";> http://example.com/schema"; xmlns="http://www.w3.org/2001/XMLSchema";> http://schemas.xmlsoap.org/soap/http"/> http://schemas.xmlsoap.org/soap/encoding/"; namespace="urn:examples:CatalogueService" use="encoded"/> http://schemas.xmlsoap.org/soap/encoding/"; namespace="urn:examples:CatalogueService" use="encoded"/> http://example.com/api/catalogue"/> SERVER CODE ini_set('soap.wsdl_cache_enabled',false); $server = new SoapServer('http://example.com/catalogue.wsdl'); $server->handle();
Re: [PHP] PHP/ Soap issue
On 01/09/2011 14:16, Richard Quadling wrote: Can you give me the URL for the WSDL file? Either online or by direct email. Thanks for the quick response Richard -- I have just posted the WSDL in my earlier resply to Louis... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP script won't run in the background
Hi all Hope someone can help me with a weird issue I have... I am trying to run a php CLI script in the background and it just won't run - it has a status of Stopped SIGTOU (Trying to write output) - Here are the details OS Mac OS X Lion 10.7.2 PHP PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep 8 2011 19:34:00) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies I created a basic script test.php Here are the results of various tests:- Test 1) php -f test.php (Hello world gets displayed) Test 2) php -f test.php >test.log 2>&1 (Hello world gets put into test.log) Test 3) php -f test.php >test.log 2>&1 & --- I get [1]+ Stopped(SIGTTOU)php -f test.php > test.log 2>&1 -- and the job just sits there doing nothing nothing gets logged however lsof shows the log file is open It is something to do with php because a similar shell script gets executed no problems in the background... This has me stumped ... any ideas? TIA Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
On 19/11/2011 16:09, Laruence wrote: $ stty -tostop makes no difference # stty -tostop # php -f test.php >test.log 2>&1 & # jobs # [1]+ Stopped(SIGTTOU)php -f test.php > test.log 2>&1 Any other ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
Laruence, while that may be a helpful answer to a few people in the know, just replying back with a single line like that isn't really going to help the people who are having this problem. At least explain why you suggested that, or what it does for those on the list that don't know, especially as it's not a PHP thing, it's a Unix command thing. Richard, some more info on the command Laruence mentioned can be found at http://docstore.mik.ua/orelly/unix/upt/ch12_07.htm which explains it in more detail. not sure this is relevant as my script is not trying to write to the terminal the >test.log 2>&1 is sending stdout and stderr to the log file not the tty... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
On 22/11/2011 05:51, Laruence wrote: did you run php with readline? try run the script without php-readline. thanks No - the script was just a basic string echo - no readline was involved. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
On 23/11/2011 11:05, Laruence wrote: Hi: I mean, do you built your php with readline support, or do you load readline.so into PHP? if so, remove it, then try again. and you also can use: gdb --pid={the pid of the stopped php} then you will find where the php hangs. thanks I didn't build PHP as it fails to make -- see https://bugs.php.net/bug.php?id=60268 so I am stuck with the PHP build provided by Apple... :( Here's what gdb says [rich@LeMans] (/web/scripts)> php -f test.php >test.log 2>&1 & [1] 3513 [rich@LeMans] (/web/scripts)> [1]+ Stopped php -f test.php > test.log 2>&1 [rich@LeMans] (/web/scripts)> gdb --pid 3513 GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin". /Web/scripts/3513: No such file or directory Attaching to process 3513. Reading symbols for shared libraries . done Reading symbols for shared libraries done Reading symbols for shared libraries + done 0x000101d057ee in __ioctl () Any clues? To me it looks like PHP cli is trying to do some I/O but I'm just a dumb developer... :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
On 29/11/2011 17:16, Daniel Brown wrote: On Sat, Nov 19, 2011 at 09:33, richard gray wrote: This happens because PHP is writing to STDOUT, of course, and then the command line redirection grabs that information and puts it into the file. Unfortunately, by itself, this won't work in the background, which is why you're getting the SIGTTOU (SIGnal TTy OUput). If you need to redirect the output and have it run in the background (where something like file_put_contents() or fwrite() isn't a practical option), give it a NOHUP (NO Hang-UP): nohup php test.php > test.log & This will automatically redirect STDERR to STDOUT, save for the message telling you the same. Thanks for your reply Daniel unfortunately nohup makes no difference the script still stops with no output being logged -- and also on a different machine (Ubuntu) php -f test.php >test.log 2>&1 & -- works perfectly - seems to be an issue with OSX Lion and the version of PHP that came with the machine -- I cannot compile my own build of PHP because of this problem -> https://bugs.php.net/bug.php?id=60268 -- so I am completely stuck :( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
On 23/11/2011 18:49, Alain Williams wrote: On Wed, Nov 23, 2011 at 06:14:07PM +0100, richard gray wrote: Reading symbols for shared libraries + done 0x000101d057ee in __ioctl () Any clues? To me it looks like PHP cli is trying to do some I/O but I'm just a dumb developer... :) ioctl on a tty is typically used to set it into single character at a time mode (remove stty's icanon). It could have decided that since it is a tty then that should be set. You need a bit more info, get a backtrace with 'where'. Thanks for the response Alain - below is the output:- [rich@LeMans] (/Web/scripts)> gdb --pid=3294 GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin". /Web/scripts/3294: No such file or directory Attaching to process 3294. Reading symbols for shared libraries . done Reading symbols for shared libraries done Reading symbols for shared libraries + done 0x7fff8f8ac7ee in __ioctl () (gdb) where #0 0x7fff8f8ac7ee in __ioctl () #1 0x7fff8f8ac1fe in ioctl () #2 0x7fff910a6b1c in tcsetattr () #3 0x00010ab05df7 in tty_end () #4 0x00010ab05c39 in tty_init () #5 0x00010aaf7261 in el_init () #6 0x00010aafeb8e in rl_initialize () #7 0x00010a3ef39a in zm_startup_readline () #8 0x00010a37a1c8 in zend_startup_module_ex () #9 0x00010a38166b in zend_hash_apply () #10 0x00010a37d3dd in zend_startup_modules () #11 0x00010a3287bf in php_module_startup () #12 0x00010a3ef637 in php_cli_startup () #13 0x00010a3efff8 in main () -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to find where class is used?
On 06/01/2012 12:11, Dotan Cohen wrote: In a large application that I am tasked with maintaining (vBulletin) there is a particular class that is used: vB_ProfileBlock_VisitorMessaging. I know the file that it is defined in, but I cannot find the file that actually creates a vB_ProfileBlock_VisitorMessaging object. I tried the brute-force grep approach, but the only place where I see the class mentioned is in the class declaration itself: [dev@localhost forum]$ grep -ir "vB_ProfileBlock_VisitorMessaging" * includes/class_profileblock.php:class vB_ProfileBlock_VisitorMessaging extends vB_ProfileBlock I know that this class is used as there is a page that is obviously using it. I have tried playing be-the-PHP-parser with that file, but it goes on to include() about a dozen other files, each of which include() another dozen files! This server does not and cannot have a debugger. What else can I do to find where this class object is created? Thanks. Can you not put a debug_print_backtrace() in the class constructor? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php