martes, 9 de diciembre de 2014

php log variables to file

a quick way to view a variable content without interrupt the webpage with a var_dump or print_r


file_put_contents('/path_to_file/file.txt', var_export($variable, true));

jueves, 8 de mayo de 2014

testing mod rewrite apache

file .htaccess
RewriteEngine On 
RewriteRule ^.*$ index.php

file index.php
<?php
print 'mod_rewrite works!';
?>

Simply put this two files in /var/www/test_mod_rewrite and from the browser call localhost/test_mod_rewrite. "mod_rewrite_works!" should be printed

sábado, 26 de abril de 2014

move dropbox folder in debian



You could just create a symlink to ~/Dropbox

ln -s <dir-that-you-want-to-sync> ~/Dropbox

domingo, 16 de febrero de 2014

php json header


For JSON:

header('Content-Type: application/json');


For JSON-P:

header('Content-Type: application/javascript');

martes, 11 de febrero de 2014

fatal error: libcouchbase/couchbase.h: No such file or directory

Installing couchbase library from php I found this little fatal error:

fatal error: libcouchbase/couchbase.h: No such file or directory

This is because the C library not was installed properly. Just run:

sudo wget -O /etc/apt/sources.list.d/couchbase.list packages.couchbase.com/ubuntu/couchbase-ubuntu1204.list 
wget -O- packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add - 
sudo apt-get update 
sudo apt-get install libcouchbase2 libcouchbase-dev

and then:

sudo apt-get install php-pear 
sudo pecl install couchbase 
sudo apt-get install build-essential
Update php.ini with extension=couchbase.so and restart apache.

lunes, 10 de febrero de 2014

Couchbase cbrestore example

Finally I can get cbrestore working after "guess" the syntax. Couchbase official cbrestore documentation is really poor.

The magic line:

sh cbrestore /home/user/Descargas/backup2014-02-10 http://Administrator:password@localhost:8091 --bucket-source=demo --bucket-destination=demo

jueves, 30 de enero de 2014

Disallowed Key Characters WTF??!!

For any weird reason, when I send some forms  this message is displayed:

Disallowed Key Characters

WTF? What I changed?? I don't know. I only know one thing: when this message appeared, I had to start debugging the FRAMEWORK, not my code, not your code, just the framework.

I found the problem in file system/core/Input.php, line 727, function _clean_input_keys{}

When I have a POST field containing "-", this doesnt match the preg_match("/^[a-z0-9:_\/-]+$/i", $str), I dont know why because the "-" IS HERE!!! then ...

I run this: var_dump(preg_match("/^[a-z0-9:_\/-]+$/i", '-')); die(); and of course was TRUE.

Conclusion: I don't know WTF is happening (It's like a devil '-' different from '-'), but, if you are seeing "Disallowed Key Characters" message and you have a post field called, for example "login-submit", rename this field to "login_submit" and maybe all the things start working again.