Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Sunday, 5 June 2016

Set the timezone in a script

date_default_timezone_set('Asia/Kolkata'); For a list of timezones: http://php.net/manual/en/timezones.asia.php

Monday, 8 December 2014

Fedora: how to restart nginx and php-fpm

sudo service nginx restart
sudo service php-fpm restart

Monday, 1 December 2014

PHP file browser

http://sourceforge.net/projects/autoindex/

Monday, 24 November 2014

Check if an array is multi-dimensional

if (count($array) == count($array, COUNT_RECURSIVE)) 
{
  echo 'array is not multidimensional';
}
else
{
  echo 'array is multidimensional';
}


http://stackoverflow.com/questions/145337/checking-if-array-is-multidimensional-or-not

Filtering data with PHP (Sanitizing data) and Validation

http://www.phpro.org/tutorials/Filtering-Data-with-PHP.html

http://code.tutsplus.com/tutorials/sanitize-and-validate-data-with-php-filters--net-259

http://www.sitepoint.com/input-validation-using-filter-functions/

To filter arrays:

http://stackoverflow.com/questions/19637210/post-variable-array-and-filter-input




http://php.net/manual/en/function.filter-input.php

http://php.net/manual/en/filter.constants.php

http://php.net/manual/en/function.filter-input-array.php

http://php.net/manual/en/filter.filters.php

http://php.net/manual/en/filter.filters.validate.php

Difference between array merge and array + array

http://stackoverflow.com/questions/5394157/whats-the-difference-between-array-merge-and-array-array

Monday, 28 July 2014

Set Timezone

This will set the timezone for all the php functions in a page. Put this at the top of a page:

date_default_timezone_set('Asia/Calcutta');

Wednesday, 23 July 2014

Enable error display in PHP

error_reporting(E_ALL);
ini_set('display_errors','1');

Friday, 20 June 2014

Enabling Opcache in PHP

Here are the commands that can be entered in php.ini for configuration of the opcache. There is also an explanation ofthe features.

http://www.php.net//manual/en/opcache.configuration.php


Here are some Opcache GUI reporting tools:

https://rtcamp.com/tutorials/php/zend-opcache/

Some configuration tips:

https://www.activecollab.com/blog/3-zend-opcache-memcached.html

More detailed configuration tips:

https://www.scalingphpbook.com/best-zend-opcache-settings-tuning-config/



Tuesday, 17 June 2014

301 permanently moved redirect with PHP

The following php commands will do a 301 redirect when using PHP FPM 
 
 
header('Status: 301 Moved Permanently', true);
header('Location: ' . $url); // or header('Location: ' . $url, true, 301);
 
http://stackoverflow.com/questions/5268454/php-301-redirect-impossible 

Monday, 16 June 2014

cPanel: Install php-devel

CPanel disables installation of php related packages using yum. To enable it:

nano /etc/yum.conf

Remove php* from the "exclude" line.

Saturday, 30 November 2013

Low-level PHP Mail Script

How to send an email with PHP without using the built-in mail() function

http://www.stringcat.com/company_blog/2012/10/13/complete-php-low-level-mailer-script-with-to-replyto-cc-bcc-and-attachments/

Thursday, 21 November 2013

Increasing the php file upload size limit

The default file upload size limit specified in php.ini is 2MB and the post size limit is 8MB. You can increase both to 25MB by modifying the appropriate lines to this:

upload_max_filesize = 25M
post_max_size = 25M

Location of php.ini

In the terminal type

php --ini

To view the locations and names of all the ini files that were parsed.

Friday, 15 November 2013

PHP: put printed data into a variable

http://stackoverflow.com/questions/4798142/php-capture-print-require-output-in-variable

PHP get the current URL

To get the actual URL (non necessarily the one shown in the address bar because of URL rewriting):

 
 
$actual_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
 
To get the URL shown in the address bar:

$displayed_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Tuesday, 12 November 2013

PHP if alternative syntax

http://php.net/manual/en/control-structures.alternative-syntax.php

Thursday, 5 September 2013

Counting the number of rows affected by Php Mysql PDO

http://stackoverflow.com/questions/883365/count-with-pdo
Creating text files in php

http://www.latestcode.net/2010/03/how-to-create-text-file-in-php.html

Saturday, 31 August 2013

count returns the number of elements in an array. If mode is set to COUNT_RECURSIVE (or 1), count() will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array.

count($var)

http://www.php.net/manual/en/function.count.php