How to break out of an iframe

So someone’s trying to make their site better by opening a page on your site inside of their site using an iframe? They’re doing something like this: 1 <iframe src="" width="100%" height="100%"></iframe> Well how about you stop that from happening by pasting the following line in your website’s header! 1 2 3 4 5 <script type="text/javascript"> if (top.location != self.location) { top.location = self.location.href; } </script> The above code basically does a check to see if the site is the same as what is said in the address bar, if not then it sets the parent’s frame (the other site) to change to your site’s location!

Edit hosts file on Windows 7

The hosts file is used to manually alter the hostname or IP address in place of it being served by a Nameserver, also known as via DNS. The hosts file is located here: 1 C:\windows\system32\drivers\etc\ Or an easiler way to get to it incase of whatever is like this: 1 %systemroot%\system32\drivers\etc\ This file cannot be editted by “normal users” and requires all changes to be done via an Administrator. This is really easy if you do it in the following way:

(EAI 2)Name or service not known: Could not resolve host name *.80 — ignoring!

You are no doubt trying to add a vhost and you get the following error when attempting to affect changes by restarting the http daemon (httpd): (EAI 2)Name or service not known: Could not resolve host name *.80 — ignoring! Not to worry! Add the following text to httpd.conf at the bottom (That’s at /etc/httpd/conf/httpd.conf): 1 2 3 4 5 6 7 NameVirtualHost ServerAdmin [email protected] DocumentRoot /var/www/html/the_path/ ServerName ErrorLog /logs/the_path.

Virgin Media blocks torrent sites!

Virgin Media have done it again! They have gone and started a “downloaders war”, I’m sure of it. Basically what happened is that Virgin Media are claiming that they have had an order from the Courts to prevent access to a whole bunch of sites which lead to illegal downloading or copyright infringement downloading. Not only is it Virgin Media but all 5 major ISP’s in the UK that have received this Court order, that’s Sky, Everything Everywhere, TalkTalk, O2 and Virgin Media.

How to Comment out a line in a Crontab on Linux

Firstly let’s just note that crontabs are read in the following way: 1 2 3 4 5 6 7 8 * * * * * command to be executed - - - - - | | | | | | | | | +----- day of week (0 - 6) (Sunday=0) | | | +------- month (1 - 12) | | +--------- day of month (1 - 31) | +----------- hour (0 - 23) +------------- min (0 - 59) Your current crontabs can be viewed on your linux setup by typing in the following command:

DateTime conversion function using PHP

It’s really very simple to convert times in different timezones using the following function. 1 2 3 4 5 6 function dateTimeConversion($datetime, $timezone="Europe/London") { $date = new DateTime($datetime, new DateTimeZone("UTC")); $date->setTimezone($timezone); return $date->format("Y-m-d H:i:s"); } As you can see, it takes 2 arguments, $datetime which is a time string and a $timezone which is a timezone to convert to. A usage example would be: 1 echo dateTimeConversion("2012-05-01 17:09:58");

Convert seconds to days, hours, minutes, seconds in PHP

With the following function you can easily convert an integer containing seconds to a nice days, hours, minutes, seconds string or array. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 function secondsToTime($seconds, $return_type="string") { // extract days $days = floor($seconds / 3600 / 24); // extract hours $hours = floor($seconds / 3600) - $days*24; // extract minutes $divisor_for_minutes = $seconds % 3600; $minutes = floor($divisor_for_minutes / 60); // extract the remaining seconds $divisor_for_seconds = $divisor_for_minutes % 60; $seconds = ceil($divisor_for_seconds); // return the final array $obj = array( "d" => (int) $days, "h" => (int) $hours, "m" => (int) $minutes, "s" => (int) $seconds ); $str = ""; if ($obj["d"]!

Remove dotted outline around anchors

This has become quite a common question asked by many website owners. “How do I remove that dotted outline around an anchor?” Lucky for you all, it’s a really easy one to resolve as well. You just have to take a look at CSS for a second and add one line as follows: 1 a { outline:0; } This will disable the outlines around clicked links all around your site.

Get amount of hours between 2 hours

If you would like to get the amount of hours between 10:00 and 12:00 then use this! 1 2 3 4 5 6 7 8 function timeDiff($firstTime,$lastTime) { $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); $timeDiff=$lastTime-$firstTime; return $timeDiff; } echo (timeDiff("10:00","12:00")/60)/60;

