Two color text header

Here’s a nice HTML and CSS trick – making text split with different colors.

Two tone title in CSS

The trick is to make 2 DIVs with the same text content in the same place (using CSS position) and make the top one a different color and only half height (setting the height to slightly over half a line using height: 0.6em and overflow: hidden)

Demo here.

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

How to see what’s going on in your mysql database (linux)

You can see every SQL command which your mysql database receives.

In your mysql interface you can set where the log file will be written to and then turn on the logging option (change log filename as applicable):
set global general_log_file = ‘/var/log/mysql.log’;
set global general_log = ‘ON’;

(to see the value of these variables type:
show global variables where variable_name like ‘general_log%’;
in your mysql interface)

Now use:
tail -f /var/log/mysql.log

and you’ll see every new SQL statement which the database receives.

And of course to turn it all off again type this in the :
set global general_log = ‘OFF’;

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

How to follow what’s going on in your Apache server logs (linux)

At the command line type:

tail -f /var/log/apache2/access.log

As apache requests are received you’ll see information about them appear on screen.

Can’t find the log file?
Try this:

find /var -name access.log 2>/dev/null

This searches for the file “access.log” in the /var directory and sub-directories. The “2>..” on the end is a really neat trick which directs all error messages to /dev/null so you don’t get messages about permission denied on directory traversal.

If this doesn’t find the file then it’s probably not in /var so try:

find / -name access.log 2>/dev/null

Which will search from /

Combine the find command with the tail command

tail -f `find /var -name access.log 2>/dev/null`

Note the wierd backtick character around the find.

Filtering the results
If you’re looking for something in particular then pipe the results through grep to filter on a string:

tail -f /var/log/apache2/access.log | grep login.php
Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

Making a 2 column layout using CSS: an introduction to “float” and “clear”

The CSS “float” property makes a block move as far to the left as possible and makes everything try to flow round it to the right. We can use this to make columns. If we set the width on the left column and the width on the right column and float both to the left then we get nicely lined up columns.

2 column layout using CSS

2 column layout using CSS


(more…)

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

Centering a page using CSS

There’s a great trick here. Some pages on your site will have more content than others. When the user goes from one page to another and the vertical scrollbar appears or disappears then the centered page shifts. To fix this, I use CSS to always show scrollbars so that content centers consistently.
(more…)

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

Preventing Email injection in a webapp form

Suppose I have a feedback form on a webpage. Something like:


<form method="get" action="testmail.php">
Email: <input name="email" type="text" value="" />
<br />
Feedback: <textarea name="feedback"></textarea>
</form>

And suppose I deal with it in PHP a bit like this:


$from = '' .POST["email"];
$feedback = '' . $_POST["feedback"];
$rtn = mail('james@rootdev.com', "Feedback from website", $feedback, "From: " . $from);

What could possibly go wrong?

Quite a lot.
(more…)

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

Demonstrating the need for HTML and SQL encoding by building an insecure blog and hacking it

I’m going to create the worst blogging software in the world, consisting of a single web page displaying a list of comments and where users can post new comments or search for comments. The data will be stored in a MySQL database. The site is going to have horrendous security flaws (on purpose). Then I’m going to hack it’s innermost secrets just through the web page. Then I’ll show you how to make it secure.

(more…)

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

How to make a ‘share this on Twitter’ link in a webpage

Should produce valid HTML and work nicely, mostly the work of Jamie Huskisson and Herself’s Webtools.

<a href=”http://twitter.com/home?status=I+like+http://yoururlhere/”> Share this on Twitter </a>

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

How to make a ‘share this on facebook’ link in a webpage

The title needs to be correctly url encoded.

<a target=”_blank” href=”http://www.facebook.com/sharer.php?u=http://yoururlhere/&amp;t=This+is+the+title”>Share this on facebook</a>

The ampersand “&” between the parameters is HTML encoded which is a bit fussy but correct.

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

How to make a ‘Digg this’ link in a webpage

Although there’s a Digg widget on their website I find it annoying. It’s in javascript and slow to load and it shows an error when I’m testing pages on my local machine which aren’t accessible on the web.

The title is url encoded.

<a target=”_blank” href=”http://digg.com/submit?url=http://yoururlhere/&amp;title=This+is+the+title”>Digg this</a>

The ampersand “&” between the parameters is HTML encoded which is a bit fussy but correct.

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter