Показаны сообщения с ярлыком php. Показать все сообщения
Показаны сообщения с ярлыком php. Показать все сообщения

понедельник, 9 апреля 2012 г.

php disable_functions

disable_functions = "apache_child_terminate, apache_setenv, define_syslog_variables, escapeshellarg, escapeshellcmd, eval, exec, fp, fput, ftp_connect, ftp_exec, ftp_get, ftp_login, ftp_nb_fput, ftp_put, ftp_raw, ftp_rawlist, highlight_file, ini_alter, ini_get_all, ini_restore, inject_code, openlog, passthru, php_uname, phpAds_remoteInfo, phpAds_XmlRpc, phpAds_xmlrpcDecode, phpAds_xmlrpcEncode, popen, posix_getpwuid, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, posix_setuid, posix_uname, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate, shell_exec, syslog, system, xmlrpc_entity_decode,mail"
or

disable_functions= "exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source "
for VirtualMin
#!/bin/bash
cd /home

for i in `ls`; do
   dir=/home/$i/etc/php5
   if [ -d $dir ]; then

        cd  $dir
        lsattr php.ini
        chattr -i php.ini
        sed -i.bak -e "s@\W*open_basedir\s*=.*@open_basedir = /home/$i@" \
        -e 's@\W*disable_functions\s*=.*@disable_functions = "apache_child_terminate, apache_setenv, define_syslog_variables, escapeshellarg, escapeshellcmd, eval, exec, fp, fput, ftp_connect, ftp_exec, ftp_get, ftp_login, ftp_nb_fput, ftp_put, ftp_raw, ftp_rawlist, highlight_file, ini_alter, ini_get_all, ini_restore, inject_code, openlog, passthru, php_uname, phpAds_remoteInfo, phpAds_XmlRpc, phpAds_xmlrpcDecode, phpAds_xmlrpcEncode, popen, posix_getpwuid, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, posix_setuid, posix_uname, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate, shell_exec, syslog, system, xmlrpc_entity_decode,mail"@' php.ini
        chattr +i php.ini
   else
        echo $i empty           
   fi;
done

понедельник, 27 февраля 2012 г.

Prestashop multishop

1) make soft link of image folder from main shop to new shop
ln -fs main_shop/img new_shop/img
2)Rename new_shop_db and main_shop_db to your names in sql procedure and run sql script
DELIMITER $$
DROP PROCEDURE if exists make_linked_tables $$

CREATE PROCEDURE make_linked_tables() 
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE str VARCHAR(250);
DECLARE cur CURSOR FOR 
 SELECT table_name FROM information_schema.tables WHERE 
table_schema = 'new_shop_db' AND (table_name LIKE 'ps_product%'
OR  table_name LIKE 'ps_category%') 
UNION
SELECT 'ps_image'
UNION
SELECT 'ps_image_lang'
;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur;
REPEAT
 FETCH cur INTO str;
 SET @s = CONCAT("RENAME TABLE ", str," TO ");
 SET @s = CONCAT(@s,str,"_orig");
 PREPARE sth FROM @s;
 EXECUTE sth;
 DEALLOCATE PREPARE sth;

 SET @s = CONCAT("CREATE VIEW ",str," as SELECT * FROM main_shop_db.",str);
 PREPARE sth2 FROM @s;
 EXECUTE sth2;
 DEALLOCATE PREPARE sth2;

UNTIL done END REPEAT;
CLOSE cur;
END$$
DELIMITER ;
3)Run procedure
CALL make_linked_tables();
DROP PROCEDURE if exists make_linked_tables; 
Manually customize categories list of new shop:
drop table if exists ps_category;
create OR replace view ps_category AS
SELECT * FROM MAIN_SHOP_DB.`ps_category` WHERE 
id_category in ( 1,17,28,35) OR id_parent in (17,28,35);

drop table if exists ps_category_group;
create OR replace view ps_category_group AS
SELECT * FROM MAIN_SHOP_DB.`ps_category_group` WHERE 
id_category in ( SELECT id_category FROM `ps_category` ) ;

drop table if exists ps_category_lang;
create OR replace view ps_category_lang AS
SELECT * FROM MAIN_SHOP_DB.`ps_category_lang` WHERE 
id_category in ( SELECT id_category FROM `ps_category`);

drop table if exists ps_category_product;
create OR replace view ps_category_product AS
SELECT * FROM MAIN_SHOP_DB.`ps_category_product` WHERE 
id_category in ( SELECT id_category FROM `ps_category`) ;

There are  id_category = 1 - main category(required), 17(subcategory optional)  .... 

среда, 25 января 2012 г.

custom php.ini для fastcgi

php5.fcgi  :

#!/bin/bash
PHPRC=$PWD/../etc/php5
#PHPINIDir=$PWD/../etc/php5
#PHP_INI_SCAN_DIR=$PWD/../etc/php5/conf.d
#export PHPINIDir
#export PHP_INI_SCAN_DIR

export PHPINIDIR=$PWD/../etc/php5
export PHP_INI_PATH=$PWD/../etc/php5

export PHPRC
umask 022
export PHP_FCGI_CHILDREN
SCRIPT_FILENAME=$PATH_TRANSLATED
export SCRIPT_FILENAME
exec /usr/bin/php5-cgi
или же в php.ini раскоментировать строчку
; Name for user-defined php.ini (.htaccess) files. Default is ".user.ini"
user_ini.filename = ".user.ini"
и в корневой вебдиректории можно создать файл .user.ini и писать в него конфигурацию php

вторник, 22 ноября 2011 г.

Ubuntu/Debian downgrade php5.3 to 5.2

Делаю downgrade в Lucid только для следующих пакетов в версии из репозитария Hardy

