We have hundreds of posts on our company blog and our theme converts all the titles to uppercase letters. Lately we had one post the
Read moreDealing with a WordPress code injection attack to all js files ‘_0xaae8’
During the last week we were attacked twice. The symptom – our site redirects to advertisements. The tricky part is that after the first redirection
Read moreVisual Studio Code (vs.code) PHP debugging
I just wasted around 7 hours of my life on this thing… life sucks. All I wanted was to have a debugger working for me
Read moreStrip images from HTML / Strings
Easy and simple:
1 |
$content = preg_replace("/<img[^>]+\>/i", " ", $content); |
This came handy when I had a wordpress theme that was showing on the homepage both the featured image and the
Read moreLog in security with password_hash and password_verify
Available since PHP 5.5 password_hash is a really simple and strong way to encrypt passwords. This is a one way encryption which means you cannot
Read moreExtract variables from a key=>value array
The extract() function imports variables from an array. This function uses array keys as variable names and values as variable values. This function returns the
Read moreOutputting all variables in PHP
There is a PHP function that outputs all defined variables:
1 2 3 4 |
<?php $allvars = get_defined_vars(); print_r($allvars); ?> |
Prevent default action from being triggered (form submission prevention or link popups)
When there’s a link that should open a window or do something different than it’s default behavior it’s best to add the javascript in an
Read moreForm submit in wordpress loads a 404 page
I created a custom form on a contact page without using any plugins. After finishing with the design I tested my form and for some
Read moreCSS Dot Selector
Selector start with dot .class_name signifies class name Two doted selector separated by space .outside .inside means element with .inside class descended from an element
Read moreadding bullets to inline elements (eg. links) while keeping line breaks nicely aligned
I had a narrow sidebar with a bunch of links that I wanted to format with bullets. This was done with the :before pseudo-element. The
Read moreHiding content from search engine bots / crawlers
I needed the following code to hide the product’s price from search engines:
1 2 3 |
if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) { return false; } |
Responsive design – replacing images depending on screen size
Using media queries we can change background images. In order to change and actual image (not background) we need javascript, so just use a div
Read moreCSS calc function
calc is used to performs a calculation to be used as the property value. If we want an element to have a the full width
Read moreRefreshing the database on a development environment
If you have a live site which is constantly updated and a local environment once in a while an update to the local database is
Read morePHP ini_get ini_set
PHP has a php.ini file that has all sorts of environment settings. Some of these settings can be changed at run-time using ini_set or checked
Read moreDrupal – dealing with Undefined index: Error Messages notices
The above notice appears when trying to assign or pull data / values from undefined arrays cells. This can be checked before trying the assignment.
Read moreRemoving The Dotted Outline of html links (images/text)
Items in HTML with links have a dotted outline when using keyboard navigation or when dragging an item with the mouse. To remove there is
Read moreGoogle chrome developer tools – searching in all sources (local sources)
In order to search in all local sources (html,js) open the developers tools (F12), press Ctrl+Shift+F and search for whatever you need. Note that there
Read moreDelete Remove Unbind Turn-off attached event with jQuery
Adding the event:
1 |
$("body").mouseleave(showPop); |
Removing the event:
1 |
$("body").off("mouseleave"); |
Event when mouse is leaving the browser screen
1 |
$("body").mouseleave(showPop); |
Seems to work with all browsers. User tries to use the toolbar or exit the page – kaboom, we have a message.
Read moreTaking an existing live Drupal site and creating a local development environment
Copy all files with FTP. Export the database. Install DAMP and choose the directory, import database. Delete the new sites.php and new site symlink DAMP
Read moreForcing CSS / Javascript refresh – avoiding caching
When including the CSS or JavaScript files add a parameter to the end of the file:
1 |
<link rel="stylesheet" type="text/css" href="style.css?version=4122005" /> |
If there’s a need to force refresh constantly
Read moreCreating and deleting form fields dynamically
I needed a form that allows the user to add and remove products with quantities as he wishes. The form had one row with a
Read morePHP variable names with integer increments
In a loop I needed to create / lookup variables that end with a numeric increment. What I found was I can use the following:
Read moreWhat page did the user come from?
If you wish to know what page was the previous page the visitor visited prior to this page you can use:
1 2 |
$testurl=$_POST['urlbefore']; if (!is_null($testurl)) {$urlbefore=$_POST['urlbefore'];} else {$urlbefore= $_SERVER['HTTP_REFERER'];} |
I’m using this
Read moreShokunin
“The Japanese word shokunin is defined by both Japanese and Japanese-English dictionaries as ‘craftsman’ or ‘artisan,’ but such a literal description does not fully express
Read morePHP script for general all pages canonical script
The following script will work well as a general in-header canonical one-line script, BUT ONLY FOR SITES THAT DON’T PASS PARAMETERS TO GENERATE CONTENT PAGES.
Read morejQuery animate easing parameter
While trying to create animations with jQuery I noticed that there are short delays between each couple of animations. After reading on the subject it
Read morehr element with an image in its center
If you wish to have a stylish separator with some kind of an ornament in its middle, use:
1 2 3 4 5 6 7 8 9 10 |
/* hr separator with ornament*/ hr:after { background: url('images/hrOrnament.gif') no-repeat top center; content: ""; display: block; height: 26px; /* height of the ornament */ position: relative; top: -14px; /* half the height of the ornament */ } |