Category Archives: Web Development

WordPress plugins to remember

https://wordpress.org/plugins/duplicator/ The Duplicator gives WordPress administrators the ability to migrate, copy or clone a site from one location to another. The plugin also serves as a simple backup utility. The Duplicator supports both serialized and base64 serialized string replacement. If you need to move WordPress or backup WordPress this plugin can help simplify the process.… Read More »

Yii2 crib sheet (until I create some proper pages)

Creating URL Old way (Yii 1.0 maybe??) $url = Yii::$app->controller->createUrl(‘xx’);// your own url generation logic New way (Yii 2.0 ) $url = \Yii::$app->getUrlManager()->createUrl(‘consignment/label’); Creating controllers Debugging (old skool) Yii::info(“My message” , ‘scsdebug’); Yii::warning(“this->consignment_date=” . $this->consignment_date , ‘scsdebug’); Yii::warning(\DateTime::createFromFormat(‘d/m/Y’, $this->consignment_date) , ‘scsdebug’);

Category: Yii

putting awstats live on a long hosted website

Search /home/awstats/DirData/ for any files relating to the domain you’re dealing with and are newer than those for which you have logs. eg… ll /home/awstats/DirData/awstats*.www.example.com.txt ll /home/awstats/DirData/awstats*2015.www.example.com.txt and then either remove them (if you know you can recreate them) or move them to a temp location rm /home/awstats/DirData/awstats122015.www.example.com.txt mv /home/awstats/DirData/awstats*.www.example.com.txt /tmp/awstats.tmp/ Unzip all your log files cd… Read More »

WordPress harderning with apache

Installing WordFence #1 #2 gives you protection and great visibility into whats going on. It’s easy to think no problems = no attacks, but after installing WordFence it was immediately obvious how much attach my little old website was under – and not because it’s a popular site (far from it – I’m pretty sure I’m… Read More »

MySQL automatically set created and lastupdated timestamps on columns

ALTER TABLE `tablename` ADD COLUMN `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD COLUMN `updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; https://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html https://dev.mysql.com/doc/refman/5.6/en/data-type-defaults.html Requires MySQL 5.6.5 or better

SSL and Apache2.4

Generate private key openssl genrsa -out domainname.key 2048 Generate Signing Request openssl req -new -key domainname.key -out domainname.csr

WordPress administration tips

