Re: [PHP] PHP script won't run in the background
On 29/11/2011 17:16, Daniel Brown wrote: On Sat, Nov 19, 2011 at 09:33, richard gray wrote: This happens because PHP is writing to STDOUT, of course, and then the command line redirection grabs that information and puts it into the file. Unfortunately, by itself, this won't work in the background, which is why you're getting the SIGTTOU (SIGnal TTy OUput). If you need to redirect the output and have it run in the background (where something like file_put_contents() or fwrite() isn't a practical option), give it a NOHUP (NO Hang-UP): nohup php test.php > test.log & This will automatically redirect STDERR to STDOUT, save for the message telling you the same. Thanks for your reply Daniel unfortunately nohup makes no difference the script still stops with no output being logged -- and also on a different machine (Ubuntu) php -f test.php >test.log 2>&1 & -- works perfectly - seems to be an issue with OSX Lion and the version of PHP that came with the machine -- I cannot compile my own build of PHP because of this problem -> https://bugs.php.net/bug.php?id=60268 -- so I am completely stuck :( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
On 23/11/2011 18:49, Alain Williams wrote: On Wed, Nov 23, 2011 at 06:14:07PM +0100, richard gray wrote: Reading symbols for shared libraries + done 0x000101d057ee in __ioctl () Any clues? To me it looks like PHP cli is trying to do some I/O but I'm just a dumb developer... :) ioctl on a tty is typically used to set it into single character at a time mode (remove stty's icanon). It could have decided that since it is a tty then that should be set. You need a bit more info, get a backtrace with 'where'. Thanks for the response Alain - below is the output:- [rich@LeMans] (/Web/scripts)> gdb --pid=3294 GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin". /Web/scripts/3294: No such file or directory Attaching to process 3294. Reading symbols for shared libraries . done Reading symbols for shared libraries done Reading symbols for shared libraries + done 0x7fff8f8ac7ee in __ioctl () (gdb) where #0 0x7fff8f8ac7ee in __ioctl () #1 0x7fff8f8ac1fe in ioctl () #2 0x7fff910a6b1c in tcsetattr () #3 0x00010ab05df7 in tty_end () #4 0x00010ab05c39 in tty_init () #5 0x00010aaf7261 in el_init () #6 0x00010aafeb8e in rl_initialize () #7 0x00010a3ef39a in zm_startup_readline () #8 0x00010a37a1c8 in zend_startup_module_ex () #9 0x00010a38166b in zend_hash_apply () #10 0x00010a37d3dd in zend_startup_modules () #11 0x00010a3287bf in php_module_startup () #12 0x00010a3ef637 in php_cli_startup () #13 0x00010a3efff8 in main () -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
On Wed, Nov 30, 2011 at 12:58:26PM +0100, richard gray wrote: > On 29/11/2011 17:16, Daniel Brown wrote: > >On Sat, Nov 19, 2011 at 09:33, richard gray wrote: > >This happens because PHP is writing to STDOUT, of course, and then the > >command line redirection grabs that information and puts it into the > >file. Unfortunately, by itself, this won't work in the background, > >which is why you're getting the SIGTTOU (SIGnal TTy OUput). If you > >need to redirect the output and have it run in the background (where > >something like file_put_contents() or fwrite() isn't a practical > >option), give it a NOHUP (NO Hang-UP): nohup php test.php > test.log & > >This will automatically redirect STDERR to STDOUT, save for the > >message telling you the same. > > Thanks for your reply Daniel unfortunately nohup makes no difference the > script still stops with no output being logged -- and also on a > different machine (Ubuntu) php -f test.php >test.log 2>&1 & -- works > perfectly - seems to be an issue with OSX Lion and the version of PHP > that came with the machine -- I cannot compile my own build of PHP > because of this problem -> https://bugs.php.net/bug.php?id=60268 -- so I > am completely stuck :( The point is that you need to completely disassociate the process from the tty. Install the daemonize program, then use it to run your PHP script. See: http://software.clapper.org/daemonize/ It claims to run under OSx (which is just BSD Unix). -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script won't run in the background
On Wed, Nov 30, 2011 at 01:01:48PM +0100, richard gray wrote: > >You need a bit more info, get a backtrace with 'where'. > Thanks for the response Alain - below is the output:- Ah, much more useful . > [rich@LeMans] (/Web/scripts)> gdb --pid=3294 > GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 > UTC 2011) > Copyright 2004 Free Software Foundation, Inc. > GDB is free software, covered by the GNU General Public License, and you are > welcome to change it and/or distribute copies of it under certain > conditions. > Type "show copying" to see the conditions. > There is absolutely no warranty for GDB. Type "show warranty" for details. > This GDB was configured as "x86_64-apple-darwin". > /Web/scripts/3294: No such file or directory > Attaching to process 3294. > Reading symbols for shared libraries . done > Reading symbols for shared libraries > > > done > Reading symbols for shared libraries + done > 0x7fff8f8ac7ee in __ioctl () > (gdb) where > #0 0x7fff8f8ac7ee in __ioctl () > #1 0x7fff8f8ac1fe in ioctl () > #2 0x7fff910a6b1c in tcsetattr () OK - it is setting tty modes as I suspected. > #3 0x00010ab05df7 in tty_end () > #4 0x00010ab05c39 in tty_init () > #5 0x00010aaf7261 in el_init () > #6 0x00010aafeb8e in rl_initialize () > #7 0x00010a3ef39a in zm_startup_readline () This is the readline routine ... probably setting the tty to raw mode, thus the tcsetattr() above. Look at the link below, it is how your CLI version of PHP is compiled: http://www.php.net/manual/en/readline.installation.php readline is mentioned as part of CLI: http://www.php.net/manual/en/features.commandline.usage.php > #8 0x00010a37a1c8 in zend_startup_module_ex () > #9 0x00010a38166b in zend_hash_apply () > #10 0x00010a37d3dd in zend_startup_modules () > #11 0x00010a3287bf in php_module_startup () > #12 0x00010a3ef637 in php_cli_startup () This is done BEFORE your script starts - so nothing that you can do to stop it. > #13 0x00010a3efff8 in main () Try the daemonize that I wrote about a few minutes ago. -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Yaf_Route
Hey Laruence, I have tried the below example, but did not really get it work. My code looks like this: public function _initRoute(Yaf_Dispatcher $dispatcher) { $route = new Yaf_Route_Regex ( "#(.*)#", array( "controller" => "index", "action" => "index", ), array( 1 => "test", ) ); Yaf_Router::addRoute ('regex', $route); } Any ideas about what I am doing wrong? Thx, edi 2011/11/28 Laruence > HI: > Yaf designd a route statck to proviods the ability for extends route > process. > > you can add new route into stack by calling > Yaf_Router::addRoute(or addConfig), > > when a request coming , Yaf will call the top route in the stack at > the first time, as pseudo codes like: > > while ($route = pop($stack)) { > if ($route->route($request) == TRUE) { > return FINISH. > } > } > > > there are two routes defined by Yaf are always return TRUE, that > are Yaf_Route_Simple and Yaf_Route_Static. > > so according your question, the easiest way is reigster a > Yaf_Route_Simple route with no-sence parameters, then all the request > will be routed to default controller and default action. > > > and also you can use Yaf_Route_Regex, it is the most felixible > route in Yaf: > http://www.php.net/manual/en/yaf-route-rewrite.construct.php > > the first argument for Yaf_Route_Regex::__construct is used to match > a uri, if the uri doesn't match this value, then the Yaf_Route_Regex > will don't route this request, just simple return FALSE, so we > can register a Regex route at the Bootstrap like: > > >public function _initRoute(Yaf_Dispatcher $dispatcher) { >$route = new Yaf_Route_Regex ( >"#(.*)#", >array( >"controller" => "product", >"action" => "info", >), >array( >1 => "test", >) >); >$router->addRoute('regex', $route); >} > >see the code above, we set the first argument to Yaf_Route_Regex a > value : "#(.*)#", which means this route will match any request-uri. > >then we can assign any controller/action pair for this route > result in the second argument. > >the last argument means, the first captrue in the regex pattern > will be named "test" in the $request::_$params, that is you can access > this value by calling $request->getParam("test"). > > >I have updates some new docs at php.net, but it need a little time > to show up.and I will keep updating :) > >PS: I am going to cc this mail to php-generall list, then if any > other people have the sampe question, they will find this :) > > thanks very much for you interesting of Yaf :) > > > 2011/11/28 Moldován Eduárd : > > Oh, I forgot something. An example of a complete application.ini and > ways to > > get the config values with YaF would be great! > > Thx ahead, > > edi > > > > > > > > 2011.11.27. dátummal, 14:49 időpontban Laruence írta: > > > > HI: > >I have update some new docs into Yaf doc(php.net), but it will > take a > > little time to show up. > >and sure, could you give me some specific questions? I will answer > you > > :) > >also, I will add some new examples soon :) > > thanks very much for your interesting of Yaf > > :) > > 2011/11/27 Moldován Eduárd > >> > >> Hey there, > >> > >> I started working a bit with YaF, but it looks like the documentation is > >> very rare. Could you tell me please where any documentation can be > found on > >> routing? > >> Any example maybe? > >> I would actually welcome any kind of documentation, on any part of YaF > >> (Except what I already found on php.net and code.google.com). > >> > >> Thx, > >> edi > >> > >> -- > >> Moldován Eduárd > >> boxed.hu > >> e...@boxed.hu > >> +36 30 691 2 691 > >> skype: edimoldovan > > > > > > -- > > Laruence Xinchen Hui > > http://www.laruence.com/ > > > > > > -- > Laruence Xinchen Hui > http://www.laruence.com/ > -- *Moldován Eduárd* boxed.hu e...@boxed.hu +36 30 691 2 691 skype: edimoldovan
[PHP] Re: Yaf_Route
Hi: Yaf_Router::addRoute is not a static method. you should do like: $dispatcher->getRouter()->addRoute("regex", $route); // http://www.php.net/manual/en/yaf-dispatcher.getrouter.php btw: when you in development environ, it is useful to keep error_reporting on and look at error_log when you get some problems :) thanks 2011/11/30 Eduárd Moldovan > Hey Laruence, > > I have tried the below example, but did not really get it work. > My code looks like this: > > public function _initRoute(Yaf_Dispatcher $dispatcher) { > > $route = new Yaf_Route_Regex ( > "#(.*)#", > array( > "controller" => "index", > "action" => "index", > > ), > array( > 1 => "test", > ) > ); > > Yaf_Router::addRoute ('regex', $route); > } > > Any ideas about what I am doing wrong? > > Thx, > edi > > 2011/11/28 Laruence > >> HI: >> Yaf designd a route statck to proviods the ability for extends route >> process. >> >> you can add new route into stack by calling >> Yaf_Router::addRoute(or addConfig), >> >> when a request coming , Yaf will call the top route in the stack at >> the first time, as pseudo codes like: >> >> while ($route = pop($stack)) { >> if ($route->route($request) == TRUE) { >> return FINISH. >> } >> } >> >> >> there are two routes defined by Yaf are always return TRUE, that >> are Yaf_Route_Simple and Yaf_Route_Static. >> >> so according your question, the easiest way is reigster a >> Yaf_Route_Simple route with no-sence parameters, then all the request >> will be routed to default controller and default action. >> >> >> and also you can use Yaf_Route_Regex, it is the most felixible >> route in Yaf: >> http://www.php.net/manual/en/yaf-route-rewrite.construct.php >> >> the first argument for Yaf_Route_Regex::__construct is used to match >> a uri, if the uri doesn't match this value, then the Yaf_Route_Regex >> will don't route this request, just simple return FALSE, so we >> can register a Regex route at the Bootstrap like: >> >> >>public function _initRoute(Yaf_Dispatcher $dispatcher) { >>$route = new Yaf_Route_Regex ( >>"#(.*)#", >>array( >>"controller" => "product", >>"action" => "info", >>), >>array( >>1 => "test", >>) >>); >>$router->addRoute('regex', $route); >>} >> >>see the code above, we set the first argument to Yaf_Route_Regex a >> value : "#(.*)#", which means this route will match any request-uri. >> >>then we can assign any controller/action pair for this route >> result in the second argument. >> >>the last argument means, the first captrue in the regex pattern >> will be named "test" in the $request::_$params, that is you can access >> this value by calling $request->getParam("test"). >> >> >>I have updates some new docs at php.net, but it need a little time >> to show up.and I will keep updating :) >> >>PS: I am going to cc this mail to php-generall list, then if any >> other people have the sampe question, they will find this :) >> >> thanks very much for you interesting of Yaf :) >> >> >> 2011/11/28 Moldován Eduárd : >> > Oh, I forgot something. An example of a complete application.ini and >> ways to >> > get the config values with YaF would be great! >> > Thx ahead, >> > edi >> > >> > >> > >> > 2011.11.27. dátummal, 14:49 időpontban Laruence >> írta: >> > >> > HI: >> >I have update some new docs into Yaf doc(php.net), but it will >> take a >> > little time to show up. >> >and sure, could you give me some specific questions? I will answer >> you >> > :) >> >also, I will add some new examples soon :) >> > thanks very much for your interesting of Yaf >> > :) >> > 2011/11/27 Moldován Eduárd >> >> >> >> Hey there, >> >> >> >> I started working a bit with YaF, but it looks like the documentation >> is >> >> very rare. Could you tell me please where any documentation can be >> found on >> >> routing? >> >> Any example maybe? >> >> I would actually welcome any kind of documentation, on any part of YaF >> >> (Except what I already found on php.net and code.google.com). >> >> >> >> Thx, >> >> edi >> >> >> >> -- >> >> Moldován Eduárd >> >> boxed.hu >> >> e...@boxed.hu >> >> +36 30 691 2 691 >> >> skype: edimoldovan >> > >> > >> > -- >> > Laruence Xinchen Hui >> > http://www.laruence.com/ >> > >> >> >> >> -- >> Laruence Xinchen Hui >> http://www.laruence.com/ >> > > > > -- > *Moldován Eduárd* > > boxed.hu > e...@boxed.hu > +36 30 691 2 691 > skype: edimoldovan > > -- Laruence Xinchen Hui http://www.laruence.com/
[PHP] Re: Yaf_Route
Hello, That worked like a charm! Thx! I thought that the error reporting was on, sorry for that. edi 2011/11/30 Laruence > Hi: > Yaf_Router::addRoute is not a static method. > > you should do like: > > $dispatcher->getRouter()->addRoute("regex", $route); // > http://www.php.net/manual/en/yaf-dispatcher.getrouter.php > > > btw: when you in development environ, it is useful to keep > error_reporting on and look at error_log when you get some problems :) > > thanks > > > 2011/11/30 Eduárd Moldovan > >> Hey Laruence, >> >> I have tried the below example, but did not really get it work. >> My code looks like this: >> >> public function _initRoute(Yaf_Dispatcher $dispatcher) { >> >> $route = new Yaf_Route_Regex ( >> "#(.*)#", >> array( >> "controller" => "index", >> "action" => "index", >> >> ), >> array( >> 1 => "test", >> ) >> ); >> >> Yaf_Router::addRoute ('regex', $route); >> } >> >> Any ideas about what I am doing wrong? >> >> Thx, >> edi >> >> 2011/11/28 Laruence >> >>> HI: >>> Yaf designd a route statck to proviods the ability for extends route >>> process. >>> >>> you can add new route into stack by calling >>> Yaf_Router::addRoute(or addConfig), >>> >>> when a request coming , Yaf will call the top route in the stack at >>> the first time, as pseudo codes like: >>> >>> while ($route = pop($stack)) { >>> if ($route->route($request) == TRUE) { >>> return FINISH. >>> } >>> } >>> >>> >>> there are two routes defined by Yaf are always return TRUE, that >>> are Yaf_Route_Simple and Yaf_Route_Static. >>> >>> so according your question, the easiest way is reigster a >>> Yaf_Route_Simple route with no-sence parameters, then all the request >>> will be routed to default controller and default action. >>> >>> >>> and also you can use Yaf_Route_Regex, it is the most felixible >>> route in Yaf: >>> http://www.php.net/manual/en/yaf-route-rewrite.construct.php >>> >>> the first argument for Yaf_Route_Regex::__construct is used to match >>> a uri, if the uri doesn't match this value, then the Yaf_Route_Regex >>> will don't route this request, just simple return FALSE, so we >>> can register a Regex route at the Bootstrap like: >>> >>> >>>public function _initRoute(Yaf_Dispatcher $dispatcher) { >>>$route = new Yaf_Route_Regex ( >>>"#(.*)#", >>>array( >>>"controller" => "product", >>>"action" => "info", >>>), >>>array( >>>1 => "test", >>>) >>>); >>>$router->addRoute('regex', $route); >>>} >>> >>>see the code above, we set the first argument to Yaf_Route_Regex a >>> value : "#(.*)#", which means this route will match any request-uri. >>> >>>then we can assign any controller/action pair for this route >>> result in the second argument. >>> >>>the last argument means, the first captrue in the regex pattern >>> will be named "test" in the $request::_$params, that is you can access >>> this value by calling $request->getParam("test"). >>> >>> >>>I have updates some new docs at php.net, but it need a little time >>> to show up.and I will keep updating :) >>> >>>PS: I am going to cc this mail to php-generall list, then if any >>> other people have the sampe question, they will find this :) >>> >>> thanks very much for you interesting of Yaf :) >>> >>> >>> 2011/11/28 Moldován Eduárd : >>> > Oh, I forgot something. An example of a complete application.ini and >>> ways to >>> > get the config values with YaF would be great! >>> > Thx ahead, >>> > edi >>> > >>> > >>> > >>> > 2011.11.27. dátummal, 14:49 időpontban Laruence >>> írta: >>> > >>> > HI: >>> >I have update some new docs into Yaf doc(php.net), but it will >>> take a >>> > little time to show up. >>> >and sure, could you give me some specific questions? I will >>> answer you >>> > :) >>> >also, I will add some new examples soon :) >>> > thanks very much for your interesting of Yaf >>> > :) >>> > 2011/11/27 Moldován Eduárd >>> >> >>> >> Hey there, >>> >> >>> >> I started working a bit with YaF, but it looks like the documentation >>> is >>> >> very rare. Could you tell me please where any documentation can be >>> found on >>> >> routing? >>> >> Any example maybe? >>> >> I would actually welcome any kind of documentation, on any part of YaF >>> >> (Except what I already found on php.net and code.google.com). >>> >> >>> >> Thx, >>> >> edi >>> >> >>> >> -- >>> >> Moldován Eduárd >>> >> boxed.hu >>> >> e...@boxed.hu >>> >> +36 30 691 2 691 >>> >> skype: edimoldovan >>> > >>> > >>> > -- >>> > Laruence Xinchen Hui >>> > http://www.laruence.com/ >>> > >>> >>> >>> >>> -- >>> Laruence Xinchen Hui >>> http://www.laruence.com/ >>> >> >> >> >> -- >> *Moldován Eduárd* >> >> boxed
[PHP] yaf modules and plugins
Hey Laruence, I have another more questions. Modules and plugins. How do they work, how are they loaded? In my current php framework database is a module, cache also. There are no plugins there. Thx in advance, edi Moldován Eduárd boxed.hu e...@boxed.hu +36 30 691 2 691 skype: edimoldovan
[PHP] mcrypt_encrypt help needed
Hello all. I am using the following function to encrypt a string: define('SALT', 'myvalueforsalthere'); function encrypt($text) { return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND; } and then: $myval="hello"; $mayval= encrypt($myval); echo decrypt($myval); returns "hello" great. But when my input string is more complicated I get unprintable characters out of the decyrpt side: $myval="var1=1&var2=2&var3=3"; The above when decrypted will spit out a string of unprintable characters. Is encrypt/decrypt choking on the "=" sign? I tried: $myval=htmlentities($myval); But it did not work. Any help is appreciated. Thanks, --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mcrypt_encrypt help needed
On Wed, Nov 30, 2011 at 9:57 PM, Rick Dwyer wrote: > Hello all. > > I am using the following function to encrypt a string: > > define('SALT', 'myvalueforsalthere'); > > function encrypt($text) > { > return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, > $text, MCRYPT_MODE_ECB, > mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), > MCRYPT_RAND; > } > Can you post your decrypt function too? You create a random IV here, don't you need that IV to decrypt too? > The above when decrypted will spit out a string of unprintable characters. > Is encrypt/decrypt choking on the "=" sign? I tried: > > $myval=htmlentities($myval); > > But it did not work. Any help is appreciated. I doubt it's choking on anything. htmlentities is only for safe output to browser, you can always check the 'real' value by looking at the page source in your browser. Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mcrypt_encrypt help needed
On Wed, Nov 30, 2011 at 3:57 PM, Rick Dwyer wrote: > Hello all. > > I am using the following function to encrypt a string: > > define('SALT', 'myvalueforsalthere'); > > function encrypt($text) > { >return trim(base64_encode(mcrypt_**encrypt(MCRYPT_RIJNDAEL_256, SALT, > $text, MCRYPT_MODE_ECB, > mcrypt_create_iv(mcrypt_get_**iv_size(MCRYPT_RIJNDAEL_256, > MCRYPT_MODE_ECB), MCRYPT_RAND; > } > > and then: > > $myval="hello"; > $mayval= encrypt($myval); > > > echo decrypt($myval); > > returns "hello" great. > > > > But when my input string is more complicated I get unprintable characters > out of the decyrpt side: > > $myval="var1=1&var2=2&var3=3"; > > The above when decrypted will spit out a string of unprintable characters. > Is encrypt/decrypt choking on the "=" sign? I tried: > > $myval=htmlentities($myval); > > But it did not work. Any help is appreciated. > > Thanks, > > --Rick > Hi Rick, Can you show us the decrypt function, too (even though it should be just the reverse order of operations using a decrypt function, I'd just like to double check it before commenting.) By the way, I wouldn't recommend using ECB mode unless you have a special circumstance: http://www.quora.com/Is-AES-ECB-mode-useful-for-anything Adam (Sorry for the duplicate, Rick, I forgot to reply all the first time.) -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
Re: [PHP] mcrypt_encrypt help needed
On Wed, Nov 30, 2011 at 4:14 PM, Matijn Woudt wrote: > On Wed, Nov 30, 2011 at 9:57 PM, Rick Dwyer wrote: > > Hello all. > > > > I am using the following function to encrypt a string: > > > > define('SALT', 'myvalueforsalthere'); > > > > function encrypt($text) > > { > >return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, > > $text, MCRYPT_MODE_ECB, > > mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, > MCRYPT_MODE_ECB), > > MCRYPT_RAND; > > } > > > > Can you post your decrypt function too? > > You create a random IV here, don't you need that IV to decrypt too? > > You're normally right, Matijn, However, ECB mode doesn't use an IV, so even though he's generating an IV, it's not being used (and, the benefit of an IV is one of the main reasons you try to avoid ECB.) Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
Re: [PHP] mcrypt_encrypt help needed
On Wed, Nov 30, 2011 at 10:18 PM, Adam Richardson wrote: > On Wed, Nov 30, 2011 at 4:14 PM, Matijn Woudt wrote: > >> On Wed, Nov 30, 2011 at 9:57 PM, Rick Dwyer wrote: >> > Hello all. >> > >> > I am using the following function to encrypt a string: >> > >> > define('SALT', 'myvalueforsalthere'); >> > >> > function encrypt($text) >> > { >> > return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, >> > $text, MCRYPT_MODE_ECB, >> > mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, >> MCRYPT_MODE_ECB), >> > MCRYPT_RAND; >> > } >> > >> >> Can you post your decrypt function too? >> >> You create a random IV here, don't you need that IV to decrypt too? >> >> > You're normally right, Matijn, > > However, ECB mode doesn't use an IV, so even though he's generating an IV, > it's not being used (and, the benefit of an IV is one of the main reasons > you try to avoid ECB.) > > Adam Ah, I see, you're right. I thought he was using CBC (which I would recommend). That also means that example #1 is wrong at mcrypt_encrypt help page[1]. Matijn [1] http://php.net/manual/en/function.mcrypt-encrypt.php#example-884 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mcrypt_encrypt help needed
On Wed, Nov 30, 2011 at 4:25 PM, Matijn Woudt wrote: > On Wed, Nov 30, 2011 at 10:18 PM, Adam Richardson > wrote: > > On Wed, Nov 30, 2011 at 4:14 PM, Matijn Woudt wrote: > > > >> On Wed, Nov 30, 2011 at 9:57 PM, Rick Dwyer > wrote: > >> > Hello all. > >> > > >> > I am using the following function to encrypt a string: > >> > > >> > define('SALT', 'myvalueforsalthere'); > >> > > >> > function encrypt($text) > >> > { > >> >return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, > >> > $text, MCRYPT_MODE_ECB, > >> > mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, > >> MCRYPT_MODE_ECB), > >> > MCRYPT_RAND; > >> > } > >> > > >> > >> Can you post your decrypt function too? > >> > >> You create a random IV here, don't you need that IV to decrypt too? > >> > >> > > You're normally right, Matijn, > > > > However, ECB mode doesn't use an IV, so even though he's generating an > IV, > > it's not being used (and, the benefit of an IV is one of the main reasons > > you try to avoid ECB.) > > > > Adam > > Ah, I see, you're right. I thought he was using CBC (which I would > recommend). > That also means that example #1 is wrong at mcrypt_encrypt help page[1]. > > Matijn > > [1] http://php.net/manual/en/function.mcrypt-encrypt.php#example-884 > Nice catch in the documentation, Matijn. While it will encrypt and decrypt successfully, the IV isn't being used, so it would seem to be a better illustration of use of someone switched the mode to one that's using the IV. Someone with access to the documents want to make the change to one of the other modes (as Matijn pointed out, CBC is pretty common?) Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
Re: [PHP] mcrypt_encrypt help needed
On Wed, Nov 30, 2011 at 10:34 PM, Adam Richardson wrote: > On Wed, Nov 30, 2011 at 4:25 PM, Matijn Woudt wrote: > >> On Wed, Nov 30, 2011 at 10:18 PM, Adam Richardson >> wrote: >> > On Wed, Nov 30, 2011 at 4:14 PM, Matijn Woudt wrote: >> > >> >> On Wed, Nov 30, 2011 at 9:57 PM, Rick Dwyer >> wrote: >> >> > Hello all. >> >> > >> >> > I am using the following function to encrypt a string: >> >> > >> >> > define('SALT', 'myvalueforsalthere'); >> >> > >> >> > function encrypt($text) >> >> > { >> >> > return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, >> >> > $text, MCRYPT_MODE_ECB, >> >> > mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, >> >> MCRYPT_MODE_ECB), >> >> > MCRYPT_RAND; >> >> > } >> >> > >> >> >> >> Can you post your decrypt function too? >> >> >> >> You create a random IV here, don't you need that IV to decrypt too? >> >> >> >> >> > You're normally right, Matijn, >> > >> > However, ECB mode doesn't use an IV, so even though he's generating an >> IV, >> > it's not being used (and, the benefit of an IV is one of the main reasons >> > you try to avoid ECB.) >> > >> > Adam >> >> Ah, I see, you're right. I thought he was using CBC (which I would >> recommend). >> That also means that example #1 is wrong at mcrypt_encrypt help page[1]. >> >> Matijn >> >> [1] http://php.net/manual/en/function.mcrypt-encrypt.php#example-884 >> > > Nice catch in the documentation, Matijn. While it will encrypt and decrypt > successfully, the IV isn't being used, so it would seem to be a better > illustration of use of someone switched the mode to one that's using the IV. > > Someone with access to the documents want to make the change to one of the > other modes (as Matijn pointed out, CBC is pretty common?) > > Adam I tried to submit a bug report, but the PHP version that comes with Ubuntu Server (oneiric) is 5.3.6, and they only accept bug reports from version 5.3.8 and above. If anyone else wants to, please do so. In that case, there's a second related bug, which is that mcrypt_get_iv_size does not return 0 for ECB modes, which it should (as the documentation also notes). Matijn > -- > Nephtali: A simple, flexible, fast, and security-focused PHP framework > http://nephtaliproject.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mcrypt_encrypt help needed
My decrypt is below: $myval=$_GET["myval"]; // let the encryption begin define('SALT', 'myvalueforsalthere'); function decrypt($text) { return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))); } echo decrypt($myval); --Rick On Nov 30, 2011, at 4:14 PM, Adam Richardson wrote: On Wed, Nov 30, 2011 at 3:57 PM, Rick Dwyer wrote: Hello all. I am using the following function to encrypt a string: define('SALT', 'myvalueforsalthere'); function encrypt($text) { return trim(base64_encode(mcrypt_**encrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_**iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND; } and then: $myval="hello"; $mayval= encrypt($myval); echo decrypt($myval); returns "hello" great. But when my input string is more complicated I get unprintable characters out of the decyrpt side: $myval="var1=1&var2=2&var3=3"; The above when decrypted will spit out a string of unprintable characters. Is encrypt/decrypt choking on the "=" sign? I tried: $myval=htmlentities($myval); But it did not work. Any help is appreciated. Thanks, --Rick Hi Rick, Can you show us the decrypt function, too (even though it should be just the reverse order of operations using a decrypt function, I'd just like to double check it before commenting.) By the way, I wouldn't recommend using ECB mode unless you have a special circumstance: http://www.quora.com/Is-AES-ECB-mode-useful-for-anything Adam (Sorry for the duplicate, Rick, I forgot to reply all the first time.) -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] compare dates
I'm puzzled why the if statement executes as true when the first date (job_closedate) is not less than the second date (now). The if statement claims that "12/02/2011" is less than "11/30/2011". if (date("m/d/Y",strtotime($jobs_closedate)) <= date("m/d/Y",strtotime("now"))){ echo date("m/d/Y",strtotime($jobs_closedate)); // displays - 12/02/2011 echo date("m/d/Y",strtotime("now")); // displays - 11/30/2011 $error.="The close date must be later than today's date, " . date("m/d/Y",strtotime("now")) . ".\n"; } If the first date is "11/16/2011" the if statement also executes as true which is correct since "11/16/2011" is less than "11/30/2011". Marc
Re: [PHP] compare dates
On Wed, Nov 30, 2011 at 11:00 PM, Marc Fromm wrote: > I'm puzzled why the if statement executes as true when the first date > (job_closedate) is not less than the second date (now). > The if statement claims that "12/02/2011" is less than "11/30/2011". > > if (date("m/d/Y",strtotime($jobs_closedate)) <= > date("m/d/Y",strtotime("now"))){ You're comparing strings here, try to compare the unix timestamp: if (strtotime($jobs_closedate) <= strtotime("now")){ That'll probably do what you want.. Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mcrypt_encrypt help needed
On Wed, Nov 30, 2011 at 10:57 PM, Rick Dwyer wrote: > My decrypt is below: > > $myval=$_GET["myval"]; > > > // let the encryption begin > > define('SALT', 'myvalueforsalthere'); > > function decrypt($text) > { > return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, > base64_decode($text), MCRYPT_MODE_ECB, > mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), > MCRYPT_RAND))); > } > > echo decrypt($myval); > > Your decrypt function seems fine, and the encrypt/decrypt functions work fine both in the same file for me. Now you say you use $_GET["myval"], which means you get them from URL. Base64 is not URL safe, have you used urlencode()? Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mcrypt_encrypt help needed
On Nov 30, 2011, at 5:13 PM, Matijn Woudt wrote: Your decrypt function seems fine, and the encrypt/decrypt functions work fine both in the same file for me. Now you say you use $_GET["myval"], which means you get them from URL. Base64 is not URL safe, have you used urlencode()? Matijn OK, the problem appears to be that my string encoded contains a + symbol: Sw+ht0agaQRBpFlfHSucpYZ So I rawurlencode it and if I echo it out, it appears correctly on the page as: Sw%2Bht0agaQRBpFlfHSucpYZ BUT... when I pass this encrypted value off to PayPal (I'm integrating with them), encoded, when they return me to my site, instead of passing me my value as above, they are somehow decoding back to the original: Sw+ht0agaQRBpFlfHSucpYZ As I can see it in the URL. The + symbol is then interpretted as a space instead of + symbol and a result, my decrypt function fails. So I send off the encrypted value encoded to PayPal but when they go to redirect back to my site after payment has been made, instead of the url with Sw%2Bht0agaQRBpFlfHSucpYZ in it, they are decoding it so my url contains Sw+ht0agaQRBpFlfHSucpYZ which causes me problems. Is there alternative encrypting scheme that will not need url encoding (so I can be sure the passed url back from PayPal is ok as is)? --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mcrypt_encrypt help needed
On Thu, Dec 1, 2011 at 1:14 AM, Rick Dwyer wrote: > On Nov 30, 2011, at 5:13 PM, Matijn Woudt wrote: >>> >> >> Your decrypt function seems fine, and the encrypt/decrypt functions >> work fine both in the same file for me. Now you say you use >> $_GET["myval"], which means you get them from URL. Base64 is not URL >> safe, have you used urlencode()? >> >> Matijn >> > > > OK, the problem appears to be that my string encoded contains a + symbol: > > Sw+ht0agaQRBpFlfHSucpYZ > > So I rawurlencode it and if I echo it out, it appears correctly on the page > as: > > Sw%2Bht0agaQRBpFlfHSucpYZ > > BUT... when I pass this encrypted value off to PayPal (I'm integrating with > them), encoded, when they return me to my site, instead of passing me my > value as above, they are somehow decoding back to the original: > > Sw+ht0agaQRBpFlfHSucpYZ > > As I can see it in the URL. The + symbol is then interpretted as a space > instead of + symbol and a result, my decrypt function fails. > > So I send off the encrypted value encoded to PayPal but when they go to > redirect back to my site after payment has been made, instead of the url > with Sw%2Bht0agaQRBpFlfHSucpYZ in it, they are decoding it so my url > contains Sw+ht0agaQRBpFlfHSucpYZ which causes me problems. > > Is there alternative encrypting scheme that will not need url encoding (so I > can be sure the passed url back from PayPal is ok as is)? > > --Rick It seems normal to me that it is decoded, I think that's how it's supposed to work. How about urlencoding it twice? That might just work. Other possibility is to send it as a string of hex characters using hex2bin or something like that. Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mcrypt_encrypt help needed
On Nov 30, 2011, at 7:38 PM, Matijn Woudt wrote: On Thu, Dec 1, 2011 at 1:14 AM, Rick Dwyer wrote: On Nov 30, 2011, at 5:13 PM, Matijn Woudt wrote: Your decrypt function seems fine, and the encrypt/decrypt functions work fine both in the same file for me. Now you say you use $_GET["myval"], which means you get them from URL. Base64 is not URL safe, have you used urlencode()? Matijn OK, the problem appears to be that my string encoded contains a + symbol: Sw+ht0agaQRBpFlfHSucpYZ So I rawurlencode it and if I echo it out, it appears correctly on the page as: Sw%2Bht0agaQRBpFlfHSucpYZ BUT... when I pass this encrypted value off to PayPal (I'm integrating with them), encoded, when they return me to my site, instead of passing me my value as above, they are somehow decoding back to the original: Sw+ht0agaQRBpFlfHSucpYZ As I can see it in the URL. The + symbol is then interpretted as a space instead of + symbol and a result, my decrypt function fails. So I send off the encrypted value encoded to PayPal but when they go to redirect back to my site after payment has been made, instead of the url with Sw%2Bht0agaQRBpFlfHSucpYZ in it, they are decoding it so my url contains Sw+ht0agaQRBpFlfHSucpYZ which causes me problems. Is there alternative encrypting scheme that will not need url encoding (so I can be sure the passed url back from PayPal is ok as is)? --Rick It seems normal to me that it is decoded, I think that's how it's supposed to work. How about urlencoding it twice? That might just work. Other possibility is to send it as a string of hex characters using hex2bin or something like that. Matijn Yes! Thanks, double urlencoding it did the trick. I first encrypt it followed by a double rawurlencode. Thanks... my head was beginning to really hurt from banging it on the wall. --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] compare dates
On Nov 30, 2011, at 5:04 PM, Matijn Woudt wrote: > On Wed, Nov 30, 2011 at 11:00 PM, Marc Fromm wrote: >> I'm puzzled why the if statement executes as true when the first date >> (job_closedate) is not less than the second date (now). >> The if statement claims that "12/02/2011" is less than "11/30/2011". >> >>if (date("m/d/Y",strtotime($jobs_closedate)) <= >> date("m/d/Y",strtotime("now"))){ > > You're comparing strings here, try to compare the unix timestamp: > > if (strtotime($jobs_closedate) <= strtotime("now")){ > > That'll probably do what you want.. > > Matijn > Another way to do it would be: if(strtotime($jobs_closedate)<=time()) { } or if(date("Y-m-d",strtotime($job_closedate))<=date("Y-m-d",time()) { } Take care, Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php