Re: [PHP] Foreach and mydql_query problem
On 07/22/2013 04:39 AM, Karl-Arne Gjersøyen wrote: Might I suggest that you place your include for ../../tilkobling.php at the very top of this page? It would save you from possibly including it twice. // The acutual source code is below: // == if(!empty($_POST['antall_kolli'])){ include('../../tilkobling.php'); --- remove this line foreach($antall_kolli as $kolli){ echo $kollibr; //echo $kolli. br; $sql = UPDATE transportdokument SET antall_kolli_stk = '$kolli' WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'; mysql_query($sql,$tilkobling) or die(mysql_error()); } Your WHERE conditions are the same, that is why it is updating a single row. Where are $dagens_dato and $brukernavn being defined? As others have stated, you need to include a unique identifier in your query so your query updates a specific record. } // THE PHP/HTML Form below: include('../../tilkobling.php'); --- move this to the top of the script $sql = SELECT * FROM transportdokument WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat, MYSQL_ASSOC)){ $valgt_lager = $rad['valgt_lager']; $un_nr = $rad['un_nr']; $sprengstofftype = $rad['sprengstofftype']; $varenavn = $rad['varenavn']; $varenr = $rad['varenr']; $antall_kolli = $rad['antall_kolli_stk']; $adr_vekt_kg = $rad['adr_vekt_kg']; $varenavn = $rad['varenavn']; $emb = $rad['emb']; ? tr td align=left valign=top?php echo $un_nr; ?/td td align=left valign=topstrongSprengstoff/strong,?php echo $sprengstofftype; ?/td td align=left valign=top?php echo $varenavn; ?/td td align=left valign=topstrong1.1D/strong/td td align=left valign=topnbsp;/td td align=left valign=top?php echo $emb; ?/td td align=left valign=top input type=hidden name=varenr[] value=?php echo $varenr; ? input type=number name=antall_kolli[] size=6 value=?php echo $antall_kolli; ? required=required /td td align=left valign=topinput type=text name=exan_kg_ut[] size=6 value=?php echo $adr_vekt_kg; ? required=required/td /tr ?php $total_mengde_kg_adr += $rad['adr_vekt_kg']; $total_antall_kolli += $rad['antall_kolli_stk']; } ? -- 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
Re: [PHP] query order issue
On 7/20/2013 9:21 AM, dealTek wrote: Hi all, I have a page that starts with several mysql sql query searches and displays data below... then I added a form (with hidden line do-update value UPDATE) on the same page with action to same page... then above other sql queries - I put... if ((isset($_POST[do-update])) ($_POST[do-update] == update)) { ---do update query--- echo 'meta http-equiv=refresh content=0; url=gohere.php'; By your description of what you think should be happening in the line above, my suggestion to would be to look at the header() function in PHP. It can send a header to the browser that will cause the browser to stop loading the current page and redirect it to another URL. http://php.net/header if ( ... ) { Do some work... header('Location: someotherpage.php'); exit(); } You want to make sure you always call exit(); after issuing a call to header('Location: ...'); } but it shows error that happens AFTER the meta http-equiv=refresh has happened Catchable fatal error: xxx on line 226 BTW - the meta http-equiv=refresh does work but the error flashes 1st for a second... Q: I would have thought that it would not go past the line - meta http-equiv=refresh - but it does any insight on this -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error checking ON
On 07/17/2013 09:28 AM, Tedd Sperling wrote: On Jul 17, 2013, at 11:55 AM, Daniel Brown danbr...@php.net wrote: On Wed, Jul 17, 2013 at 11:49 AM, Tedd Sperling t...@sperling.com wrote: This is what I do for error checking: ini_set('error_reporting', E_ALL | E_STRICT); ini_set('display_errors', 'On'); ini_set('log_errors', 'On'); ini_set('error_log', 'error_log'); Is this: 1. Sufficient? 2. An overkill? 3. OK? 4. OR, better served with this (and provide an example). That's standard practice. Sometimes, though, it isn't enough, and we find ourselves using Derick's Xdebug, mod_top, or performing an strace on either the execution or attached to a process. For nearly all cases, though, that's sufficient without being overkill (except for production cases). Daniel: Thanks -- I always wondered about that. Cheers, tedd PS: Of course, turned OFF for production. :-) _ t...@sperling.com http://sperling.com But... It won't work in all cases. I find it best to set these settings in the server itself. Not in code. Sometimes, if you have broken code that cannot be parsed, your commands listed above will never be executed. Therefor they will never do any good. -- 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
Re: [PHP] Reseting the auto-increment number in a MySQL database.
On 06/26/2013 10:07 AM, Tedd Sperling wrote: Hi gang: I have a client where their next auto-increment number just jumped from 2300 to 10 for reasons not understood. They want it set back. Options such as dropping the primary key and rebuilding the index is NOT possible -- this is a relational table thing. So, is there a way (programmatically) to set the next number in an auto-increment? Something like: alter table abc auto_increment = 2301; Any ideas of why this happened? Cheers, tedd _ t...@sperling.com http://sperling.com If mysql logging is turned on, you might be able to rummage through the logs and see what happened and when it happened. -- 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
Re: [PHP] undef func - any more clues ?
On 5/13/2013 11:32 PM, georg wrote: Thanks ! yum install php-odbc really did the trick. Now Im stuck where connect gives an error in apache error_log that it cannot find file /lib/libmimerodbc.so which is evidently there in exactly that place (as given in odbcini.ini for driver definition) ! A bit unexpected. (possibly an error in errorhandling ?, i.e. other cause) So, the file /lib/libmimerodbc.so exists? If it does and Apache cannot access it, then it might be permissions. Make sure it is readable by httpd. And that your httpd is not setup in a chroot environment. /georg - Original Message - From: Jim Lucas li...@cmsws.com To: georg georg.chamb...@telia.com Cc: a...@ashleysheridan.co.uk; php-general@lists.php.net Sent: Tuesday, May 14, 2013 3:25 AM Subject: Re: [PHP] undef func - any more clues ? On 05/12/2013 10:34 AM, georg wrote: Hi Im not really following, I have done: pecl list-all ; but dont find anything that has to do with ODBC so still stuck with Apache error log saying : no such function (or eqiv speak) odbc_connect() tnx Georg I am using a CentOS 6.4 system as a work station. So, with that said, the systems are similar, but still different enough that you need to make a few changes regarding the package names to get things working. I also have Apache installed the I develop with. These are the steps that I performed, and the order I performed them in, to get odbc working at the CLI and with Apache. Here first is an example of what I got when trying to call odbc_connect() without the proper packages installed from the CLI. [root@jim ~]# php -r odbc_connect(); PHP Fatal error: Call to undefined function odbc_connect() in Command line code on line 1 Fatal error: Call to undefined function odbc_connect() in Command line code on line 1 Search for the correct package. [root@jim ~]$ yum list php* | grep -i odbc php-odbc.x86_64 5.3.3-22.el6 base Install found package... (change the package name if needed) [root@jim ~]# yum install php-odbc ... Total download size: 428 k Installed size: 1.2 M Is this ok [y/N]: y ... Running Transaction Installing : unixODBC-2.2.14-12.el6_3.x86_64 1/2 Installing : php-odbc-5.3.3-22.el6.x86_64 2/2 Verifying : php-odbc-5.3.3-22.el6.x86_64 1/2 Verifying : unixODBC-2.2.14-12.el6_3.x86_64 2/2 Installed: php-odbc.x86_64 0:5.3.3-22.el6 Dependency Installed: unixODBC.x86_64 0:2.2.14-12.el6_3 Complete! Update your locate database [root@jim ~]# updatedb Search for the recently installed package [root@jim ~]# locate odbc.so | grep php /usr/lib64/php/modules/odbc.so /usr/lib64/php/modules/pdo_odbc.so Re-run the first test - ah it is found... [root@jim ~]# php -r odbc_connect(); PHP Warning: odbc_connect() expects at least 3 parameters, 0 given in Command line code on line 1 Warning: odbc_connect() expects at least 3 parameters, 0 given in Command line code on line 1 Once you have this, you know that everything in place to get it working with Apache. Now to test in the web server. This is what I received when I viewed my test script via Apache and my browser. URL: http://localhost/odbc_test.php Fatal error: Call to undefined function odbc_connect() in /var/www/html/odbc_test.php on line 3 Now, to get it working with Apache, all I had to do was restart the web server. [root@jim html]# service httpd restart Stopping httpd:[ OK ] Starting httpd:[ OK ] Now, refreshing the above page gives me this. Warning: odbc_connect() expects at least 3 parameters, 0 given in /var/www/html/odbc_test.php on line 3 So, it is now working. Review my steps above, make sure you perform them as I did and you should be working when you are done. Let us know if you need anything further. -- 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
Re: [PHP] undef func - any more clues ?
On 05/12/2013 10:34 AM, georg wrote: Hi Im not really following, I have done: pecl list-all ; but dont find anything that has to do with ODBC so still stuck with Apache error log saying : no such function (or eqiv speak) odbc_connect() tnx Georg I am using a CentOS 6.4 system as a work station. So, with that said, the systems are similar, but still different enough that you need to make a few changes regarding the package names to get things working. I also have Apache installed the I develop with. These are the steps that I performed, and the order I performed them in, to get odbc working at the CLI and with Apache. Here first is an example of what I got when trying to call odbc_connect() without the proper packages installed from the CLI. [root@jim ~]# php -r odbc_connect(); PHP Fatal error: Call to undefined function odbc_connect() in Command line code on line 1 Fatal error: Call to undefined function odbc_connect() in Command line code on line 1 Search for the correct package. [root@jim ~]$ yum list php* | grep -i odbc php-odbc.x86_64 5.3.3-22.el6 base Install found package... (change the package name if needed) [root@jim ~]# yum install php-odbc ... Total download size: 428 k Installed size: 1.2 M Is this ok [y/N]: y ... Running Transaction Installing : unixODBC-2.2.14-12.el6_3.x86_64 1/2 Installing : php-odbc-5.3.3-22.el6.x86_64 2/2 Verifying : php-odbc-5.3.3-22.el6.x86_64 1/2 Verifying : unixODBC-2.2.14-12.el6_3.x86_64 2/2 Installed: php-odbc.x86_64 0:5.3.3-22.el6 Dependency Installed: unixODBC.x86_64 0:2.2.14-12.el6_3 Complete! Update your locate database [root@jim ~]# updatedb Search for the recently installed package [root@jim ~]# locate odbc.so | grep php /usr/lib64/php/modules/odbc.so /usr/lib64/php/modules/pdo_odbc.so Re-run the first test - ah it is found... [root@jim ~]# php -r odbc_connect(); PHP Warning: odbc_connect() expects at least 3 parameters, 0 given in Command line code on line 1 Warning: odbc_connect() expects at least 3 parameters, 0 given in Command line code on line 1 Once you have this, you know that everything in place to get it working with Apache. Now to test in the web server. This is what I received when I viewed my test script via Apache and my browser. URL: http://localhost/odbc_test.php Fatal error: Call to undefined function odbc_connect() in /var/www/html/odbc_test.php on line 3 Now, to get it working with Apache, all I had to do was restart the web server. [root@jim html]# service httpd restart Stopping httpd:[ OK ] Starting httpd:[ OK ] Now, refreshing the above page gives me this. Warning: odbc_connect() expects at least 3 parameters, 0 given in /var/www/html/odbc_test.php on line 3 So, it is now working. Review my steps above, make sure you perform them as I did and you should be working when you are done. Let us know if you need anything further. -- 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
Re: [PHP] Updated PHP breaks processing-intense Procedure
On 04/24/2013 02:40 PM, Ken Kixmoeller wrote: Thanks so much. Yes, we found that because PHP threw an error that said that explicitly. A bit of research led us to add a line to php.ini to set the max_input_vars to a higher level. At first, that appeared to fix it (on the development machine). The appearance is wrong; it is still broken. No errors are being thrown. We are baffled. Ken If you have the Suhosin patch installed, it also introduces other limits to GET and POST variable counts within PHP. -- 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
Re: [PHP] Updated PHP breaks processing-intense Procedure
On 04/24/2013 03:24 PM, Ken Kixmoeller wrote: Thanks, Jim --- Is this different from the max_input_vars discussion above? (from David OBrien) yes. For example... php.ini:[suhosin] php.ini:;suhosin.log.syslog = php.ini:;suhosin.log.syslog.facility = php.ini:;suhosin.log.syslog.priority = php.ini:;suhosin.log.sapi = php.ini:;suhosin.log.script = php.ini:;suhosin.log.phpscript = 0 php.ini:;suhosin.log.script.name = php.ini:; variables registered in the current scope: SUHOSIN_ERRORCLASS and php.ini:; SUHOSIN_ERROR. The first one is the alert class and the second variable is php.ini:;suhosin.log.phpscript.name = php.ini:;suhosin.log.phpscript.is_safe = Off php.ini:;suhosin.log.use-x-forwarded-for = Off php.ini:;suhosin.executor.max_depth = 0 php.ini:;suhosin.executor.include.max_traversal = 0 php.ini:;suhosin.executor.include.whitelist = php.ini:;suhosin.executor.include.blacklist = php.ini:;suhosin.executor.func.whitelist = php.ini:;suhosin.executor.func.blacklist = php.ini:;suhosin.executor.eval.whitelist = php.ini:;suhosin.executor.eval.blacklist = php.ini:;suhosin.executor.disable_eval = Off php.ini:;suhosin.executor.disable_emodifier = Off php.ini:; by default in Suhosin = 0.9.6. Allowing symlink() while open_basedir is used php.ini:;suhosin.executor.allow_symlink = Off php.ini:; If you fear that Suhosin breaks your application, you can activate Suhosin's php.ini:; simulation mode with this flag. When Suhosin runs in simulation mode, php.ini:;suhosin.simulation = Off php.ini:; first. It always uses resource slot 0. If Suhosin got this slot assigned APC php.ini:; will overwrite the information Suhosin stores in this slot. When this flag is php.ini:; set Suhosin will request 2 Slots and use the second one. This allows working php.ini:;suhosin.apc_bug_workaround = Off php.ini:;suhosin.sql.bailout_on_error = Off php.ini:;suhosin.sql.user_prefix = php.ini:;suhosin.sql.user_postfix = php.ini:;suhosin.multiheader = Off php.ini:suhosin.mail.protect = 1 php.ini:; memory_limit to whatever value they want. Suhosin changes this fact and php.ini:; that Suhosin will disallows scripts setting the memory_limit to a value above php.ini:;suhosin.memory_limit = 0 php.ini:suhosin.session.encrypt = Off php.ini:;suhosin.session.cryptkey = php.ini:;suhosin.session.cryptua = On php.ini:;suhosin.session.cryptdocroot = On php.ini:;suhosin.session.cryptraddr = 0 php.ini:; session. The difference to suhosin.session.cryptaddr is, that the IP is not php.ini:;suhosin.session.checkraddr = 0 php.ini:;suhosin.cookie.encrypt = 0 php.ini:;suhosin.cookie.cryptkey = php.ini:;suhosin.cookie.cryptua = On php.ini:;suhosin.cookie.cryptdocroot = On php.ini:;suhosin.cookie.cryptraddr = 0 php.ini:; cookie. The difference to suhosin.cookie.cryptaddr is, that the IP is not php.ini:;suhosin.cookie.checkraddr = 0 php.ini:;suhosin.cookie.cryptlist = php.ini:;suhosin.cookie.plainlist = php.ini:; Defines the reaction of Suhosin on a filter violation. php.ini:;suhosin.filter.action = php.ini:;suhosin.cookie.max_array_depth = 50 php.ini:;suhosin.cookie.max_array_index_length = 64 php.ini:;suhosin.cookie.max_name_length = 64 php.ini:;suhosin.cookie.max_totalname_length = 256 php.ini:;suhosin.cookie.max_value_length = 1 php.ini:;suhosin.cookie.max_vars = 100 php.ini:;suhosin.cookie.disallow_nul = 1 php.ini:;suhosin.get.max_array_depth = 50 php.ini:;suhosin.get.max_array_index_length = 64 php.ini:;suhosin.get.max_name_length = 64 php.ini:;suhosin.get.max_totalname_length = 256 php.ini:;suhosin.get.max_value_length = 512 php.ini:;suhosin.get.max_vars = 100 php.ini:;suhosin.get.disallow_nul = 1 php.ini:;suhosin.post.max_array_depth = 50 php.ini:;suhosin.post.max_array_index_length = 64 php.ini:;suhosin.post.max_name_length = 64 php.ini:;suhosin.post.max_totalname_length = 256 php.ini:suhosin.post.max_value_length = 2048000 php.ini:suhosin.post.max_vars = 500 php.ini:;suhosin.post.disallow_nul = 1 php.ini:;suhosin.request.max_array_depth = 50 php.ini:;suhosin.request.max_array_index_length = 64 php.ini:;suhosin.request.max_totalname_length = 256 php.ini:suhosin.request.max_value_length = 2048000 php.ini:;suhosin.request.max_vars = 200 php.ini:;suhosin.request.max_varname_length = 64 php.ini:;suhosin.request.disallow_nul = 1 php.ini:;suhosin.upload.max_uploads = 25 php.ini:;suhosin.upload.disallow_elf = 1 php.ini:;suhosin.upload.disallow_binary = 0 php.ini:;suhosin.upload.remove_binary = 0 php.ini:;suhosin.upload.verification_script = php.ini:;suhosin.session.max_id_length = 128 php.ini:; Undocumented: Controls if suhosin coredumps when the optional suhosin patch php.ini:;suhosin.coredump = Off php.ini:;suhosin.protectkey = 1 php.ini:; Controls if suhosin loads in stealth mode when it is not the only php.ini:;suhosin.stealth = 1 php.ini:; Controls if suhosin's ini directives are changeable per directory php.ini:;suhosin.perdir = 0 Ken On Wed, Apr 24, 2013 at 5:06 PM, Jim Lucas li...@cmsws.com wrote: On 04/24/2013 02:40 PM, Ken
Re: [PHP] variable type - conversion/checking
On 3/14/2013 4:05 PM, Matijn Woudt wrote: On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas li...@cmsws.com wrote: On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote: Something like if (is_numeric($var) $var == floor($var)) will do the trick. I don't know if there's a better (more elegant) way. On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudttijn...@gmail.com wrote: On Thu, Mar 14, 2013 at 7:02 PM, georggeorg.chamb...@telia.com** wrote: Hi, I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georg You could use is_numeric for that, though it also accepts floats. - Matijn for that type of test I have always used this: if ( $val == (int)$val ) { http://www.php.net/manual/en/**language.types.integer.php#** language.types.integer.castinghttp://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting I hope you're not serious about this... When comparing a string and an int, PHP will translate the string to int too, and of course they will always be equal then. So: $a = abc; if($a == (int)$a) echo YES; else echo NO; Will always return YES. - Matijn H... Interesting. Looking back at my code base where I thought I was doing that, turns out the final results were not that, but this: $value = asdf1234; if ( $value === (string)intval($value) ) { Looking back at the OP's request and after a little further searching, it seems that there might be a better possible solution for what the OP is requesting. ?php $values = array(asdf1234, 123.123, 123); foreach ( $values AS $value ) { echo $value; if ( ctype_digit($value) ) { echo ' - is all digits'; } else { echo ' - is NOT all digits'; } echo 'br /'.PHP_EOL; } returns... asdf1234 - is NOT all digits 123.123 - is NOT all digits 123 - is all digits http://www.php.net/manual/en/function.ctype-digit.php An important note: This function expects a string to be useful, so for example passing in an integer may not return the expected result. However, also note that HTML forms will result in numeric strings and not integers. See also the types section of the manual. -- Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable type - conversion/checking
On 03/15/2013 02:33 PM, richard gray wrote: 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 Nope, because the OP wants to test if a variable, that is a string, could be converted to an integer. Not if a variable is an integer. -- 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
Re: [PHP] variable type - conversion/checking
On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote: Something like if (is_numeric($var) $var == floor($var)) will do the trick. I don't know if there's a better (more elegant) way. On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudttijn...@gmail.com wrote: On Thu, Mar 14, 2013 at 7:02 PM, georggeorg.chamb...@telia.com wrote: Hi, I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georg You could use is_numeric for that, though it also accepts floats. - Matijn for that type of test I have always used this: if ( $val == (int)$val ) { http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting -- 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
Re: [PHP] Joining fixed text to a SUBJECT variable
On 3/2/2013 11:56 AM, tamouse mailing lists wrote: Ah, crikey, syntax error!! $Body ENDOFMAIL should be: $Body = ENDOFMAIL assignment operator necessary!! AND... it should have 3 instead of 2 http://www.php.net/manual/en/language.types.string.php \ #language.types.string.syntax.heredoc -- Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stupid question
On 02/26/2013 01:27 PM, Curtis Maurand wrote: I have the following: $dsn = mysqli://$username:$password@$hostname2/$database; $options = array( 'debug' = 3, 'result_buffering' = false, ); $dbh = MDB2::factory($dsn, $options); if (PEAR::isError($mdb2)) { die($mdb2-getMessage()); } function tallyCart($_u_id,$dbh){ while($row = $result-fetchrow(MDB2_FETCHMODE_ASSOC)) { Talking in code. The above two lines tell me... $dbh != $result isset($result) === false $_showCheckOut=1; $_pdetail=new ProductDetail($row{'product_ID'}, $row{'product_Quantity'}, $_u_id); $_getSubTotal += $_pdetail-_subTotal; $_counter++; } } I'm getting: Call to undefined method MDB2_Error::fetchrow() anyone have any ideas? Can I not pass a database handle to a function? Thanks, Curtis -- 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
Re: [PHP] Arrays
On 02/25/2013 05:40 PM, Karl DeSaulniers wrote: Hi Guys/Gals, If I have an multidimensional array and it has items that have the same name in it, how do I get the values of each similar item? EG: specialservices = array( specialservice = array( serviceid = 1, servicename= signature required, price = $4.95 ), secialservice = array( serviceid = 15, servicename = return receipt, price = $2.30 ) ) How do I get the prices for each? What would be the best way to do this? Can I utilize the serviceid to do this somehow? It is always going to be different per specialservice. TIA, Best, Karl DeSaulniers Design Drumm http://designdrumm.com This will never work. Your last array will always overwrite your previous array. Here is how I would suggest building it: $items = array( 1 = array( serviceid = 1, servicename= signature required, price = $4.95 ), 15 = array( serviceid = 15, servicename = return receipt, price = $2.30 ) ) This will ensure that your first level indexes never overwrite themselves. But, with that change made, then do this: foreach ( $items AS $item ) { if ( array_key_exists('price', $item) ) { echo $item['price']; } else { echo 'Item does not have a price set'; } } Resources: http://php.net/foreach http://php.net/array_key_exists -- 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
Re: [PHP] stripped \n
On 02/20/2013 10:16 AM, John Taylor-Johnston wrote: Hi, I have a textarea when submitted creates a new form with the textarea data in a hidden field: input name=DPRnarration type=text hidden form=DPRform value=Enter call narration here. But when this new form gets resubmitted, the \n get stripped? input name=DPRnarration type=text hidden form=DPRform value=Enter callnarration here. I don't get it. There is nothing in my code that is stripping the \n? input name=DPRnarration type=text hidden form=DPRform value=?php echo stripslashes($_POST[DPRnarration]);? Do I need to put it in another textarea and declare it hidden? Here is a quote: If the element is mutable, its value should be editable by the user. User agents must not allow users to insert LF (U+000A) or CR (U+000D) characters into the element's value. I found it on this page: http://www.w3.org/TR/html5/forms.html#text-%28type=text%29-state-and-search-state-%28type=search%29 Does that explain why your example doesn't work? -- 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
Re: [PHP] php5.3 exec() : output truncate
On 01/30/2013 10:14 AM, patrick ficheux wrote: Hi, I want to get the list of running processes. also, I call exec() with ps -A What user is your httpd process running as? run this from your cli: ps aux | grep httpd and show us the output -- 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
Re: [PHP] Boolean type forced on string assignment inside if statement
On 01/03/2013 09:25 AM, Marc Guay wrote: Hi Tedd, A little searching enlightened me to the fact that in other languages, a single | or operator will cancel the short-circuiting so all of the evaluations are done before proceeding. However, they don't seem to exist in PHP so in your example it behaves the same as ||...? http://php.net/manual/en/language.operators.logical.php Marc In PHP | is not a logical operator, it is a bitwise operator. It is used to flip bits in binary data. Not to be used in a logical condition statement. http://php.net/manual/en/language.operators.bitwise.php -- 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
Re: [PHP] date problem
On 01/03/2013 01:57 PM, Marc Fromm wrote: $jes = 01/03/2012; # php -r echo 01/03/2012; 0.00016567263088138 You might want to put quotes around that value so it is actually a string and does not get evaluated. -- 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
Re: [PHP] Boolean type forced on string assignment inside if statement
On 01/03/2013 11:43 AM, Andreas Perstinger wrote: is the bitwise and operator. So is a single pipe. http://php.net/manual/en/language.operators.bitwise.php -- 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
Re: [PHP] Boolean type forced on string assignment inside if statement
On 01/02/2013 07:53 AM, Marc Guay wrote: Hi folks, if ($a = foo $b = bar){ echo $a.br /.$b; } Returns: 1 bar I expect: foo bar Is this documented? Marc Why would you do this. I cannot envision a time or condition that would require such a test. Can you please explain why you would want to do this? Won't this type of condition/test always return true? -- 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
Re: [PHP] Boolean type forced on string assignment inside if statement
On 01/02/2013 10:21 AM, Marc Guay wrote: Won't this type of condition/test always return true? I simplified the example. In my real life case the foo and bar are variables which can be empty strings, and if they both are not, I would like to display them. Marc Then why not use empty()? $a = foo; $b = bar; if ( !empty($a) !empty($b) ){ echo $a.br /.$b; } The reason I ask is that what if one of your strings was a 0 (zero) I would expect your code would not work as you had intended. php -r 'if ( $a=foo $b=0 ) { echo \n\n{$a}\n{$b}\n\n; }' In my testing, it does not. I would then have to ask, how often do you think a string will be 0? -- 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
Re: [PHP] Nested loopa
On 12/25/2012 4:21 PM, Ken Arck wrote: So I cannot do nested do loops in php? ?php $a = 0 ; $b = 0 ; do { echo $a\n ; do { echo $b\n ; $b++ }while($b =10) ; $a++; }while($a = 20) ; ? You have a typo. Line 8 What are you expecting as output? -- Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] storing searching docs
On 12/13/2012 02:49 PM, Jim Giner wrote: Thanks for all the posts. After reading and googling all afternoon, I think the best approach for me is: Create two macros in Word (done!) to export each of my .doc files to .txt and .pdf formats. Create a sql table to hold the .txt contents of my .doc files, along with a reference to the meeting date and the name of the corresponding .pdf file. Upload my two sets of files with an ftp client and then use a script to load the table with my .txt file data. Now I just need a couple of scripts to allow a user to locate a file and bring up the pdf for when he wants to read about a meeting. And a second script to accept user input (search words) and perform a query against the textual data and present some kind of results - probably a listing containing a reference to the meeting date and a tbd-length string showing the matching result for each occurrence, ie, something like n chars in front of and after the match so the user can see the context of the match. Sizes - a 28k .doc file grows to 142kb in .pdf format and is only 5kb in .txt format. (actually, if I 'print' the .doc as a pdf instead of using the Word's File,Save as, the resulting pdf is only 70kb. Might need a new macro!) Thanks again! I wrote this script a few years ago that extracted the plain text out of the .doc file. http://www.cmsws.com/examples/applications/word2_/convert.php if you look in the directory you will see a few example files. You can view them like this. .../convert.php?filename=test_building.doc replace test_building.doc with any of the other .doc files from the dir listing to see its contents. I currently have it set to 64bit width rows. Show you some nice pattern stuff with the MS Word format. I have the source file viewable for the convert.php script as well. http://www.cmsws.com/examples/applications/word2_/convert.phps I have thought about extending this even further to figure out the layout and test formatting. But it hasn't gotten much attention for quite some time now. Hope it helps. -- 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
Re: [PHP] Php application with session used in a cluster
On 12/12/2012 05:19 AM, Jan Vávra wrote: Hello, we are considering to use a php on several application servers behind the apache mod_proxy_balancer. Our php app is using session cookies. And we would like to use session stickyness - once the user connects to app server X and gets the session cookie, all other request will be ballanced (reverse proxied) to the app server X. We have these theoretical possibilities: [...] Can anybody give me an advice? Why not use database driven sessions? Their are many examples on the net of how to setup such a system to replace the file based system used by default. Thanks. Jan. -- 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
Re: [PHP] how to read emails with php
On 12/04/2012 05:10 AM, Farzan Dalaee wrote: hi guys i want to open an email content ( subject ,body , attachment ) with php i use imap_php but its wont connect to host what should i do? thanx As others have suggested, try connecting using telnet from the same server you are running the PHP from. Here is a page I wrote a while back that shows you how to do this. http://bendsource.cmsws.com/serverSetup -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://bendsource.cmsws.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP site search broken?
On 12/04/2012 01:03 PM, Sebastian Krebs wrote: 2012/12/4 Paul M Fosterpa...@quillandmouse.com Is it just me, or is the search feature on php.net broken? When I enter a full search term (known good function name) and then hit the arrow, it brings me back to the generic search page. If I enter a partial search term and then click on one of the suggested completions, it usually (not always) does the same thing. Etc. Hi, Works fine here. You could try a different mirror? or a different browser? Regards, Sebastian Paul -- Paul M. Foster http://noferblatz.com http://quillandmouse.com -- 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
Re: [PHP] PDO question
On 11/28/2012 12:58 PM, ad...@buskirkgraphics.com wrote: Guys, I am not quiet sure what is happening but every time i try to connect to a remote host it refers back to localhost. $pdo = new PDO('mysql:host=171.16.23.44;dbname=test', 'user','password'); ERROR: Access denied for user 'user'@'localhost' (using password: YES) in /var/www/html/text.php Any clue as to WHY it keeps referring back to localhost when i clearly set the host parameter to another server. I checked the /etc/hosts records to see if there was a referral for that domain back to it's self there is NOT. There is a warning on the following page that talks about a possible issue with connections. Might give it a look. http://www.php.net/manual/en/ref.pdo-mysql.connection.php -- 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
Re: [PHP] CSV importer tool
On 11/27/2012 12:56 PM, Leandro Dardini wrote: Hello, I am going to write a PHP page to allow the client to upload a CSV file and assign each column to one or more fields of a mysql table. Quite simple, but I feel like I am reinventing the wheel... is it possible there is no library to do it, maybe using AJAX or similar cute techniques? Leandro google for: php csv importer script Reading the first result, it seems it is exactly what you are looking for. -- 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
Re: [PHP] Date comparison going wrong, wrong, wrong
On 11/12/2012 02:06 AM, Duken Marga wrote: Try this: $todaydate = strtotime(date(D, M jS, Y g:i:s a)); $showenddate = strtotime(date(D, M jS, Y g:i:s a, strtotime($showsRecord['end_date']))); Won't this give you the same results without the extra conversion steps? $todaydate = date(U); $showenddate = strtotime($showsRecord['end_date']); if ($todaydate $showenddate): echo The date of the show has not yet arrived; else: echo The show has ended; endif; You must convert both $todaydate and $showendate with strtotime() function, then you can compare them. On Mon, Nov 12, 2012 at 1:30 AM, Terry Ally (Gmail)terrya...@gmail.comwrote: Hi all, I am having a problem with comparing time. I am using the following: $todaydate = date(D, M jS, Y g:i:s a); $showenddate = date(D, M jS, Y g:i:s a, strtotime($showsRecord['end_date'])); if ($todaydate $showenddate): echo The date of the show has not yet arrived; else: echo The show has ended; endif; The problem that I am encountering is that PHP is rendering the reverse of the equation. For example: If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*, the message that I am getting is *the show has ended* which is wrong. A test example is at http://www.lakesidesurrey.co.uk/test.php. You can also me what I am doing wrong? Thanks Terry -- 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
Re: [PHP] memory allocation error
On 11/11/2012 08:45 AM, Carol Peck wrote: Hi all, I've been chasing around a memory allocation error for some time and can't figure it out. It is somewhat random - I can run the script 3 times and then it will happen, or sometimes the first time. It happens at the very end of a script, actually after the script has finished running. I will see the following after the closing /html tag: Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 494142432 bytes) in Unknown on line 0 Just previous to this my mem usage is 3772104 The script itself does some database work (deletes, inserts, selects) but nothing very heavy and writes out an XML file. I use adodb 5.18, the server is PHP 5.3.18 (this was updated recently) and it is a VPS on inmotionhosting.com. As you can see, the memory limit is 256M so it's really high and I never see that I'm using more than 4M. The error doesn't fall through my error class - I'm assuming that's because it is happening after the script is complete. I am completely out of ideas on how to trap it or figure it out. Any ideas would be appreciated! Try adding exit or die at the end of what you know is the end of your scripts. See if the problem continues. Maybe at the very end of your customer error handler. If the problem stops showing up, you might want to look at your PHP config to see if anything is setup in the auto_append_file section. -- 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
Re: [PHP] memory allocation error
On 11/12/2012 7:50 AM, Carol Peck wrote: Jim, Thanks for your idea - using die prevents it from coming up. As I mentioned, it is rather random so sometimes hard to verify. My auto_prepend and auto_append have no value in php.ini. I'm wondering why you suggested that? If something was injecting code using the auto_append param, then you would not know about it, but it would still cause you issues. And by issuing a die or exit at the end of the code would show if it was your code or something running after all your script has completed. Best, Carol On 11/12/2012 8:09 AM, Jim Lucas wrote: On 11/11/2012 08:45 AM, Carol Peck wrote: Hi all, I've been chasing around a memory allocation error for some time and can't figure it out. It is somewhat random - I can run the script 3 times and then it will happen, or sometimes the first time. It happens at the very end of a script, actually after the script has finished running. I will see the following after the closing /html tag: Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 494142432 bytes) in Unknown on line 0 Just previous to this my mem usage is 3772104 The script itself does some database work (deletes, inserts, selects) but nothing very heavy and writes out an XML file. I use adodb 5.18, the server is PHP 5.3.18 (this was updated recently) and it is a VPS on inmotionhosting.com. As you can see, the memory limit is 256M so it's really high and I never see that I'm using more than 4M. The error doesn't fall through my error class - I'm assuming that's because it is happening after the script is complete. I am completely out of ideas on how to trap it or figure it out. Any ideas would be appreciated! Try adding exit or die at the end of what you know is the end of your scripts. See if the problem continues. Maybe at the very end of your customer error handler. If the problem stops showing up, you might want to look at your PHP config to see if anything is setup in the auto_append_file section. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] memory allocation error
On 11/12/2012 8:54 AM, Carol Peck wrote: Jim, I just found that the die didn't fix it after all - just ran into it again. So still looking for ideas! thanks, Carol Then it must be something in either your code or the way PHP is doing some garbage collection with the libs you are using. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fwd: PHP Enterprise Bananas
On 11/06/2012 05:03 AM, Ben Edwards wrote: Not sure if this was some type of joke but came across it a while ago. We have some PHP we want to move from a site to a cron. Is this the answer or is there a better way (that does not involve re-writing code in another language). Cant find a home page for the project, maybe it is defunct. Ben I have scripts that get ran via crond and others that run 24/7 as daemons. I have no issues using PHP via the cli. Like Bastien said, you will want to setup better logging and maybe summary emails from cron would be useful too. -- 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
Re: [PHP] URGENT! Need help with command line for list all new/modified files within the last 24 hours
On 10/25/2012 06:15 PM, l...@afan.net wrote: Hi to all, My site with Drupal 7. I contacted tech support and he said he accessed to the site with FTP - what I doubt. But if it's truth - it's even worse because whole server is then compromised. I need help with command line for list all new/modified files within the last 24 hours. Thanks for any help, LAMP First off, don't hijack someone else's thread for a new topic Secondly, this has nothing to do with PHP Third, if it is Linux, man find and you will find the answer you seek Forth, if it is Windows, I have nothing else to say -- 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
Re: [PHP] Send php Mail not working in MAMP (non pro version)
On 10/17/2012 05:00 PM, Dave wrote: Make sure, if you happen to have install postfix as well, that it has replaced your sendmail. Then, from the cli, as your apache/php user, try sending an email using sendmail. # sendmail -v y...@email.com testing . Thanks a lot Jim for the help... sorry this is getting a bit above me... if you mean use the terminal I have a friend that can help me soon try to change user to apache/php user (not sure how yet) and test this ... Did it work? More then likely your php/apache process does not know where sendmail is or does not have permission to use it. Check in your php.ini file and see what is set as the sendmail_path Mine is set like this: ; For Unix only. You may supply arguments as well (default: sendmail -t -i). ;sendmail_path = As a standard user on my linux box I get this [jlucas@jim ~]$ which sendmail /usr/bin/which: no sendmail in (...) But as root, I get this [root@jim ~]# which sendmail /usr/sbin/sendmail So, make sure your apachephp user can see and execute sendmail -- Jim Lucas Ji Jim, in the mamp php.ini file I had set like the demo to: [mail function] ; For Win32 only. ;SMTP = localhost - these commented out as described ;smtp_port = 25 - these commented out as described ; For Win32 only. ;sendmail_from = m...@example.com ; For Unix only. You may supply arguments as well (default: sendmail -t -i). sendmail_path =/usr/sbin/sendmail -t -i -f m...@site.com From your terminal, you will need to verify that /usr/sbin/sendmail exists and can be called by your apache/php user. First off, make sure that sendmail is installed and functioning. I am not using sendmail that I know of. I didn't install anything - just the basic NON PRO MAMP Also I did not install postfix. and I am using the basic php function mail() You could get around using the mail function completely and use phpmailer or SwiftMail. They would allow you to talk directly to an outside SMTP server. In most cases, unless your web server happens to serve as your mail server, you would want to relay your message(s) through your official mail server. -- 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
Re: [PHP] Send php Mail not working in MAMP (non pro version)
On 10/17/2012 09:52 AM, Dave wrote: Hi all, MAC LION 10.7.4 latest MAMP (non pro version) I've tried various things - but php send mail not working in MAMP (non pro version) ... mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) the same script works on a hosted server... tried this but not working... viewtopic.php?f=2t=10722 seems like I need to add more data - somewhere in php.ini or the php sendmail script like authentication info of mailhost and user / pass and port etc maybe setting data here? --- [, string $additional_headers [, string $additional_parameters ]] - i don't know how.. I also posted this at mamp forum but there does not seem much action there... http://forum.mamp.info/viewtopic.php?f=2t=37583p=53515#p53515 First off, make sure that sendmail is installed and functioning. Make sure, if you happen to have install postfix as well, that it has replaced your sendmail. Then, from the cli, as your apache/php user, try sending an email using sendmail. # sendmail -v y...@email.com testing . ... Did it work? More then likely your php/apache process does not know where sendmail is or does not have permission to use it. Check in your php.ini file and see what is set as the sendmail_path Mine is set like this: ; For Unix only. You may supply arguments as well (default: sendmail -t -i). ;sendmail_path = As a standard user on my linux box I get this [jlucas@jim ~]$ which sendmail /usr/bin/which: no sendmail in (...) But as root, I get this [root@jim ~]# which sendmail /usr/sbin/sendmail So, make sure your apachephp user can see and execute sendmail -- 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
Re: [PHP] foreach
On 10/15/2012 05:16 PM, David McGlone 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_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. Code please. -- 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
[PHP] Ok then, here is a test
On 10/12/2012 11:42 AM, Daniel Brown wrote: Well, as the adage goes, you'll catch more flies with honey than with vinegar. And considering this is the very first message I've ever seen from you, it sounds like either (a) you didn't follow the proper protocol, or (b) there's something in the process we need to review. If you think the issue lies on our end, you can submit a bug at https://bugs.php.net/ and detail the steps to reproduce the issue. If it is indeed something we need to correct, believe me, we will. We don't deliberately attempt to mislead or frustrate people, despite how it might have seemed. Well, with that said, here is a test. I have found, in the past, that when I enable all the SPAM filtering that I want, that 76.75.200.58/pb1.pair.com/lists.php.net mail server gets blocked by my mail server. It has been a while so I don't remember what the reason was it got blocked, but I have enabled all the filtering again, and this is my test email with the full set of filtering enabled. Lets see if the server still gets blocked. I will post the logs if and when it gets blocked. -- Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ok then, here is a test
On 10/13/2012 10:42 PM, Jim Lucas wrote: On 10/12/2012 11:42 AM, Daniel Brown wrote: Well, as the adage goes, you'll catch more flies with honey than with vinegar. And considering this is the very first message I've ever seen from you, it sounds like either (a) you didn't follow the proper protocol, or (b) there's something in the process we need to review. If you think the issue lies on our end, you can submit a bug at https://bugs.php.net/ and detail the steps to reproduce the issue. If it is indeed something we need to correct, believe me, we will. We don't deliberately attempt to mislead or frustrate people, despite how it might have seemed. Well, with that said, here is a test. I have found, in the past, that when I enable all the SPAM filtering that I want, that 76.75.200.58/pb1.pair.com/lists.php.net mail server gets blocked by my mail server. It has been a while so I don't remember what the reason was it got blocked, but I have enabled all the filtering again, and this is my test email with the full set of filtering enabled. Lets see if the server still gets blocked. I will post the logs if and when it gets blocked. -- Jim Lucas Well, I got it. Seems the problem has gone away. Never mind then. -- Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Bounce messages
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. -- 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
Re: [PHP] Bounce messages
On 09/21/2012 12:22 PM, Jeff Burcher wrote: Hi, I don't know if this is specifically what he is referring to when he says, the 'reply to sender' email handling camp , but I know that when I just click Reply it goes to the individual whose post I am commenting on. I need to click on Reply All and several emails are in the blanks and I need to delete them all and move the list email address from the CC: box to the TO: box. If I am not paying attention and don't do this little email musical chairs process, sometimes I will get out of office replies from some of the email addresses in the reply. Is this 'bouncing'? Technically, it is called back scatter. And SPAMers can use it to send SPAM to unsuspecting servers. And http://www.backscatterer.org loves to block mail servers that have auto responders turned on. Jeff -Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Friday, September 21, 2012 2:56 PM To: Jim Lucas Cc: Lester Caine; php-general@lists.php.net Subject: Re: [PHP] Bounce messages On Fri, 2012-09-21 at 09:56 -0700, Jim Lucas 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. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ 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? -- Thanks, Ash http://www.ashleysheridan.co.uk -- 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
Re: [PHP] about PHP's filter_var function
On 09/20/2012 02:35 AM, Sebastian Krebs wrote: Plaseplease update... 5.1.6 is from 2006! I read the it's required, but I can't imagine _anything_ that it's worth it to use such an extremely outdated, unsupported and therefore insecure and inefficient version... You know: There are 3 (!) new minor versions available right now (5.2, 5.3 and 5.4). However: Regarding your concrete problem I guess you can use ip2long() if (ip2long($ip)) { I would suggest a modification to this. if ( ip2long($ip) !== false ) { I suggest this because IP to long will return negative numbers for half the IP range. Therefor 50% of your possible results would be considered false when in fact they are valid IPs. See Example #2 on this page: http://php.net/manual/en/function.ip2long.php } else { } Regards, Sebastian Am 20.09.2012 11:14, schrieb lx: Hello: I want to use filter_var function by this way: $ip = 192.168.0.1; if( !filter_var($ip, FILTER_VALIDATE_IP) ) { echo IP is not valid; } else { echo IP is valid; } I want to check the string $ip is IP address or not.but my PHP version is 5.1.6. and I know the filter_var requires at least PHP version 5.2.0. so, Any other function in PHP 5.1.6 can slove this work and replace the filter_var function ? Thank you, I'm a new one, so I don't know much about PHP documentation. By the way, The PHP version is required. so I can't upgrade it. -- 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
Re: [PHP] about PHP's filter_var function
On 09/20/2012 10:00 AM, Matijn Woudt wrote: On Thu, Sep 20, 2012 at 6:03 PM, Jim Lucasli...@cmsws.com wrote: On 09/20/2012 02:35 AM, Sebastian Krebs wrote: Plaseplease update... 5.1.6 is from 2006! I read the it's required, but I can't imagine _anything_ that it's worth it to use such an extremely outdated, unsupported and therefore insecure and inefficient version... You know: There are 3 (!) new minor versions available right now (5.2, 5.3 and 5.4). However: Regarding your concrete problem I guess you can use ip2long() if (ip2long($ip)) { I would suggest a modification to this. if ( ip2long($ip) !== false ) { I suggest this because IP to long will return negative numbers for half the IP range. Therefor 50% of your possible results would be considered false when in fact they are valid IPs. See Example #2 on this page: http://php.net/manual/en/function.ip2long.php First of all, I agree with Maciek that inet_pton is the way to go because of IPv6. But, there seems to be some wrong information in your reply which bothers me. First of all, ip2long only returns negative numbers on 32bit systems, not on 64bit (which most servers are nowadays). Second, there's nothing wrong with the if, if(-5) is still true. The only difference is that you can differentiate between IP 0.0.0.0 and false. But IP 0.0.0.0 is not valid anyway. - Matijn After some testing, I stand corrected. Wow, I wonder where I ran into the issue of negative numbers equating to false. while loops maybe... Strange. I must have ran into this issue years ago. I have always performed strict (===) comparisons because I thought PHP would equate negative numbers as false. Learn something new every day... -- 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
Re: [PHP] How to limit source IP in PHP
On 09/12/2012 08:21 AM, Daniel Brown wrote: On Wed, Sep 12, 2012 at 10:18 AM, Tonix (Antonio Nati) to...@interazioni.it wrote: Is PHP able to 'force' binding IP? I hoped there was an external directive I did not see, but probably this is a PHP lack. Not at all. Essentially, PHP is an interface to underlying software, OS commands, and APIs. You'd have to configure the system to bind requests, as PHP does not presently have that capability (and, to my knowledge, there's no plan to change that). Daniel, Correct me if I wrong, but you could use the stream_* functions within a process running as a daemon that can listen on a given IP:port . I do this on my php scripts right now. It accepts, processes, and responds to the client connections without the need of any other applications. And, it responds to the client from the IP PORT that the client made the connection to. -- 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
Re: [PHP] How to limit source IP in PHP
On 09/13/2012 04:15 PM, Tonix (Antonio Nati) wrote: Jim, sorry but you did not read carefully my posts. Since the fist post, I ALWAYS spoke about connections a PHP script may open autonomously (what you name second connection). I'm never speaking about listening/intercepting/using the original HTTP request. Then why did you bring up apache? That seems to be the source of confusion... It is well clear for anyone with a minimum knowledge of programming in apache that only apache listens and answers from the binded port of httpd. And, of course, any program/script/binary called from apache, will return his data to apache, and apache only will send them back to the original requester. That is why your mentioning Apache confused me (and probably others). At the same time it is well clear too that each called program/script/binary may live autonomously before returning data to apache, and do whatever action it requires to do, including the opening of a network socket to an external or internal server. Your still talking about Apache... And this is true for any language, from perl to C to PHP. Only first two replies understood the initial request, all other just added confusion to the thread. Regards, Tonino Which is it that you are talking about? PHP running through Apache or a dedicated PHP script running on its own as a daemon? -- 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
Re: [PHP] How to limit source IP in PHP
On 09/13/2012 12:28 PM, Tonix (Antonio Nati) wrote: You are speaking about incoming connections, I suppose. I'm speaking about connections started from within PHP. Which is a response to the incoming connection. Unless you are talking about PHP being ran from cron or the CLI. if you are talking about YOU running a PHP script as a daemon, then yes, you have the ability to BIND to an IP address. I do this in a few scripts/daemons of mine. I use the stream_* functions for this. But, if you are talking about calling fopen() from the CLI and have it bind to a specific IP when connecting out, that is more of a OS specific option. You will need to find out how to run a php script and have it bind to a given IP (or interface) when it connects to the WWW. Hope this helps. Jim Regards, Tonino -- 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
Re: [PHP] How to limit source IP in PHP
On 09/13/2012 12:55 PM, Tonix (Antonio Nati) wrote: Il 13/09/2012 21:41, Jim Lucas ha scritto: On 09/13/2012 12:28 PM, Tonix (Antonio Nati) wrote: You are speaking about incoming connections, I suppose. I'm speaking about connections started from within PHP. Which is a response to the incoming connection. And so? There is no relation between the call received from Apache (which is not passed to PHP), and any connection PHP may open later. My experience has always been, with Apache and lighttpd at least, that the response comes from the IP:PORT that the request was made to. So, if I connect to http://10.10.10.10/ Then the response is going to come from PORT 80. You might want to run a little trafshow on your server to see how the traffic behaves. I have a number of web servers that I run, all with either apache or lighttpd, and they all behave this way. Here is the output of my http request from my office to my server: From Address To Address ProBytes CPS == 66.39.178.2..58479 66.39.167.51..80 tcp 725 12 66.39.167.51..80 66.39.178.2..58479 tcp 2720 66.39.178.2..52515 66.39.167.51..80 tcp 1303 66.39.178.2..54506 66.39.167.51..80 tcp 696 66.39.178.2..62658 66.39.167.51..80 tcp 700 66.39.178.2..65382 66.39.167.51..80 tcp 700 66.39.167.51..80 66.39.178.2..52515 tcp 545 66.39.178.2..50794 66.39.167.51..80 tcp 700 66.39.178.2..65015 66.39.167.51..80 tcp 711 66.39.167.51..80 66.39.178.2..54506 tcp 305 66.39.167.51..80 66.39.178.2..62658 tcp 305 66.39.167.51..80 66.39.178.2..65382 tcp 357 66.39.167.51..80 66.39.178.2..50794 tcp 357 66.39.167.51..80 66.39.178.2..65015 tcp 357 This is running Apache. Unless you are talking about PHP being ran from cron or the CLI. if you are talking about YOU running a PHP script as a daemon, then yes, you have the ability to BIND to an IP address. I do this in a few scripts/daemons of mine. I use the stream_* functions for this. But, if you are talking about calling fopen() from the CLI and have it bind to a specific IP when connecting out, that is more of a OS specific option. You will need to find out how to run a php script and have it bind to a given IP (or interface) when it connects to the WWW. When apache starts a php script, the script can open a socket towards another end-point, asking to bind to any local address as source address. But this is a secondary connection (that you open in process) and has nothing to do with the request connection to the server from the client. Period. Regards, Tonino -- 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
Re: [PHP] another Array question
On 9/10/2012 9:41 PM, admin wrote: Hello everyone, I have a very long array. I want to pull all the data from the array from a certain position to a certain position. $myarray = array('0'='me', '1'='you','2'='her','3'='him','4'='them', '5'='us'); Yes I know the array above it small it's an example, mine has over 150 positions. $foundyou = array_search('you', $myarray); $foundthem = array_search('them', $myarray); Now I want to take all the array positions from $foundyou to $foundthem and put their values into a variable; For the life of me I can't remember how I did it. I DO NOT want to foreach over the array positions that would be counterproductive. Well, depends on exactly what you mean by and put their values into a variable. Do you mean concatenate all the values into one single flat variable. Or do you mean to make a subset array of the values between your two points you found? First, check out array_slice. Second, look at join ?php $myarray = array( '0'='me', '1'='you', '2'='her', '3'='him', '4'='them', '5'='us', ); $s_pos = array_search('you', $myarray); $f_pos = array_search('them', $myarray); # Calculate the length, it is needed by array_slice() $length = ($f_pos - $s_pos); $subset_array = array_slice($myarray, $s_pos, $length); print_r($subset_array); $all_values = join(', ', $subset_array); echo $all_values; ? Obviously, you need to add in some error checking. But that should get you started. -- Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP to XLS Security Alert issue
On 08/29/2012 10:28 AM, admin wrote: -Original Message- From: Matijn Woudt [mailto:tijn...@gmail.com] Sent: Tuesday, August 28, 2012 3:55 PM To: admin Cc: php-general@lists.php.net Subject: Re: [PHP] PHP to XLS Security Alert issue I believe that's normal, and that it does that with any document downloaded from the web. I'm not sure if there's a workaround, but you should not ask that here but on a Microsoft Office forum/list, or just ask the question to Microsoft themselves. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Matijn, I understand YOU believe this is normal. I am sorry you feel that way because the construction of the document is exactly where the problem was resolved, and that is in PHP. So asking in the PHP-List was the exact the place to post a question of document construction using PHP. Yes understanding the document verification methods of Microsoft helps but it is up to the DEVELOPER to put the correct headers and content strings to make the document valid and that is what I was asked. Q: I am exporting to a XLS file and the file does export, but when I open the file Microsoft is giving a Excel Security Notice. I am sure there is something in the header that is missing or causing this problem? If I create a file using MS Excel, I get this message if I screw up some data in one of the fields. If it has a formula in one of the cells that it doesn't like, then it complains. May want to check that as well. -- 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
Re: [PHP] Re: get question
On 08/27/2012 01:26 PM, Ashley Sheridan wrote: On Mon, 2012-08-27 at 15:56 -0400, Jim Giner wrote: Also, as Ashley can attest, make sure that your able to run with short-tags enabled. Seeings how your code block starts with a short-tag. eg. '?' Change this to ?php and see if you get the same results. Sorry Ashley, had to point it out. -- 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
Re: [PHP] Dynamic Content thoughts
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/ My test attachment -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic Content thoughts
On 08/24/2012 08:25 AM, Matijn Woudt wrote: On Fri, Aug 24, 2012 at 5:22 PM, Jim Lucasli...@cmsws.com wrote: Two simple guide lines will help everybody here. 1) Limit your lines to 80 characters 2) Use spaces instead of Tabs Are we going to discuss coding guidelines again? The 80-character limit is outdated, 100 or 120 is more common today. And while I do agree with the spaces, do you also insist on 2, 4 or .. spaces? ;) Oh and I'd like everybody to put the opening brackets on the same line.. bla bla My point is: It's not going to happen. - Matijn This has absolutely nothing to do with your own personal coding styles. This has only to do with how you are going to present code to the list members. Personally, I let my code ramble on as long a line as it needs. I use tabs (set to 8 chars) in my code. That is because the other developers that I work with have editors that can display the tabs in whatever width they desire. I also do not wrap at 80 chars. But if you look back at any of my code examples that I have written, none of them are longer then 80 characters, and uses two spaces for indentation. Simply because my email client is set to plain text and wraps at 80 chars. -- 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
Re: [PHP] Dynamic Content thoughts
On 08/24/2012 08:47 AM, Matijn Woudt wrote: On Fri, Aug 24, 2012 at 5:33 PM, Jim Lucasli...@cmsws.com wrote: On 08/24/2012 08:25 AM, Matijn Woudt wrote: On Fri, Aug 24, 2012 at 5:22 PM, Jim Lucasli...@cmsws.com wrote: Two simple guide lines will help everybody here. 1) Limit your lines to 80 characters 2) Use spaces instead of Tabs Are we going to discuss coding guidelines again? The 80-character limit is outdated, 100 or 120 is more common today. And while I do agree with the spaces, do you also insist on 2, 4 or .. spaces? ;) Oh and I'd like everybody to put the opening brackets on the same line.. bla bla My point is: It's not going to happen. - Matijn This has absolutely nothing to do with your own personal coding styles. This has only to do with how you are going to present code to the list members. So you expect people to convert all their code to a 'mailing list standard' before posting? If it means that more eyes will even look at the code, then I would hope they would do anything possible to make that happen. Still not going to see that happen.. Unfortunate. Personally, I let my code ramble on as long a line as it needs. I use tabs (set to 8 chars) in my code. That is because the other developers that I work with have editors that can display the tabs in whatever width they desire. I also do not wrap at 80 chars. But if you look back at any of my code examples that I have written, none of them are longer then 80 characters, and uses two spaces for indentation. Simply because my email client is set to plain text and wraps at 80 chars. I can see that you do that indeed, but that does *not* guarantee that it is also seen that way. I think most of us use a 'smart' mail client, that automatically makes emails more readable by undoing these stupid line breaks at 80 chars. Gmail for example shows your mail as lines with approx 175 chars on my 17 notebook.. I'm not sure how Gmail sends my messages, but looking at the 'Show original' option, it seems it breaks long lines but might be at a different length too. - Matijn Well, not to talk bad about Gmail (I use it for personal accounts), but I like using a client that I do have some control over what it does to my email. Making sure that it retains my formatting is one of my first requirements. -- 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
Re: [PHP] Dynamic Content thoughts
On 08/24/2012 09:28 AM, tamouse mailing lists wrote: On Fri, Aug 24, 2012 at 10:16 AM, Jim Lucasli...@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. Wow, I did not know it even allowed attachments. The catch is, they must be txt files. -- 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
Re: [PHP] Dynamic Content thoughts
On 08/24/2012 12:34 PM, Matijn Woudt wrote: On Fri, Aug 24, 2012 at 8:24 PM, Jim Lucasli...@cmsws.com wrote: Personally, I let my code ramble on as long a line as it needs. I use tabs (set to 8 chars) in my code. That is because the other developers that I work with have editors that can display the tabs in whatever width they desire. I also do not wrap at 80 chars. But if you look back at any of my code examples that I have written, none of them are longer then 80 characters, and uses two spaces for indentation. Simply because my email client is set to plain text and wraps at 80 chars. I can see that you do that indeed, but that does *not* guarantee that it is also seen that way. I think most of us use a 'smart' mail client, that automatically makes emails more readable by undoing these stupid line breaks at 80 chars. Gmail for example shows your mail as lines with approx 175 chars on my 17 notebook.. I'm not sure how Gmail sends my messages, but looking at the 'Show original' option, it seems it breaks long lines but might be at a different length too. - Matijn Well, not to talk bad about Gmail (I use it for personal accounts), but I like using a client that I do have some control over what it does to my email. Making sure that it retains my formatting is one of my first requirements. That's where we have different requirements. My first priority is speed, both in access (email clients tend to be slow), and in delivery time. I really need emails to be delivered to my PC instantly, and that's not the case with POP3 and IMAP. Even push mail to my Android smartphone with original Gmail app is faster than POP or IMAP. - Matijn IMAP is not fast enough? I have my own mail server running SMTP IMAP and I use Thunderbird w/IMAP and when my mail server receives an email within 1 to 2 seconds my client is notified. I'm not sure how you can get much faster then that. You realize that IMAP works completely differently then POP. POP clients fetch the mail. Normally on some preset time frame. IMAP clients are notified by the server when a new message arrives. As long as your IMAP client is open and logged into your account, that notification process will take less then a couple seconds. I cannot see how IMAP is slow. -- 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
Re: [PHP] Cost of redirect and site domain switch? Good Practice/ Bad Practice / Terrible Practice
On 8/17/2012 6:35 PM, Jim Giner wrote: On 8/17/2012 7:16 PM, Jim Lucas wrote: You could simply remove all full domain+path URL links and replace them with absolute path urls only. turn http://www.somedomain.com/path/to/my/webpage.html into /path/to/my/webpage.html This would work with either domain. Those would be relative paths, ..o? No. Quick Google search turns up this: http://www.uvsc.edu/disted/decourses/dgm/2120/IN/steinja/lessons/06/06_04.html I have three description or types of paths that I use normally. I feel the first two generally get grouped together by most persons. Full or complete path: a href=http://www.cmsws.com/index.php;Home/a Absolute Path: a href=/index.phpHome/a Relative: a href=index.phpHome/a -- Jim Lucas http://cmsws.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OT (maybe not): Drupal vs WordPress
On 8/19/2012 2:39 PM, Michael Shadle wrote: Yes this is going to spawn a religious debate. But joomla sucks. Sorry folks. 1+ -- Jim Lucas http://cmsws.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cost of redirect and site domain switch? Good Practice / Bad Practice / Terrible Practice
On 08/17/2012 01:09 PM, Tristan wrote: Sebastian, I'll check into 307 I haven't used that before but, this really is a permanent redirect. They are going to a shorter domain. About the SEO part of it though. Would it be good to find replace all internal links from somedomain.com to somenewdomain.com or will it follow the 301 with no punishment or cause any other weirdnesses you can think of. Thanks, T On Fri, Aug 17, 2012 at 1:56 PM, Sebastian Krebskrebs@gmail.comwrote: If you need to change the domain completely, choose 301. - Crawler will recognize it and will update their indexes quite soon. Especially you avoid duplicate content-punishments, because you say yourself, that the content originally comes from another domain, that isn't anymore (Like It's not a duplicate, it's _the_ content, but under a different address). - The delay is negliable. Also as soon as every index were updated no new visitor should enter your site via the old domain. Browser should (don't know wether they do, or not) recognize 301 too and redirect any further request to the url on their own (think of it as they cache the redirect permanently). If this change is only temporary I would recommend using 307 to avoid duplicate contents. I would even say, that a 307-redirect from somenewdomain.com to somedomain.com is more appropiate, but that depends. Regards, Sebastian You could simply remove all full domain+path URL links and replace them with absolute path urls only. turn http://www.somedomain.com/path/to/my/webpage.html into /path/to/my/webpage.html This would work with either domain. -- 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
Re: [PHP] Reading class variable value always returns NULL
On 08/12/2012 05:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. Does anyone have an idea what could cause this, or how to further debug? Thanks, Reto What is your error reporting set to? Do you have display errors turned on? Are you saving your errors to a log file? -- 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
Re: [PHP] Is PHP unsuitable for HTML5 WebSockets?
On 8/12/2012 12:06 PM, BRIAN M. FITZPATRICK wrote: I've looked all over the net and I have been unable to find a concrete answer to this question. I am about to start development on a web application that will need to provide real-time updates of data to user's browsers. WebSockets are ideal for this task. I have read in some places on the net that PHP is not suitable for WebSockets due to it's nature. That WebSockets are designed for long running threads/processes which each maintain multiple event-driven connections, whereas PHP was designed around the short-lived single process procedural paradigm. Yet on the other hand I see lots of guides and libraries (such as http://socketo.me/) on the net that deal with PHP WebSockets. So I don't know what to think at this stage. Is PHP a suitable platform for developing a web application that requires WebSockets? Back in 2007, I wrote a cli php script to run as a socket server for a game I was playing at the time. It has been running on every server I've put together since then. To say that PHP isn't suited to this type of service is wrong. Give it a shot. Can't hurt to try. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP session variables
On 08/09/2012 01:45 PM, Tedd Sperling wrote: On Aug 8, 2012, at 5:41 PM, Jim Ginerjim.gi...@albanyhandball.com wrote: On 8/8/2012 11:24 AM, Ansry User 01 wrote: I am setting the _SESSION variables in one of my file, but whenever I leave the php page session variables are not accessible. Not sure what I need to do additionally other then defining _SESSION[]. Any pointer. You must make it a habit to start each script with session_start(); I like this way: if (!session_id()) { session_start(); } Cheers, tedd _ t...@sperling.com http://sperling.com You are relying on PHP's loose typing. This is a poor check. session_id() returns a string, not boolean. You should do this instead. if ( session_id() === '' ) -- 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
Re: [PHP] Too many open files
On 8/9/2012 5:01 PM, Al wrote: Getting Too many open files error when processing an email batch process. I've looked extensively and can't find more than about 100 files that could be open. All my fetching is with get_file_contents(); Why not use fopen() and other related functions to open/grap/close your batch of files? You could replace a call like this: $data = file_get_contents($filename); with this: if ( $fh = fopen($filename, 'r') ) { $data = fread($fh, filesize($filename)); fclose($fh); } This should take care of your issue. Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Too many open files
On 8/9/2012 9:40 PM, Alan Hoffmeister wrote: +1 to fopen and fclose. You can implement your function: function read($file){ if ( $fh = fopen($file, 'r') ) { $data = fread($fh, filesize($file)); fclose($fh); } } echo read('hello-world.txt'); echo read('hello-world1.txt'); echo read('hello-world2.txt'); echo read('hello-world3.txt'); This way you will close one file before start reading the other one. -- Att, Alan Hoffmeister You top posted AND you didn't send it to the list... Jim 2012/8/10 Jim Lucas li...@cmsws.com: On 8/9/2012 5:01 PM, Al wrote: Getting Too many open files error when processing an email batch process. I've looked extensively and can't find more than about 100 files that could be open. All my fetching is with get_file_contents(); Why not use fopen() and other related functions to open/grap/close your batch of files? You could replace a call like this: $data = file_get_contents($filename); with this: if ( $fh = fopen($filename, 'r') ) { $data = fread($fh, filesize($filename)); fclose($fh); } This should take care of your issue. Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magic getter
On 07/19/2012 12:22 PM, Sebastian wrote: Hi all, is this a bug, or a feature? class Foo { private $data; public function __get($name) { return $this-data[$name]; } } $foo = new Foo(); $foo-color = 'red'; echo $foo-color; I would expect an error, or a least a notice, but it prints out red ... Their is nothing magical about this. When you do this: $foo = new Foo(); $foo-color = 'red'; you create a variable within the $foo instance variable called color with a value of red. Then, later on when you do this echo $foo-color; you are then simply echo'ing the variable/value you created. with this example, you are never using the __get() magic function to retrieve the value of color. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reverse DNS testing
On 07/12/2012 11:17 AM, Al wrote: I want to do a rDNS check on a admin entered host name to insure in-coming mail servers don't reject mail, sent by my app, because the rDNS doesn't exist or doesn't match. Here is the fundamental code: $host = $_SERVER['SERVER_NAME']; //site name shared or not $ip = gethostbyname($host); $hostName = gethostbyaddr($ip); //May be different on a shared host $ip2 = gethostbyname($hostName); Throw in a filter_var() check with the FILTER_VALIDATE_IP flag? if ( filter_var($hostName, FILTER_VALIDATE_IP) === TRUE ) { # This is an IP # do something } Or do a conditional check if ( $hostName === $ip2 ) { # no change... # handle no resolution issue. } The $ip works fine. However, one of the shared hosts I'm working with returns this instead of the original $host gethostbyaddr($ip)= 93.247.128.148-static.foo.com [foo is subs for actual] gethostbyname($hostName)= 93.247.128.148-static.foo.com It appears gethostbyname() is just returning $hostName because it is not legit. Using just the foo.com in gethostbyname() returns the host's server IP. Thus, the typical rDNS check fails for this site. Several online checks also report rDNS fails. Any suggestions how I can handle this? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO Prevent duplicate field names?
On 07/02/2012 03:38 PM, Scott Baker wrote: On 07/02/2012 03:34 PM, Matijn Woudt wrote: Why the would you want to return 2 columns with the same name? To be short, there's no such function, so you have to: 1) Rename one of the columns 2) or, use fetch_row with numerical indexes instead of fetch_assoc. My real world scenario was this SELECT a.CustID, b.* FROM Customer a LEFT JOIN Sales B USING (CustID) WHERE a.CustID = 1234; In that case, there was a record in Customer, but not in Sales. Sales returned CustID as NULL, which overwrote the one from Customer. It was my mistake, and the SQL was easily fixed. But it woulda been nice to have PHP realize there was a dupe when it was building that array to return to me. You could always do this. SELECT b.*, a.CustID FROM Customer a LEFT JOIN Sales B USING (CustID) WHERE a.CustID = 1234; -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How does this code work?
On 7/2/2012 7:15 PM, Robert Williams wrote: I found this code in a user comment in the PHP docs for htmlentities(): ?php function xml_character_encode($string, $trans='') { $trans = (is_array($trans)) ? $trans : get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); foreach ($trans as $k=$v) $trans[$k]= #.ord($k).;; return strtr($string, $trans); } ? It seems to work. For instance, this (assuming UTF-8 encoding): echo xml_character_encode('Château'); echo \n; echo xml_character_encode('Chteau'); Yields this: Ch#195;#162;teau Ch#38;teau My question is, *how* does it work? It makes sense right up to the return statement. According to the docs for strstr(), when a non-string is passed in as the needle, it's, converted to an integer and applied as the ordinal value of a character. First, an array-to-int conversion is undefined, though it seems to produce 1 on my copy of PHP. Now, I'm not quite sure how to interpret the last part of that statement from the docs, but I take it that the ultimate value supplied to strstr() is going to be either '1' (the character value of the integer value of the array) or '49' (the ordinal value of the character '1'). Whatever, neither one makes sense to look for in the haystack, so I'm obviously missing something. I think you missed something here... The above function uses strtr() not strstr() http://php.net/strtr http://php.net/strstr Perhaps it's just late-Monday slowness on my part, but what's going on here? I have no intention of using this code, but I'd sure like to understand how it works! Regards, Bob -- Robert E. Williams, Jr. Associate Vice President of Software Development Newtek Businesss Services, Inc. -- The Small Business Authority https://www.newtekreferrals.com/rewjr http://www.thesba.com/ Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] else if vs switch
On 6/15/2012 3:29 PM, Joshua Kehn wrote: Way easier to just use a map. $mapping = array( 'Calgary' = abc@emailaddress, 'Brooks' = def@emailaddress, // etc ); $toaddress = $mapping[$city]; I would use this, but add a check to it. $mapping = array( 'default' = 'defa...@domain.tld', ... ); ... if ( isset($mapping[$city]) ) { $toaddress = $mapping[$city]; } else { $toaddress = $mapping['default']; } Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: php form action breaks script
On 06/15/2012 06:35 AM, Jim Giner wrote: Hear, Hear for heredocs. The only way to code up your html. Took me a few months to discover it and haven't looked back since. The only problem I have with HEREDOC is I cannot use constants within them. -- 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
Re: [PHP] Re: show info from mysql db
On 06/10/2012 09:50 AM, Tim Dunphy wrote: You had been keeping the password secret, but it looks like you accidentally leaked it, so a replacement might be in order :) oh wow.. gotta hate when you do that!!! on it! Glad you got it fixed. Typos can be little buggers to find sometimes. me too.. fell back to the old 'echo hello' test strategy .. have to try to remember that strategy before i go running for help.. :) FYI: When developing, make sure to have error_reporting = E_ALL and display_errors = On or be sure to tail your error_log file. tim On Sun, Jun 10, 2012 at 12:15 PM, Adam Richardsonsimples...@gmail.com wrote: On Sun, Jun 10, 2012 at 8:25 AM, Tim Dunphybluethu...@gmail.com wrote: $dbc = mysqli_connect('127.0.0.1','admin',secret','trek_db') or die ('Could not connect to database'); used to be... $dbc = mysqli_conect('127.0.0.1','admin','Duk30fZh0u','trek_db') or die ('Could not connect to database'); You had been keeping the password secret, but it looks like you accidentally leaked it, so a replacement might be in order :) Glad you got it fixed. Typos can be little buggers to find sometimes. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SQL Injection
On 06/08/2012 10:31 AM, Govinda wrote: Is it possible to have a meeting of the minds to come up with (an) appropriate method(s)? Minds, meet prepared statements :) PDO is the way to go :D Not to refute the above advice one bit (not to mention oppose the arguments against escaping in general) ... but just curious - can anyone demo a hack that effectively injects past mysqli_real_escape_string(), while using utf-8 ? It may just be a matter of time (or already?) before mysqli_real_escape_string is *proven* ineffective (w/utf-8) ... but here I am just attempting to gather facts. Thanks -Govinda Ah, but what if I use sqlite or postgres? IMHO, the discussion needs to be a the best way to prevent SQL injection across all possible DB types. Not just mysql. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help with query
On 06/07/2012 09:37 AM, Jack wrote: $query = select a.startdate, a.articleid, c.name, a.title, a.intro, a.datecreated from articles as a, categories as c where (a.startdate = -1 or a.startdate= {$now}) and (a.enddate = -1 or a.enddate= {$now}) and a.categoryid = c.categoryid order by a.startdate DESC; $query = SELECT a.startdate, a.articleid, c.name, a.title, a.intro, a.datecreated FROMarticles as a, categories as c WHERE ( a.startdate = -1 OR a.startdate = {$now} ) AND ( a.enddate = -1 OR a.enddate = {$now} ) -- This line must stay, it is limiting the combination of the data from -- both tables AND a.categoryid = c.categoryid -- You need to add this line to make it work, but keep the previous line AND a.categoryid = 1 ORDER BY a.startdate DESC ; -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uploading large files with HTTP_Request class
On 05/31/2012 03:28 AM, Voß, Marko wrote: Hello, I need to perform uploading of large files using the HTTP_Request class: http://pear.php.net/manual/package.http.http-request.php How am I supposed to do that with this class? Are there any alternatives, which do not force me to add new PHP dependancies/libraries to the project? I am writing a library and do not want to force the users to add dependancies to their projects in order to use this library. You don't want to require additional dependencies yet you require PEAR. Isn't PEAR an addition dependency? I am currently using PHP 5.3.0. Thank you and best regards, Marko -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uploading large files with HTTP_Request class
On 05/31/2012 11:34 AM, Bastien Koert wrote: On Thu, May 31, 2012 at 12:24 PM, Jim Lucasli...@cmsws.com wrote: On 05/31/2012 03:28 AM, Voß, Marko wrote: Hello, I need to perform uploading of large files using the HTTP_Request class: http://pear.php.net/manual/package.http.http-request.php How am I supposed to do that with this class? Are there any alternatives, which do not force me to add new PHP dependancies/libraries to the project? I am writing a library and do not want to force the users to add dependancies to their projects in order to use this library. You don't want to require additional dependencies yet you require PEAR. Isn't PEAR an addition dependency? I am currently using PHP 5.3.0. Thank you and best regards, Marko -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php If you don't want dependencies, try swfuploader...uses flash but is more robust for large file uploads, From what I read, he is wanting the server to upload a file to a remote machine. Not a client uploading to his server. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] w.r.t. mail() function
On 05/24/2012 04:39 AM, Matijn Woudt wrote: On Wed, May 23, 2012 at 10:25 PM, Jim Lucasli...@cmsws.com wrote: On 05/22/2012 09:12 PM, Ashwani Kesharwani wrote: Hi , I have a query w.r.t. mail() function in php. I have hosted my site and i have created an email account as well. when i am sending mail to different recipient from my php script using above function it is getting delivered to respective recipients as expected. However if I want to see those mail in the sent folder of my email account , i can not see those mails there. How can I achieve this. Any suggestions. Regards Ashwani Why not BCC it to your self, and then setup a filter in your email client to move it where ever you want it to be. Maybe because not everyone uses mail clients that have a filter functionality? well, if he is wanting the message to be placed in the outbox or sent folder of his email client, and this client is on his workstation and the sent folder is accessed via IMAP, nor is it via a web client, then his only option is to have his email client filter a message to the sent folder. POP3 picks up new messages from your inbox. IMAP allows you to have folders on/in the mail server file structure, but the mail server would then need a filter (ie: procmail) to move the new message over to the correct folder. So, no matter what type of solution he comes up with, something, either his client or the mail server will need to have a filter created to move the message to the correct folder. Now, I guess you could completely sidestep all security and with proper setting have php write the email to the correct folder in the persons sent box. And he could then access it via IMAP and/or a web based email client. But, this would require that php process have file level access to the folder which his mail directory resides. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] w.r.t. mail() function
On 05/22/2012 09:12 PM, Ashwani Kesharwani wrote: Hi , I have a query w.r.t. mail() function in php. I have hosted my site and i have created an email account as well. when i am sending mail to different recipient from my php script using above function it is getting delivered to respective recipients as expected. However if I want to see those mail in the sent folder of my email account , i can not see those mails there. How can I achieve this. Any suggestions. Regards Ashwani Why not BCC it to your self, and then setup a filter in your email client to move it where ever you want it to be. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 5/17/2012 1:57 PM, shiplu wrote: On Fri, May 18, 2012 at 2:37 AM, Jim Ginerjim.gi...@albanyhandball.comwrote: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h=0 $h13 $m=0 $m60); } That won't work, it doesn't account for the possibility of a single digit hour field. I would do something like this: ?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d:]+|', '', $time) ) !== $time ) return false; if ( ( $pos = strpos($c_time, ':') ) !== false ) { list($hour, $minute) = explode(':', $c_time, 2); } else { $break = (strlen($c_time) - 2); $hour = substr($c_time, 0, $break); $minute = substr($c_time, $break, 2); } $hour = (int)$hour; $minute = (int)$minute; if ( strlen($c_time) = 2 ) return false; if ( ( $hour = 0 $hour = 12 ) ( $minute = 0 $minute = 59 ) ) { return true; } return false; } It seems overly complicated, but it does check and error for the various things that I could think of for possible input. Give it a try and let us know. See it in action here. http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.php http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.phps Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 5/17/2012 8:07 PM, Jim Giner wrote: Jim Lucasli...@cmsws.com wrote in message news:4fb5b89e.8050...@cmsws.com... On 5/17/2012 1:57 PM, shiplu wrote: On Fri, May 18, 2012 at 2:37 AM, Jim Ginerjim.gi...@albanyhandball.comwrote: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h=0 $h13 $m=0 $m60); } That won't work, it doesn't account for the possibility of a single digit hour field. I would do something like this: ?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d:]+|', '', $time) ) !== $time ) return false; if ( ( $pos = strpos($c_time, ':') ) !== false ) { list($hour, $minute) = explode(':', $c_time, 2); } else { $break = (strlen($c_time) - 2); $hour = substr($c_time, 0, $break); $minute = substr($c_time, $break, 2); } $hour = (int)$hour; $minute = (int)$minute; if ( strlen($c_time)= 2 ) return false; if ( ( $hour= 0 $hour= 12 ) ( $minute= 0 $minute= 59 ) ) { return true; } return false; } It seems overly complicated, but it does check and error for the various things that I could think of for possible input. Give it a try and let us know. See it in action here. http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.php http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.phps Jim Lucas Thanks for the work you did, but I really wanted to try to solve this using the more elegant way, which from my readings over the last year as a new php developer, seemed to be the regexp methodology. I'm so close - it's only the 1300,1400,etc. time values that are getting by my expression. And thank you Shiplu also for your simple, but non-regexp, solution. Yes - it works and I had something similar that was just missing one more check when I decided to explore the regexp method. How about this instead? pre?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d\:]+|', '', $time) ) != $time ) return false; preg_match('#^(?Phour\d{1,2}):?(?Pminute\d{2})$#', $time, $m); if ( $m ( 0 = (int) $m['hour']12 = (int) $m['hour'] ) ( 0 = (int) $m['minute'] 59 = (int) $m['minute'] ) ) { return TRUE; } return false; } Let me know. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 5/17/2012 9:52 PM, Jim Lucas wrote: How about this instead? pre?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00', # valid '12:59', # valid '00:01', # valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d\:]+|', '', $time) ) != $time ) return false; preg_match('#^(?Phour\d{1,2}):?(?Pminute\d{2})$#', $time, $m); if ( $m ( 0 = (int) $m['hour'] 12 = (int) $m['hour'] ) ( 0 = (int) $m['minute'] 59 = (int) $m['minute'] ) ) { return TRUE; } return false; } Let me know. I optimized it a little... http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.php http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.phps pre?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_time($time)?'valid':'invalid').\n; function valid_time($time) { if ( preg_match('#^(\d{1,2}):?(\d{2})$#', $time, $m) ( 0 = (int) $m[1] 12 = (int) $m[1] ) ( 0 = (int) $m[2] 59 = (int) $m[2] ) ) { return TRUE; } return FALSE; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] alias address in REMOTE_ADDR
On 5/11/2012 10:57 PM, Tóth Csaba wrote: Hi Everyone, I've run into a curious problem, not even really sure it's PHP, but that's where I caught it, so here it is: I have two servers hanging on the net, without proxies. Let's call them Server1 and Server2. Server1 has multiple IP addresses, configured as aliases. My problem: When I do a wget --spider from 1 to 2, I get the eth0 (not alias) address in Apache's accesslog on Server2. But when I do a file_get_contents(http://server2.tld), and observe the $_SERVER['REMOTE_ADDR'] on Server2, I get one of the alias IP addresses back. What can cause this? I really need the eth0 IP address back in REMOTE_ADDR. Regards, Csaba What IP address is your Apache bound to? You eth0 or one of the alias IPs? Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting date string to unix timestamp
On 05/11/2012 04:11 PM, Karl DeSaulniers wrote: Hello everyone, Got a quick one (I hope), and probably an easy one. For some reason it is eluding me at the moment. Hoping someone can help. I am building an ics file with PHP and the form that is submitting to create this ics file has a jQuery date picker on it. The date furnished comes to me like this Saturday, January 1, 2012, and a time furnished like 4:20 pm with no seconds. Now for the ics file, I need the date/time combo to be.. Ymd\THis\Z or in the case of the above date and time, 20120101T042000Z Here is the block of code that I am using for this. Why do you have so much code to do such a simple thing? This works for me. ?php $date = Saturday, January 1, 2012; $time = 4:20 pm; echo date('Ymd\THis\Z', strtotime($date.' '.$time)); // Outputs 20120107T162000Z ? Check it out in action: http://www.cmsws.com/examples/php/jquery_time_stamp.php http://www.cmsws.com/examples/php/jquery_time_stamp.phps Jim CODE [ ... } else { $dt_start = $_POST[field20] ? $_POST[field20] : $_POST[field21]; //Saturday, January 1, 2012 $dt_end = $_POST[field22]; //Saturday, January 1, 2012 $t_start = $_POST[field24]; //4:20 pm $t_end = $_POST[field25]; //5:55 pm //date_default_timezone_set('UTC'); try { $start_DT = new DateTime($dt_start . . $t_start); $st_date_fmt = new DateTime($start_DT-format(l, F d, Y\TH:ia T)); //$startdate_stamp = strtotime($st_date_fmt); $startdate = $st_date_fmt-format('U'); //$startdate = date('Ymd\THis\Z', $startdate_stamp); } catch (Exception $e) { trigger_error(startdate error: . $e-getMessage(), E_USER_ERROR); exit(1); } try { if(empty($dt_end)) { $enddate = $startdate + (60 * 60); //If no end date provided, enddate is 1 hour after startdate. } else { $end_DT = new DateTime($dt_end . . $t_end); $end_date_fmt = new DateTime($end_DT-format(l, F d, Y\TH:ia T)); //$enddate_stamp = strtotime($end_date_fmt); $enddate = $end_date_fmt-format('U'); //$enddate = date('Ymd\THis\Z', $enddate_stamp); } } catch (Exception $e) { trigger_error(enddate error: . $e-getMessage(), E_USER_ERROR); exit(1); } $stampnow = date('Ymd\THis\Z', time()); //$datestampnow = strtotime($stampnow); } ... ] I have a feeling I am mixing something up on my own, but I have been staring at this code to long to see it. Can anyone help me please? Like I said, this is probably an easy one. TIA!! Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting date string to unix timestamp
On 05/11/2012 05:55 PM, Karl DeSaulniers wrote: Thanks Jim, To tell you the truth, this was handed off to me. Thank you for the response. I knew this was just bloated code. Thanks for verifying that for me. :) Just one question, why does it echo the 7th and not the 1st? I see that... Figuring their is a logical reason... Ah! The first Saturday in the month of January this year WAS the 7th. The 1st was on a Sunday. I would say that your date picker has issues. Should be 20120101T162000Z not 20120107T162000Z Best, Karl On May 11, 2012, at 7:42 PM, Jim Lucas wrote: On 05/11/2012 04:11 PM, Karl DeSaulniers wrote: Hello everyone, Got a quick one (I hope), and probably an easy one. For some reason it is eluding me at the moment. Hoping someone can help. I am building an ics file with PHP and the form that is submitting to create this ics file has a jQuery date picker on it. The date furnished comes to me like this Saturday, January 1, 2012, and a time furnished like 4:20 pm with no seconds. Now for the ics file, I need the date/time combo to be.. Ymd\THis\Z or in the case of the above date and time, 20120101T042000Z Here is the block of code that I am using for this. Why do you have so much code to do such a simple thing? This works for me. ?php $date = Saturday, January 1, 2012; $time = 4:20 pm; echo date('Ymd\THis\Z', strtotime($date.' '.$time)); // Outputs 20120107T162000Z ? Check it out in action: http://www.cmsws.com/examples/php/jquery_time_stamp.php http://www.cmsws.com/examples/php/jquery_time_stamp.phps Jim CODE [ ... } else { $dt_start = $_POST[field20] ? $_POST[field20] : $_POST[field21]; //Saturday, January 1, 2012 $dt_end = $_POST[field22]; //Saturday, January 1, 2012 $t_start = $_POST[field24]; //4:20 pm $t_end = $_POST[field25]; //5:55 pm //date_default_timezone_set('UTC'); try { $start_DT = new DateTime($dt_start . . $t_start); $st_date_fmt = new DateTime($start_DT-format(l, F d, Y\TH:ia T)); //$startdate_stamp = strtotime($st_date_fmt); $startdate = $st_date_fmt-format('U'); //$startdate = date('Ymd\THis\Z', $startdate_stamp); } catch (Exception $e) { trigger_error(startdate error: . $e-getMessage(), E_USER_ERROR); exit(1); } try { if(empty($dt_end)) { $enddate = $startdate + (60 * 60); //If no end date provided, enddate is 1 hour after startdate. } else { $end_DT = new DateTime($dt_end . . $t_end); $end_date_fmt = new DateTime($end_DT-format(l, F d, Y\TH:ia T)); //$enddate_stamp = strtotime($end_date_fmt); $enddate = $end_date_fmt-format('U'); //$enddate = date('Ymd\THis\Z', $enddate_stamp); } } catch (Exception $e) { trigger_error(enddate error: . $e-getMessage(), E_USER_ERROR); exit(1); } $stampnow = date('Ymd\THis\Z', time()); //$datestampnow = strtotime($stampnow); } ... ] I have a feeling I am mixing something up on my own, but I have been staring at this code to long to see it. Can anyone help me please? Like I said, this is probably an easy one. TIA!! Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to send XML requests from PHP?
On 05/08/2012 10:50 AM, Michelle Konzack wrote: Hello *, I have to implement an interface which must access a Domain-Registration API. From the manual I have for example: 8-- Example 2.8. Contact Update:valid(change password) Change password from multipass to green REQUEST: Generic Operation: POST(http://backend.example.com/bdom/contact/update/DOJOB0001/1/,xml) Where xml: ?xml version=1.0 encoding=UTF-8? request xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; typePERS/type sexMALE/sex first-nameOtto/first-name last-nameNormalverbraucher/last-name organisationAcme Gmbh/organisation streetMain Strasse/street number13/number postcode55/postcode cityNewe Stad/city countryDE/country phone+040.0123456789/phone fax+040.0123456789/fax emailh...@nictest.de/email passwordnew_secret/password /request RESPONSE: response1 updated/response 8-- The problem is (I am sitting on my line) that I do not understand how to send this XML stuff. Any hints please? Thanks, Greetings and nice Day/Evening Michelle Konzack Look into cURL http://php.net/curl -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How to send XML requests from PHP?
On 05/08/2012 11:25 AM, Michelle Konzack wrote: Hello Jim Lucas, Am 2012-05-08 11:08:13, hacktest Du folgendes herunter: Look into cURL http://php.net/curl I know curl but I do not know, HOW to send the XML stuff. The XML code is generated using a temp file for logging, which mean, I can see any changes on the system... Thanks, Greetings and nice Day/Evening Michelle Konzack It is data, you send it in the data section of a post. Typically you must also assign it to a variable as you would any other value that you are submitting. What you should do is capture (using Firefox and viewing the headers) the communication that your browser would perform when submitting the data via FireFox. Once you have that, you will then see how the data needs to be associated. Sending post data via curl is a matter of formatting the data right and inserting it into the curl request. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] date conversion/extraction issues
On 05/02/2012 02:36 PM, Haluk Karamete wrote: This is my code and the output is right after that... $PDate = $row['PDate']; //row is tapping into ms-sql date field. //and the ms-sql data field has a value like this for the PDate; //07/12/2001 $PDate = $PDate-date; echo h1[, $PDate , ]/h1; echo h1[, var_dump($row['PDate']) , ]/h1; echo h1[, serialize($row['PDate']) , ]/h1hr; the output is as follows. And my question is embedded in the output. [] ??? WHY IS THIS BLANK? WHY IS THIS NOT 2001-12-07 00:00:00? [object(DateTime)#3 (3) { [date]= string(19) 2001-12-07 00:00:00 [timezone_type]= int(3) [timezone]= string(19) America/Los_Angeles } ] [O:8:DateTime:3:{s:4:date;s:19:2001-12-07 00:00:00;s:13:timezone_type;i:3;s:8:timezone;s:19:America/Los_Angeles;}] if I were to directly insert the $row['date'] ms-sql value into mysq, I get this error; Catchable fatal error: Object of class DateTime could not be converted to string in sql.php on line 379 I think you need to double check your variable names. In one place you are using $row['PDate'] in another you are referring to $row['date'] -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with AssertTag: children count wrong
On 05/02/2012 10:55 AM, Michael Otteneder wrote: Hi List! I'm trying to use phpUnit's AssertTag function to make sure that some html code contains an ul element with exactly li items in it. My test looks like this: function testUnconfiguredFilter() { $matcher = array( 'tag' = 'ul', 'children' = array( 'count' = 3, 'only' = array('tag' = 'li') ) ); $this-assertTag($matcher, $this-html, $message, $isHtml = FALSE); } the value of $html is: div class=flFilterbox id=flFilterunconfiguredFilter h3unconfiguredFilter/h3 ul class=flFilterboxInner lia href= FilterValue1/a ()/li lia href= FilterValue2/a ()/li lia href= FilterValue3/a ()/li /ul /div So I think the assertion SHOULD work - but it does not, no matter what I use for count! Sadly PHPUnit's output ist not very helpful, all it gives me is: 1) GeneratedFiltersTest::testUnconfiguredFilter Failed asserting that false is true. When dealing with classes, and specifically calling a static method within a class, the variable $this does not exist. You must use 'self' instead. You would need to do this instead if you wanted to use the $this way of things $test = new GeneratedFiltersTest; $test-testUnconfiguredFilter(); Plus, I am going to assume (since I don't see your code), that the method assertTag() is in a parent class that is inherited by the class GeneratedFiltersTest and again, since you are calling it via a static method, the inheritance would not have taken place. Has someone got an idea whats going on? This is really freakin me out, could not find anything about it anywhere on the web. Kind regards, Michael -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Database Problems
I do believe attachments are allowed. Looking back, I see that there have been messages sent to the list that had odt, php, and ini attachments On 05/02/2012 12:12 PM, Gavin Chalkley wrote: Ethan, Some coding you are using would be helpful (as far as i am aware attachments are not support on the mailing list's) Gav -Original Message- From: Ethan Rosenberg [mailto:eth...@earthlink.net] Sent: 02 May 2012 19:54 To: php-db-lists.php.net; php-general@lists.php.net Subject: [PHP-DB] PHP Database Problems have a database mysql describe Intake3; ++-+--+-+-+---+ | Field | Type| Null | Key | Default | Extra | ++-+--+-+-+---+ | Site | varchar(6) | NO | PRI | | | | MedRec | int(6) | NO | PRI | NULL| | | Fname | varchar(15) | YES | | NULL| | | Lname | varchar(30) | YES | | NULL| | | Phone | varchar(30) | YES | | NULL| | | Height | int(4) | YES | | NULL| | | Sex| char(7) | YES | | NULL| | | Hx | text| YES | | NULL| | ++-+--+-+-+---+ 8 rows in set (0.00 sec) mysql describe Visit3; ++--+--+-+-++ | Field | Type | Null | Key | Default | Extra | ++--+--+-+-++ | Indx | int(4) | NO | PRI | NULL| auto_increment | | Site | varchar(6) | YES | | NULL|| | MedRec | int(6) | YES | | NULL|| | Notes | text | YES | | NULL|| | Weight | int(4) | YES | | NULL|| | BMI| decimal(3,1) | YES | | NULL|| | Date | date | YES | | NULL|| ++--+--+-+-++ and a program to enter and extract data. I can easily extract data from the database. However, if I try to enter data, it goes into the incorrect record. Following are some screenshots. The program is attached. [pardon the comical names. This is a test, and any resemblance to true names is not intentional] Let us say that I wish to deal with Medical Record 1: This it data from Intake3: Site Medical Record First Name Last Name Phone Height Sex History AA 1 David Dummy 845 365-1456 66 Male c/o obesity. Various treatments w/o success This is data from Visit3: Index Site Medical Record Notes Weight BMI Date 2322 AA 1 Second Visit. 170 27.4 2010-01-20 2326 AA 1 Third visit. Small progress, but pt is very happy. 165 26.6 2010-02-01 I then request to enter additional data: Site Medical Record First Name Last Name Phone Height Sex History AA 10003 Stupid Fool 325 563-4178 65 Male Has been convinced by his friends that he is obese. Normal BMI = 23. Index Site Medical Record Notes Weight BMI Date Notice that it is entered into record 10003 The data is First Try Index Site Medical Record Notes Weight BMI Date 2590 AA 10003 First Try 189 31.4 02 May 2012 Help and advice, please. Thanks. Ethan -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Database Problems
On 5/2/2012 4:28 PM, Duken Marga wrote: But I don't see any attachments in this message. This was in the first email of this thread. I can easily extract data from the database. However, if I try to enter data, it goes into the incorrect record. Following are some screenshots. The program is attached. [pardon the comical names. This is a test, and any resemblance to true names is not intentional] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: No error reporting on
On 04/23/2012 01:21 PM, Dotan Cohen wrote: On Mon, Apr 23, 2012 at 14:18, Jim Ginerjim.gi...@albanyhandball.com wrote: Just my $.02, but don't you need: ini_set('display_errors', '1'); as well? Possibly, thanks. I actually don't have access to that! That line should be placed in your script. not the php.ini file -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP: a fractal of bad design
On 04/17/2012 05:43 AM, Bogdan Ribic wrote: Where's the Like button on this list? :) On 4/13/2012 01:44, Ross McKay wrote: On Wed, 11 Apr 2012 17:06:10 -0700, Daevid Vincent wrote: There are only two kinds of languages: the ones people complain about and the ones nobody uses. -- Bjarne Stroustrup a simple +1 will do -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork behavior with php version 5.1.2
On 03/29/2012 12:49 PM, Ralf Gnädinger wrote: Hi, i got some trouble with a PHP script using pcntl_fork do run some work in background. Runnig my script on my development system (PHP version 5.3.3-7) it behaves like intended. But running it on my production test system (PHP version PHP 5.1.2), i got some strange results. The problem is, that when i logout from my SSH session the console closes not properly, like somethings is kept open. Sadly, updating this old PHP version is not a option... :/ Does anyone have an idea whats going on? Thanks in advance Ralf The script is this: #!/usr/bin/env php ?php $pid = pcntl_fork(); if ($pid == -1) { die('Fork failed!'); } else if($pid 0) { exit(0); // close parent process } else { // child process: while(true) { sleep(10); // do your work -- stripped } } ? do not work with: PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies works with: PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH This sounds more like an OS issue then a PHP issue. What are the two OSs involved? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Thinking out loud - a continuation...
On 03/21/2012 11:39 AM, Jay Blanchard wrote: If you were me would you just generate the JSON? If not what is he best way to output an array that will nest properly for each subsequent query? Depends on where the data is coming from and how you are retrieving it from. Can you provide examples of the code that retrieves the data and some of the actual output data? Then provide a structure that you want the data to look like when done. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fgetcsv doesn't return an array?
On 03/15/2012 10:09 AM, Jay Blanchard wrote: I thought that fgetcsv returned an array. I can work with it like an array but I get the following warning when using it |Warning: implode(): Invalid arguments passed on line 155 154 $csvCurrentLine = fgetcsv($csvFile, 4096, ','); 155 $currentLine = implode(,, $csvCurrentLine); | Everything that I have read online indicates that it is because $csvCurrentLine is not declared as an array. Adding a line to the code 153 |$csvCurrentLine = array(); Does not get rid of the warning. The warning isn't interfering with the script working, but it us annoying. Does anyone know the solution? Thanks! Jay | From the manual fgetcsv() returns NULL if an invalid handle is supplied or FALSE on other errors, including end of file. do this 154 $csvCurrentLine = fgetcsv($csvFile, 4096, ','); var_dump($csvCurrentLine); 155 $currentLine = implode(,, $csvCurrentLine); What does it say about the variable from the failing line? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Have little enough hair as it is ...
On 03/12/2012 06:38 AM, Lester Caine wrote: Simon Schick wrote: I suggest that all done with this variable before is not of interest ... Assuming this, I'd say the following: Right here you are creating two strings within an array within an array. My guess is you will want to replace the $secondsGap[] with $secondsGap $secondsGap[] = array($gap[0] * 60, $gap[1] * 60); Implicit initializing of an array that has the following structure: array( array(int, int) ); OK $gap comes from the loop foreach(self::$timeGap as $gap) self::$timeGap is a list of pairs of numbers. if( isset($secondsGap[1]) ) { Trying to get the second element .. which will never happen if you haven't added an element before the snipped you pasted here. $gapName = $secondsGap[0].to.$secondsGap[1]; } else { $gapName = $secondsGap[0]; } [some-code] I'm quite unsure what you want to do here. If you'd update the first line as following it would always trigger the first condition: $secondsGap = array($gap[0] * 60, $gap[1] * 60); What this code is doing perfectly in PHP5.3 is generating the text string to display for each time period listed in the array of pairs of numbers ( some with a 'blank' second number and what the code returns is a string of the format '(number1)to(number2)' or simply '(number1)' - something fairly standard in PHP? But the nanny message says it need to be re-writen, the question is 'How?' :( -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function mktime() documentation question
On 03/08/2012 03:14 PM, Tedd Sperling wrote: On Mar 8, 2012, at 11:20 AM, Ford, Mike wrote: -Original Message- From: Tedd Sperling [mailto:tedd.sperl...@gmail.com] From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. Huh? The 0th day of next month *is* the last day of the current month, which gives you the number of days in the current month. QED. I think it's possible you may be being confuzled by the number of nexts and previouses floating around. Your mktime call is asking for the 0th day of next month, i.e. the last day of the previous month of next month, i.e. the last day of the current month. Which is exactly what you say works. I think. :) However, I agree that the description is not very well worded - saying that days in the requested month are relative to the previous month is very odd indeed if you ask me -- if they must be relative to anything, why not the beginning of the relevant month? Actually, with a bit more thought, I think I'd rewrite it something like this: The day number relative to the given month. Day numbers 1 to 28, 29, 30 or 31 (depending on the month) refer to the normal days in the month. Numbers less than 1 refer to days in the previous month, so 0 is the last day of the preceding month, -1 the day before that, etc. Numbers greater than the actual number of days in the month refer to days in the following month(s). Mike: Very well put. You say: Huh? The 0th day of next month *is* the last day of the current month, which gives you the number of days in the current month. That IS exactly what I am saying. But why does anyone have to use the next month to figure out how many days there are are in this month? Do you see my point? It would have been better if one could use: $what_date = getdate(mktime(0, 0, 0, $this_month, 0, $year)); $days_in_this_month = $what_date['nday']; // note an additional key for getdate() But instead, we have to use: $next_month = $this_month +1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_this_month = $what_date['mday']; Additionally, there's a perception problem. You say that 0 of the next month *is* the last day of the current month -- as such, apparently months overlap in your (and Dan's) explanation. Well... I agree with both of you, but my objection is having to increase the month value by one to get the number of days in the current month. That's all I was saying. Side-point: I find it interesting that getdate() has all sorts of neat descriptions for the current month (such as, what weekday a numbered day is), but lacks how many days are in the month. Doesn't that seem odd? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com I am surprised that nobody has come up with this one yet. $what_date = getdate(mktime(0, 0, 0, $this_month, 35, $year)); $days_in_this_month = 35 - $what_date['mday']; -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function mktime() documentation question
On 03/08/2012 04:24 PM, Jim Lucas wrote: On 03/08/2012 03:14 PM, Tedd Sperling wrote: On Mar 8, 2012, at 11:20 AM, Ford, Mike wrote: -Original Message- From: Tedd Sperling [mailto:tedd.sperl...@gmail.com] From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. Huh? The 0th day of next month *is* the last day of the current month, which gives you the number of days in the current month. QED. I think it's possible you may be being confuzled by the number of nexts and previouses floating around. Your mktime call is asking for the 0th day of next month, i.e. the last day of the previous month of next month, i.e. the last day of the current month. Which is exactly what you say works. I think. :) However, I agree that the description is not very well worded - saying that days in the requested month are relative to the previous month is very odd indeed if you ask me -- if they must be relative to anything, why not the beginning of the relevant month? Actually, with a bit more thought, I think I'd rewrite it something like this: The day number relative to the given month. Day numbers 1 to 28, 29, 30 or 31 (depending on the month) refer to the normal days in the month. Numbers less than 1 refer to days in the previous month, so 0 is the last day of the preceding month, -1 the day before that, etc. Numbers greater than the actual number of days in the month refer to days in the following month(s). Mike: Very well put. You say: Huh? The 0th day of next month *is* the last day of the current month, which gives you the number of days in the current month. That IS exactly what I am saying. But why does anyone have to use the next month to figure out how many days there are are in this month? Do you see my point? It would have been better if one could use: $what_date = getdate(mktime(0, 0, 0, $this_month, 0, $year)); $days_in_this_month = $what_date['nday']; // note an additional key for getdate() But instead, we have to use: $next_month = $this_month +1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_this_month = $what_date['mday']; Additionally, there's a perception problem. You say that 0 of the next month *is* the last day of the current month -- as such, apparently months overlap in your (and Dan's) explanation. Well... I agree with both of you, but my objection is having to increase the month value by one to get the number of days in the current month. That's all I was saying. Side-point: I find it interesting that getdate() has all sorts of neat descriptions for the current month (such as, what weekday a numbered day is), but lacks how many days are in the month. Doesn't that seem odd? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com I am surprised that nobody has come up with this one yet. $what_date = getdate(mktime(0, 0, 0, $this_month, 35, $year)); $days_in_this_month = 35 - $what_date['mday']; Even a one liner... $what_date = getdate(mktime(0,0,0,$this_month,35,$year)-(35 * 86400)); -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function mktime() documentation question
On 03/08/2012 04:31 PM, Jim Lucas wrote: On 03/08/2012 04:24 PM, Jim Lucas wrote: On 03/08/2012 03:14 PM, Tedd Sperling wrote: On Mar 8, 2012, at 11:20 AM, Ford, Mike wrote: -Original Message- From: Tedd Sperling [mailto:tedd.sperl...@gmail.com] From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. Huh? The 0th day of next month *is* the last day of the current month, which gives you the number of days in the current month. QED. I think it's possible you may be being confuzled by the number of nexts and previouses floating around. Your mktime call is asking for the 0th day of next month, i.e. the last day of the previous month of next month, i.e. the last day of the current month. Which is exactly what you say works. I think. :) However, I agree that the description is not very well worded - saying that days in the requested month are relative to the previous month is very odd indeed if you ask me -- if they must be relative to anything, why not the beginning of the relevant month? Actually, with a bit more thought, I think I'd rewrite it something like this: The day number relative to the given month. Day numbers 1 to 28, 29, 30 or 31 (depending on the month) refer to the normal days in the month. Numbers less than 1 refer to days in the previous month, so 0 is the last day of the preceding month, -1 the day before that, etc. Numbers greater than the actual number of days in the month refer to days in the following month(s). Mike: Very well put. You say: Huh? The 0th day of next month *is* the last day of the current month, which gives you the number of days in the current month. That IS exactly what I am saying. But why does anyone have to use the next month to figure out how many days there are are in this month? Do you see my point? It would have been better if one could use: $what_date = getdate(mktime(0, 0, 0, $this_month, 0, $year)); $days_in_this_month = $what_date['nday']; // note an additional key for getdate() But instead, we have to use: $next_month = $this_month +1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_this_month = $what_date['mday']; Additionally, there's a perception problem. You say that 0 of the next month *is* the last day of the current month -- as such, apparently months overlap in your (and Dan's) explanation. Well... I agree with both of you, but my objection is having to increase the month value by one to get the number of days in the current month. That's all I was saying. Side-point: I find it interesting that getdate() has all sorts of neat descriptions for the current month (such as, what weekday a numbered day is), but lacks how many days are in the month. Doesn't that seem odd? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com I am surprised that nobody has come up with this one yet. $what_date = getdate(mktime(0, 0, 0, $this_month, 35, $year)); $days_in_this_month = 35 - $what_date['mday']; Even a one liner... $what_date = getdate(mktime(0,0,0,$this_month,35,$year)-(35 * 86400)); Sorry, had my math backwards... $what_date = getdate((35 * 86400)-mktime(0,0,0,$this_month,35,$year)); -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function mktime() documentation question
On 03/08/2012 04:44 PM, Jim Lucas wrote: On 03/08/2012 04:31 PM, Jim Lucas wrote: On 03/08/2012 04:24 PM, Jim Lucas wrote: On 03/08/2012 03:14 PM, Tedd Sperling wrote: On Mar 8, 2012, at 11:20 AM, Ford, Mike wrote: -Original Message- From: Tedd Sperling [mailto:tedd.sperl...@gmail.com] From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. Huh? The 0th day of next month *is* the last day of the current month, which gives you the number of days in the current month. QED. I think it's possible you may be being confuzled by the number of nexts and previouses floating around. Your mktime call is asking for the 0th day of next month, i.e. the last day of the previous month of next month, i.e. the last day of the current month. Which is exactly what you say works. I think. :) However, I agree that the description is not very well worded - saying that days in the requested month are relative to the previous month is very odd indeed if you ask me -- if they must be relative to anything, why not the beginning of the relevant month? Actually, with a bit more thought, I think I'd rewrite it something like this: The day number relative to the given month. Day numbers 1 to 28, 29, 30 or 31 (depending on the month) refer to the normal days in the month. Numbers less than 1 refer to days in the previous month, so 0 is the last day of the preceding month, -1 the day before that, etc. Numbers greater than the actual number of days in the month refer to days in the following month(s). Mike: Very well put. You say: Huh? The 0th day of next month *is* the last day of the current month, which gives you the number of days in the current month. That IS exactly what I am saying. But why does anyone have to use the next month to figure out how many days there are are in this month? Do you see my point? It would have been better if one could use: $what_date = getdate(mktime(0, 0, 0, $this_month, 0, $year)); $days_in_this_month = $what_date['nday']; // note an additional key for getdate() But instead, we have to use: $next_month = $this_month +1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_this_month = $what_date['mday']; Additionally, there's a perception problem. You say that 0 of the next month *is* the last day of the current month -- as such, apparently months overlap in your (and Dan's) explanation. Well... I agree with both of you, but my objection is having to increase the month value by one to get the number of days in the current month. That's all I was saying. Side-point: I find it interesting that getdate() has all sorts of neat descriptions for the current month (such as, what weekday a numbered day is), but lacks how many days are in the month. Doesn't that seem odd? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com I am surprised that nobody has come up with this one yet. $what_date = getdate(mktime(0, 0, 0, $this_month, 35, $year)); $days_in_this_month = 35 - $what_date['mday']; Even a one liner... $what_date = getdate(mktime(0,0,0,$this_month,35,$year)-(35 * 86400)); Sorry, had my math backwards... $what_date = getdate((35 * 86400)-mktime(0,0,0,$this_month,35,$year)); Spoke too soon. Since you have to know the output of getdate() to calculate the minus figure... I guess that won't work. Use the first one that I suggested. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested database loops and completing an unordered list....
On 03/01/2012 06:20 PM, Jay Blanchard wrote: [snip] Can you show the output of the function above? [/snip] Doesn't this SQL query return everything that has company_id set to 3 which would it not contain all the data from the other queries combined into one large data set? At this point, I don't believe you have shown your output. Please show the output of your function. 0 SELECT DISTINCT `TIER1DATA` FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' Executives and Management Normally this query alone returns 9 rows of data. Each of these rows should be included in the next query where TIER1DATA = each of the nine in succession 1 SELECT DISTINCT `TIER2DATA` FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `TIER1DATA` = 'Executives and Management' Executives and ManagementLeadership 2 SELECT DISTINCT `TIER3DATA` FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `TIER2DATA` = 'Executives and ManagementLeadership' Executives and ManagementLeadershipManager 3 SELECT DISTINCT `BUSTIER1DATA` FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `TIER3DATA` = 'Executives and ManagementLeadershipManager' Knee 4 SELECT DISTINCT `BUSTIER2DATA` FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `BUSTIER1DATA` = 'Knee' KneeDIV01 5 SELECT DISTINCT `BUSTIER3DATA` FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `BUSTIER2DATA` = 'KneeDIV01' KneeDIV01DEPT02 6 SELECT DISTINCT `BUSTIER4DATA` FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `BUSTIER3DATA` = 'KneeDIV01DEPT02' KneeDIV01DEPT02GRP04 7 SELECT DISTINCT `` FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `BUSTIER4DATA` = 'KneeDIV01DEPT02GRP04' 1054Unknown column '' in 'field list' -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] curl equivalent in PHP
On 03/02/2012 06:26 AM, Nibin V M wrote: Hello, I am trying to display the website content through a php code ( my own websites; doesn't cause copy right issues ). I use curl to display the page via the following simple code. ?php $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, http://mytest.com;); curl_exec ($curl); curl_close ($curl); ? But on some of my servers, curl isn't enabled! Is there any equivalent code to achieve the same? Thank you, As long as you do not need to perform posts to the other website via the PHP request, you could include, file_get_contents, fopen + fread, etc... All you need to make sure is that allow_url_fopen is enabled. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php