Use WP-CLI (http://wp-cli.org/) Su to a non-privileged user # su -m www # wp core version 4.2.2 # wp core verify-checksums Success: WordPress install verifies against checksums. # wp core check-update Success: WordPress is at the latest version. # wp core update Plugsin # wp plugin status 4 installed plugins: UI akismet 3.1.1 A force-login-except-special-ip-range… Read More »

How to check WordPress versions on your server are up to date

Original script at https://www.howtoforge.com/how-to-find-outdated-wordpress-versions-on-your-server-to-reduce-the-risk-of-being-hacked This script has been improved to automatically detect latest WordPress version by sending a HTTP HEAD request to http://wordpress.org/latest and parsing the Content-Disposition: attachment; filename=wordpress-A.B.C.tar.gz result as suggested at https://wordpress.org/support/topic/programmatically-check-latest-wp-release <?php /** * find outdated wordpress versions * (c) 2014 howtoforge.com (M. Cramer) <m.cramer@pixcept.de> * Appended by Steve Scotter www.stephen-scotter.net */ if(!isset($argv[1])) die(“Please start this program with… Read More »

Transfering MySQL database between hosts

The single command approach mysqldump -h oldhost -u oldusername -poldpassword olddbname | mysql -h newhost -u newusername -pnewpassword newdbname make sure you can … mysql -h newhost -u newusername -pnewpassword newdbname … before attempting the transfer. Common issues are :- Firewall preventing access to MySQL server across the network User configured to only be able… Read More »

FreeBSD, Fatal error: Call to undefined function geoip_country_name_by_name()

Getting Fatal error: Call to undefined function geoip_country_name_by_name() ? Install /usr/ports/net/pecl-geoip # cd /usr/ports/net/pecl-geoip && make install clean # “/usr/local/www/awstats/cgi-bin/awstats.pl” -update -config=account.ptiexpress.com -configdir=”/usr/local/etc/awstats/” Error: Plugin load for plugin ‘geoipfree’ failed with return code: Error: Can’t locate Geo/IPfree.pm in @INC (you may need to install the Geo::IPfree module) (@INC contains: /usr/local/lib/perl5/site_perl/mach/5.18 /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.18/mach /usr/local/lib/perl5/5.18 /usr/local/lib/perl5/site_perl/5.18 /usr/local/lib/perl5/site_perl/5.18/mach… Read More »

my MySQL default configuration

my.cnf file. Try and use this before you start MySQL Server for the first time! [mysqld] log-output=TABLE expire_logs_days=1 general_log=ON general_log_file=/var/db/mysql/mysqld-queries.log slow_query_log=ON slow_query_log_file=/var/db/mysql/mysqld-slow-queries.log log_queries_not_using_indexes=ON log-error=/var/db/mysql/mysqld-error.log default-storage-engine=innodb innodb_file_per_table Run the following SQL script to update the logs to use MyISAM (instead of CSV!). SET @old_log_state = @@global.general_log; SET GLOBAL general_log = ‘OFF’; TRUNCATE TABLE general_log; ALTER TABLE… Read More »

MySQL function to calculate the distance between two latitude and latitude GPS pairs

CREATE DEFINER=`root`@`localhost` FUNCTION `FIND_DISTANCE`(`src_latitude` float,`src_longitude` float, `dest_latitude` float,`dest_longitude` float) RETURNS int(11) BEGIN /* This function takes four parameterss, two sets of latitude and latitude pairs and returns the distance between them in miles. Example use SELECT * , FIND_DISTANCE(home_latitude, home_longitude, 52.5, -1) AS distance FROM users WHERE deleted = 0; */ RETURN ( 3959 *… Read More »

MySQL Logs – Selecting General Query and Slow Query Log Output Destinations

[mysqld] … log-output=TABLE expire_logs_days=1 general_log=1 general_log_file=/var/log/mysqld-queries.log slow_query_log=1 slow_query_log_file=/var/log/mysqld-slow-queries.log …   SET @old_log_state = @@global.general_log; SET GLOBAL general_log = ‘OFF’; ALTER TABLE mysql.general_log ENGINE = MyISAM; SET GLOBAL general_log = @old_log_state; SET GLOBAL general_log = ‘ON’; SET @old_log_state = @@global.slow_query_log; SET GLOBAL slow_query_log = ‘OFF’; ALTER TABLE mysql.slow_log ENGINE = MyISAM; SET GLOBAL slow_query_log = @old_log_state;… Read More »

Add WordPress Admin user via MySQL query

// You may need to update the table names if a WordPress table prefix has been set. INSERT INTO wp_users (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES (‘spectrum’, MD5(‘some-password’), ‘Spectrum Computer Solutions’, ‘wordpress@spectrumcs.net’, ‘http://www.spectrumcs.net’, NOW(), ”, ‘0’, ‘Spectrum Computer Solutions’); SET @USER_ID = LAST_INSERT_ID(); INSERT INTO wp_usermeta (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES… Read More »

FreeBSD and phpList : White Screen of Death

Despite turning on errors in php.ini I wasn’t getting any error messages when I went to http://ipaddress/lists/ or http://ipaddress/lists/admin/, I just received a white screen of death. After adding error_log() statements thoughout the code to trackdown the issues I discovered that execution was getting as far as line 198 in /lists/admin/init.php ## remember the length of a hashed string… Read More »

’ characters or similar on your WordPress site

If you see random â€™ characters or similar on your WordPress site its likely to be an encoding mismatch between your WordPress installation and your MySQL database server. I did the following to fix mine, your mileage may vary. 1. Confirm wp-config.php has the encoding set as UTF8.. /** Database Charset to use in creating database… Read More »

degree2decimal

DROP FUNCTION IF EXISTS `degree2decimal`; CREATE DEFINER = `root`@`localhost` FUNCTION `degree2decimal`(deg_coord float) RETURNS float BEGIN #converts NMEA/GPS Lat -Long to Decimal Degrees. Code comments are self explanatory. #The code is not graceful, but it works. declare degree INT; declare minutes2 FLOAT; declare dotdegree FLOAT; declare decimal2 FLOAT; set degree= (deg_coord/100); set minutes2 = deg_coord-(degree*100); set… Read More »

Your WordPress Metadata theme patch

<?php $meta_values = get_post_meta(get_the_ID()); $original_urls = ”; foreach ($meta_values[‘original_url’] as $url) { $original_urls .= “Original URL : <a href=\”$url\”>$url</a><br />”; } ?>   <?php print “<small>$original_urls</small><br />”; ?>

WordPress Security

SSL and Cookies in WordPress 2.6 HOWTO: Set up secret keys in WordPress 2.6+ Secret Key Generator

PHP and MySQLi SELECT query

<?php $i = new mysqli(‘localhost’, ‘username’, ‘password’, ‘database’); if ($result = $i->query(“SELECT * FROM tablename;”) ) { printf(“Select returned %d rows.\n”, $result->num_rows); if ($result->num_rows > 0) { while ($row = $result->fetch_object()) { print_r($row); } } $result->close(); } else { printf(“%d : %s\n”, $i->errno, $i->error); } ?> if (!$i->query(“INSERT INTO table VALUES(null, ‘x’,’x’,’x’);” ) ) {… Read More »

Category: PHP

Creating PDFs from PHP

http://www.fpdf.org/ (Used on PTI and JMS) http://www.ros.co.nz/pdf/ Never used, but looks interesting.

Category: PHP