Categories
Free PHP Classes & Library PDF Tips & Tutorials

Generating PDF documents with PHP

I generate, oh no, I mean PHP generates the PDF version of all the blog posts I have here by this library, but I think this one‘s a lot easier!

Giving it a try sometime later, thanks Dan for the find!

Yeah, yeah, I know I know, I could have posted this to twitter by nature of microblogging. I’m just trying to be more casual and to be myself for a while.

I hate most of the social medias that are no more than just pompous distractions providing little value if at all.

Update: Better libraries to accomplish the job of converting HTML/CSS to PDF documents might be HTML2PDF and PrinceXML.

Categories
Anti Spam Tips & Tricks Information Security Web Applications & Online Software

phpBB Spam Control – phpBB Anti-Spam Options for Fresh Forum Installations

phpBB is pretty much the best php forum software out there that is free, and comes the first choice of many webmasters. However, after a few weeks of first installation, many complain that spam bots start to overwhelm their forums, flooding with automated spam registrations and spam posts.

Unfortunately, that is generally because:

  1. phpBB disables account activation by default so that any registered account would be instantly able to write and submit posts.
  2. The default image captcha at registration is much too easy for anti-captcha programs to break.

So, taking phpBB 3.0.4 for an example, to prevent the majority of simple phpBB forum spam bots, with every new phpBB installation, you will:

  1. Enable registration activation: Administration Control Panel => General => (Board Configuration) User registration settings => (General settings) Account activation => Now select ‘By User‘ from ‘None‘ => Submit.Thereby all new registered accounts will be required to validate the email address which no automated spam bots would do with fabricated ones, at least for not-so-valuable new forums.
  2. Use harder captcha images: Administration Control Panel => General => (Board Configuration) Visual confirmation settings => (General options) => GD CAPTCHA foreground noise => Select ‘Yes‘ instead of ‘No‘ => Submit.This would make the captcha a lot harder to break but also less user friendly / accessible because the texts are also much harder for human recognizing. To ease the pain, you may want to set the numeric values just below the option for background noises of x-axis and y-axis higher or zero. I use 200.

After all these efforts you should be receiving much less spam now. If they still laugh at your defense and keep on coming, you should consider using more advanced image captcha such as reCaptcha.net.

For an idea of what captcha works best

Below is a list of famous Chinese websites image captchas that have allegedly been broken by automated text recognition programs with an accuracy percentage and price for each of them. From them you can get an idea of what captcha works the best and what can be easily worked around.

Origin Samples Accuracy Price Comments
9you captcha broken by spam bots 100% 500
$100
Very Easy
tiancity captcha broken by spam bots 100% 500
$100
Very Easy
cncard captcha broken by spam bots 100% 500
$100
Very Easy
the9 captcha broken by spam bots 100% 500
$100
Very Easy
the9 captcha broken by spam bots 99% 1000
$200
Easy
kingsoft captcha broken by spam bots 98% 1000
$200
Easy
taobao captcha broken by spam bots 95% 1000
$200
Easy
dvbbs captcha broken by spam bots 95% 1000
$200
Easy
126 captcha broken by spam bots 95% 1000
$200
Easy
163 captcha broken by spam bots 95% 1500
$300
Middle
shanda captcha broken by spam bots 90% 1500
$300
Middle
qq captcha broken by spam bots 90% 1500
$300
Middle
xiaonei captcha broken by spam bots 85% 1000
$200
Middle
sdo captcha broken by spam bots 85% 1500
$300
Middle
ourgame captcha broken by spam bots 80% 1500
$300
Middle
chinaren captcha broken by spam bots 85% 2000
$400
Middle
monter captcha broken by spam bots 80% 2000
$400
Middle
baidu captcha broken by spam bots 80% $3000 Difficult
qq captcha broken by spam bots 75% $3000 Difficult
ebay captcha broken by spam bots 60% $4000 Difficult
myspace captcha broken by spam bots 30%
google captcha broken by spam bots 30%
hotmail captcha broken by spam bots 30%
yahoo captcha broken by spam bots 45% $8000
Categories
PHP Tips & Tutorials

PHP: Return and Get the Last Letter / Character of a String

To get the last character of a string in PHP, you need a combination of the functions of substr() and strlen().

For example, you need to get the last digit of a date string such as ‘Feb. 3’ or ‘Aug. 14’ to determine whether the trailing of the date will be ‘st’, ‘nd’, ‘rd’ or ‘th’.

Just go with this:

$str = 'Feb. 2';
$last = substr($str, strlen($str) - 1);
echo $last;

Then $last would be:

2

PHP function substr returns a slice of a string by the starting and ending positions while strlen returns the length of the string which should be subtracted by 1, would be the position of the last character in the string, in this case, ‘2’.

Categories
Hilariously Funny or Creepy

What the heck are forums?

You know, the plural of forum should at all be fora instead of forums. Data is the plural of datum, but have you seen any datums?

Ahha, here’s a reason.

Categories
Content / SEO Tips & Tutorials Information Security

Robots.txt Disallow All and Block Search Engine Spiders

You can literally block any visitor including search engines and secure the data or information you have on your website by the help of .htaccess Deny From All. A similar solution is to have a robots.txt, majorly for search engines.

To disallow all search engine visits and stop the any spider or crawler, create a robots.txt and put the follow text in it:

User-agent: * Disallow: /

That’s a rather strong statement of close-up, as after you have placed the robots.txt file in the document root of your domain, almost all search engine spiders would stop accessing and indexing your entire site, preventing the precious information that you want to keep private from leaking outside.

Usually, you just want a sub folder / directory under the domain to be excluded from the search engine crawling scope, then below is what you need:

User-agent: * Disallow: /data/

Similarly, put the robots.txt at the root directory of the domain, and all play-by-the-rules search engines would never break your privacy by accessing http://www.yoursite.com/data/ any more.

Categories
Programming Tips & Insights

Incisive Software Engineering & Programming Quotes and Sayings

“ If debugging is the process of removing software bugs, then programming must be the process of putting them in. ”

– Edsger Dijkstra

“ Rules of Optimization:
Rule 1: Don’t do it.
Rule 2 (for experts only): Don’t do it yet. ”

– Michael A. Jackson

“ The best method for accelerating a computer is the one that boosts it by 9.8 m/s2. ”

– Anonymous

“ Walking on water and developing software from a specification are easy if both are frozen. ”

– Edward V Berard

“ Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. ”

– Brian Kernighan

“ It’s not at all important to get it right the first time. It’s vitally important to get it right the last time. ”

– Andrew Hunt and David Thomas

“ First, solve the problem. Then, write the code. ”

– John Johnson

“ Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration. ”

– Stan Kelly-Bootle

“ Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ”

– Rick Osborne

“ Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ”

– Martin Fowler

“ Software sucks because users demand it to. ”

– Nathan Myhrvold

“ Linux is only free if your time has no value. ”

– Jamie Zawinski

“ Beware of bugs in the above code; I have only proved it correct, not tried it. ”

– Donald Knuth

“ There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code. ”

– Flon’s Law

“ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ”

– Tom Cargill

“ Good code is its own best documentation. As you’re about to add a comment, ask yourself, "How can I improve the code so that this comment isn’t needed?" Improve the code and then document it to make it even clearer. ”

– Steve McConnell

“ Programs must be written for people to read, and only incidentally for machines to execute. ”

– Abelson / Sussman

“ Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. ”

– Alan Kay

“ Programming can be fun, so can cryptography; however they should not be combined. ”

– Kreitzberg and Shneiderman

“ Copy and paste is a design error. ”

– David Parnas

“ Before software can be reusable it first has to be usable. ”

– Ralph Johnson

“ Without requirements or design, programming is the art of adding bugs to an empty text file. ”

– Louis Srygley

“ When someone says, "I want a programming language in which I need only say what I want done," give him a lollipop. ”

– Alan Perlis

“ Computers are good at following instructions, but not at reading your mind. ”

– Donald Knuth

“ Any code of your own that you haven’t looked at for six or more months might as well have been written by someone else. ”

– Eagleson’s law

“ Java is to JavaScript what Car is to Carpet. ”

– Chris Heilmann

“ It’s hard enough to find an error in your code when you’re looking for it; it’s even harder when you’ve assumed your code is error-free. ”

– Steve McConnell

Categories
AJAX Tips and Tricks Domains Internet Tools

The Best Online Domain Name Availability Checker Tool (AJAX)

As if there’s an offline one to check whether a domain is available or not. 😉

Psychic Whois is it.

psychicwhois: domain availability checker

It’s the best domain availability checking tool I know so far. AJAX powered, it instantly checks whether a domain is available for registration after you have typed the primary part by listing all 6 popular TLDs: .com, .net, .org, .biz, .info and .us and the name’s availability for each of them. Not only that, it suggests keyword combinations based from what others have searched and queried.

If you need to search for 100s of domains  at one time, bulk domains search tool is what you need.