vim /etc/apt/preferences.d/php5-pin

Package: php5-cgi
Pin: release a=hardy
Pin-Priority: 1001

Package: libapache2-mod-php5
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-common
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-cli
Pin: release a=hardy
Pin-Priority: 1001

Package: php-auth
Pin: release a=hardy
Pin-Priority: 1001

Package: php-pear
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-curl
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-dev
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-gd
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-imagick
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-imap
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-mcrypt
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-mysql
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-sqlite
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-tidy
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-xmlrpc
Pin: release a=hardy
Pin-Priority: 1001

Package: php5-xsl
Pin: release a=hardy
Pin-Priority: 1001

aptitude install php5-cgi php-auth php-pear php5-cli php5-curl php5-dev php5-gd php5-imagick php5-imap php5-mcrypt php5-mysql php5-sqlite php5-tidy php5-xmlrpc php5-xsl

пятница, 18 ноября 2011 г.

Phpfarm custom.sh

aptitude install libxml2-dev libjpeg8-dev libcurl4-openssl-dev libpng-dev libfreetype6-dev libmcrypt-dev libmhash-dev libxslt-dev

mkdir -m 0755 /usr/local/php
git clone git://git.code.sf.net/p/phpfarm/code phpfarm

cd phpfarm/src

vim custom-options-5.2.17.sh
### 
configoptions="
            --enable-cli \
            --with-pear \
            --with-openssl=/usr \
            --with-iconv \
            --with-curl \
            --with-mysql \
            --with-mysqli \
            --enable-mbstring \
            --with-zlib \
            --with-zlib-dir \
            --with-gettext \
            --with-mhash \
            --enable-ftp \
            --with-mcrypt \
            --enable-bcmath \
            --with-mime-magic \
            --with-pdo-mysql \
            --enable-sockets \
            --enable-soap \
            --enable-fastcgi \
            --enable-force-cgi-redirect \
            --with-xsl \
--with-gd \
--enable-gd-native-ttf \
--with-ttf \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \

    "
#
#           --with-gd \
#            --with-gd=/usr/lib/php5/20090626 \
#--with-png-dir \
#--with-jpeg-dir \
#            --enable-gd-native-ttf \
#            --with-pspell \
#            --enable-exif \


пятница, 10 июня 2011 г.

SuEXEC + Fast-CGI = upload error 500

Замечательная ошибка 500 при загрузке файла пхп скриптом .
Лекарство

/etc/apache2/mods-available/fcgid.conf


MaxRequestLen 15728640


PS: чем дальше тем больше я начинаю "обожать" php и особенно его последние развитие (Ошибки из-за сообщений DEPRICATED уже достали, и ведь они не всегда исправляються изменением переменной конфига error_reporting ).

воскресенье, 29 мая 2011 г.

simple token algorithm with PHP

function uid($n, $len1=5, $len2=15, $base=36)
  {
    $id_part = base_convert($n, 10, $base);
    $rand_part = str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789');
    return sprintf("%0".$len1."s-%.".$len2."s", $id_part, $rand_part);
  }   

source: http://stackoverflow.com/questions/2377633/how-create-an-unique-20-single-byte-token-key-id-on-php

понедельник, 23 августа 2010 г.

php unzip

     $zip = new ZipArchive;
     $res = $zip->open('111.zip');
     if ($res === TRUE) {
         $zip->extractTo('./');
         $zip->close();
         echo 'ok';
     } else {
         echo 'failed';
     }

src: http://www.bjw.co.nz/developer/php

суббота, 10 апреля 2010 г.

php header

http://www.jonasjohn.de/snippets/php/headers.htm

// See related links for more status codes


// Use this header instruction to fix 404 headers
// produced by url rewriting...
header('HTTP/1.1 200 OK');

// Page was not found:
header('HTTP/1.1 404 Not Found');

// Access forbidden:
header('HTTP/1.1 403 Forbidden');

// The page moved permanently should be used for
// all redrictions, because search engines know
// what's going on and can easily update their urls.
header('HTTP/1.1 301 Moved Permanently');

// Server error
header('HTTP/1.1 500 Internal Server Error');

// Redirect to a new location:
header('Location: http://www.example.org/');

// Redriect with a delay:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';

// you can also use the HTML syntax:
// < meta equiv="refresh" content="" >

// override X-Powered-By value
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');

// content language (en = English)
header('Content-language: en');

// last modified (good for caching)
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');

// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');

// set content length (good for caching):
header('Content-Length: 1234');

// Headers for an download:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// load the file to send:
readfile('example.zip');

// Disable caching of the current document:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');

// set content type:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); // plain text file
header('Content-Type: image/jpeg'); // JPG picture
header('Content-Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file
header('Content-Type: application/x-shockwave-flash'); // Flash animation

// show sign in box
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';

суббота, 20 марта 2010 г.

php grep -R

.htaccess
php_flag magic_quotes_gpc off


dosearch.php

<?php

if($_SERVER['REQUEST_METHOD'] != 'POST' ){
echo <<<EOL
<form action="" method="post" enctype="multipart/form-data">
<textarea name="search" rows=20 cols=50>...search value...</textarea>
<input type="submit" value="Submit" />
</form>
EOL;

exit ;
}

$needle = $_REQUEST['search'];
echo '<pre>',$needle,'</pre>';
$path = realpath(getcwd());
//$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
foreach($objects as $name => $object):
if ($object->isFile()) {
$info = pathinfo($object->getFilename());
if($info['extension'] == 'php' ){
$str = file_get_contents($object->getPathname());
if(strpos($str, $needle) !== false){
echo $object->getPathname(),"\n  ","<br>";
}
}  
}
endforeach;