VarjuOrg

Linux / Windows – what’s the difference…

PHP

Snippet for replacing certain code within PHP code

Replaces/searches by row on unix commandline: find folder/* -type f -name \*.php -exec sed -i.bak.php "s/function_name('blahblah');/\$variable['blahblah'];/" {} \; – searches in certain folder – searches in .php files – makes backup of modified files NB! Some things must be escaped with \ mark

Fix for old code when GLOBALS are needed on newer PHP versions

Quickfix is: if (! isset($PXM_REG_GLOB)) { $PXM_REG_GLOB = 1; if (! ini_get('register_globals')) { foreach (array_merge($_GET, $_POST) as $key => $val) { global $$key; $$key = (get_magic_quotes_gpc()) ? $val : addslashes($val); } } if (! get_magic_quotes_gpc()) { foreach ($_POST as $key => $val) $_POST[$key] = addslashes($val); foreach ($_GET as $key => $val) $_GET[$key] = addslashes($val); } […]

How to install Symfony3 under shared webhosting in Developement mode

1. Log in to SSH 2. Install Composer (We assume that composer is not yet installed): export COMPOSERDIR=~/bin;mkdir bin curl -sS https://getcomposer.org/installer | php — –install-dir=$COMPOSERDIR –filename=composer (Composer will be installed under: /home/username/bin/composer ) 3. To test that installation was successful – You can run: ~/bin/composer 4. Make environment global INSTALLDIR: export INSTALLDIR=~/public_html/symfony mkdir $INSTALLDIR […]

, , ,

unserialize() : Error at offset XX:XXX

Food for thought: 1. Probably Your charset is wrong (after PHP 5.5) – Set charset after open tag: header('Content-Type: text/html; charset=utf-8'); – And set charset utf8 in your database : mysql_query("SET NAMES 'utf8'"); 2. Your serialized array is faulty Could be fixed by: $fixed_data = preg_replace_callback ( '!s:(\d+):"(.*?)";!', function($match) { return ($match[1] == strlen($match[2])) ? […]

Nifty snippet in PHP to get POST GET and SESSION variables

<?php echo ‘<pre>’; print_r($_SESSION); print_r($_POST); print_r($_GET); echo ‘</pre>’; ?>  

, ,

PHP: Graafiline % pilt lehele

Image link: <img alt="" src="bar.php?val=10&amp;max=100" />

, ,