Categories
Business and Marketing Kavoir & Whatever

The most dangerous thing in your career or business

It’s not the mistakes or failures themselves that you should be aware of. Everything is a bless including them which descend upon you for you to grow. Bad attitude rather than bad things is the driving force to your self-destruction.

So what is the most dangerous mistake you could make in your career and business.

It’s what you have always believed right instead of judged right.

Too often a startup fails because of something the CEO sticks his guts to – it’s always that way and it got be that way this time.

Too often a kingdom collapses as a result of the perverse and arrogant Kingship.

Too often an army flee by the blind confidence of the commander.

Always ask yourself when making a decision: Is this something I have believed in or reasoned for?

Categories
CSS & HTML Tips Web Design Tips and Insights

Styling an Alphabet of 26 Letters in HTML and CSS

What does an alphabet have for us to style? It’s no more than a list of 26 single-letter items! Yep. But wait until you have seen this alphabet of 26 letters author index.

Now do you want to know how to achieve that? I coded it quite a while back and it just occurred to me that it would be nice to share it with my fellow readers. You can easily apply the hover tricks to other applications.

The HTML

I know, it’s everything but simplicity and clean code. That is the price for the interactive delicacies.

<div id="author_alphabetic">
	<ul>
		<li><a href="#" title="A"><span class="first"><span>A</span></span></a></li>
		...
		<li><a href="#" title="Z"><span class="first"><span>Z</span></span></a></li>
	</ul>
</div>

Note the extra span I have for the letter links for the fly out and rounded corner background.

The CSS
#author_alphabetic {
	text-align:center;
}
#author_alphabetic ul {
}
#author_alphabetic li {
	float:left;
	margin:3px 3px 0 0;
}
#author_alphabetic a {
	position:relative;
	width:74px;
	height:74px;
	border:1px solid rgb(203, 214, 149);
	text-decoration:none;
	font:2.4em/2.4em "Times New Roman";
	float:left;
	display:inline;
	color:#330;
}
#author_alphabetic a span {
	background:url(../image/alpha_br.png) no-repeat right bottom;
	width:75px;
	height:75px;
	display:block;
	position:absolute;
	top:0;
	left:0;
}
#author_alphabetic a:hover {
	background:rgb(224, 232, 158);
	z-index:100;
}
#author_alphabetic a:hover span.first {
	display:block;
	font-size:3em;
	line-height:1.1;
	font-weight:bold;
	color:#15362d;
	cursor:pointer;
	width:100px;
	height:100px;
	top:-1px;
	left:-1px;
	background:rgb(224, 232, 158);
	border:1px solid rgb(203, 214, 149);
}
#author_alphabetic a:hover span span {
	background:url(../image/alpha_br.png) no-repeat right bottom;
	display:block;
	position:absolute;
	width:101px;
	height:101px;
}

Highlighted style rules are the ones that you should pay special attention to in this technique. A similar application can be spotted with the top deep blue menu at the home page of Charm HTML wherein you can make the size of the inner element bigger than the container or the position of it out of the normal document flow to mimic an outstanding bookmark while keeping the underlying layout intact.

Categories
CSS & HTML Tips

HTML Table Size – Control and Change the Size of Table and Table Cells

In HTML 4.01, you can directly change the size of table via HTML properties width and height instead of controlling them by CSS styles.

Table Size

The overall size of a table is determined by the width and height of it.

For example, to set table width as 400 pixels and table height as 150 pixels:

<table width="400" height="150">
...
</table>

You can also specify a percentage for the table to be adjusted proportionately to the width or height of its container. For example, setting a width of 50% to this table will result in it being always half the width of the page while maintaining a height of 150px:

<body>
	<table width="50%" height="150">
	...
	</table>
</body>

You can apply the same value to height as well, which depending on the container, may or may not work.

Cell Size

HTML table cells are denoted by td tag which can be controlled in size by the same approach – the width and height attributes:

<table width="100%">
	<tr>
		<td width="325">&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td height="113" width="325"></td>
		<td height="113"></td>
		<td height="113"></td>
	</tr>
	<tr>
		<td width="325">&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
</table>
The CSS way

In the era of XHTML, you have to do all styling and presentational decoration in the CSS way, width and height attributes on table and td are simply unacceptable. The applauded approach is to have the style attribute wherever it needs additional styling such as changing the size of HTML table or table cell:

<table style="width: 400px; height: 150px;">
...
	<tr>
	...
		<td  style="width: 325px; height: 113px;"></td>
	</tr>
</table>