How to embed HTML5 video with fallback

A common question with the rise of HTML5 becoming more and more common and the whole iGeneration (iPhones/iPads/iEtc) is “how can I embed a video on my site without using a flash player?“. An option that really does work quite well is to use the JWPlayer and set it up to use HTML5. The benefit of going this route is you can also tell it to have a fallback to flash if the browser is not HTML5 compatible, or even fall all the way back to downloading the video if all else fails.

How to backup all mysql databases

In order to backup all mysql databases, you can run the following command in your linux command line: The example below is configured with username “theuser” and password “thepass”. 1 mysqldump -utheuser -pthepass ?all-databases > all_dbs.sql

Invalid command 'RewriteEngine'

If you receive the following error message if means that mod_rewrite is not enabled in Apache: Invalid command ‘RewriteEngine’, perhaps misspelled or defined by a module not included in the server configuration. 1 a2enmod rewrite Bear in mind this is done like this on Linux Ubuntu, not entirely sure if this works for other flavours too.

How to get the Hours Difference (in HH:MM format) in PHP

It’s very simple to get the difference in hours using PHP 1 2 3 4 5 6 7 8 function timeDiff($firstTime,$lastTime) { $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); $timeDiff=$lastTime-$firstTime; return $timeDiff; } echo (timeDiff("10:00","12:00")/60)/60;

Warning: Invalid argument supplied for foreach()

A common error which occurs with foreach loops is the standard “Invalid argument supplied for foreach()” whch gets thrown up as a warning. This can easily be overcome by wrapping the foreach loop in a conditional if statement which checks to see if the argument supplied to the loop is an array or not. Below is an example of how to correct the problem: 1 2 3 4 5 if (in_array($arrItem)) { foreach($arrItem as $arrItemi) { // use $arrItemi; } }

Unable to connect to any of the specified MySQL hosts.

If you get the following error while trying to connect to a MySQL database using a third party client such as TOAD or SQL Workbench, then you need to edit your mysql server’s my.cnf file. Error Message: Unable to connect to any of the specified MySQL hosts. So open the my.cnf file by running a similar command to the following one dependent on your server’s setup: 1 vi /etc/mysql/my.cnf Then edit the bind-address from what is probably set as 127.

PHP nl2br on one line

I usually store data from a textarea directly to the database as is, then once I retrieve it back into HTML I use that lovely PHP function nl2br() to convert it to HTML tags. This works well for most cases until you are passing this data back into javascript where everything has to be on one line! nl2br() outputs as follows: Line one Line two And I want it to be as follows:


In MySQL 5.1 LEN is called LENGTH, you use it exactly the same and pass in the link, so: LENGTH(link).

Remove all linebreaks in PHP

If you are having problems with a string that keeps adding a line break when output from PHP to HTML then the following code will work wonders for you! 1 2 $string_with_line_break = "blabla\nbla\r"; $string_without_line_break = trim(preg_replace( "/\s+/","",$string_with_line_break));

IE9 adding empty table cells in large table

Well as usual, we are once again fighting the woes of the beloved Internet Explorer, and it appears that Microsoft’s latest greatest new and improved browser rival to the market IE9 still has a whole bunch of irritations and retardation to worry about (saw that one coming). Today I was busy loading a massive amount of data into the body of a table using ajax and in Firefox and even Internet Explorer 8 it worked quite well, but Internet Explorer 9 decided that it would like to add some empty table cells randomly around my “massive table”, now of course I began by kicking something and cried a few times….

SELECT Duplicate Items Using SQL

If you have a table which has duplicate items in then you can use the below statement to select them. 1 2 3 SELECT * FROM tableName GROUP BY columnName HAVING ( COUNT( columnName) >1 )