SEO Web Development and Design Blog

 

Archive for the ‘PHP’ Category

Detecting search engine bots with PHP

Sunday, September 7th, 2008

I have to admit i am writing this post because i will publish soon big article about cURL extension and show you how to use it to create bots which would be even able to login to web pages and do some actions there, actually nothing illegal, but still i fill the need to tell you how to detect “good” (search engine bots) and “bad” (scrappers) bots and how to protect from them. (more…)

Clone keyword in PHP

Wednesday, July 30th, 2008

A lot of people do not read PHP manual. That is a fact, they will look for answers to their questions on forums, books, blogs (like this one for example) and so on, while most of the answers they are looking for, are already there … in PHP manual. Or maybe it is me who is weired, because i like to browse PHP.net to see “what’s new”, well can’t really tell. (more…)

PHP, JSON and JavaScript usage

Thursday, July 17th, 2008

Today i want to introduce you to jSON (JavaScript Object Notation), in short, it is a simple format designed to exchange data between different programming languages. I will show you how to create JavaScript object, convert it to JSON string, and send to PHP script, which will decode jSON string to readable format (for PHP). But that’s not all, PHP script will create it’s own data object encode it to jSON string and send it back. All communication between JavaScript and PHP will be done thru AJAX. (more…)

Clean input variable PHP

Sunday, June 29th, 2008

Some time ago i wrote a post about query string and i think i pretty well covered that topic, however i didn’t mentioned one thing … cleaning input variables. In fact it is much more important to know how to clean $_POST and $_GET arrays then know how to handle query string, because variables sent by user are the only way to hack your script, it is that simple, if you take care of input variables then your script is 100% safe.

(more…)

Using PHP cURL to read RSS feed XML

Thursday, June 19th, 2008

I very rearly, use feeds, i prefer to go to my favourite website and see what is going on instead of downloading their content to my computer with some RSS reader. However the fact is feeds are getting popular and people are searching for a ways to access and easily automatically parse those feeds with PHP, and because RSS and ATOM are nothing more then XML documents then i have for you really simple way of handling those feeds which i want to share with you (thru my blog as well thru my blog feeds :)).

(more…)

PHP Query String

Thursday, June 12th, 2008

Query strings play important role in building web applications, especially if you want to make nice urls without question mark and many key, value pairs, actually it is not so easy to design application with nice urls however it is always worth doing so, because it not only looks very proffessional, such URLs are search engine friendly, which means that they will get indexed faster but also it happens that search engines have problems with indexing pages with more then 3 key=value pairs in query string.

(more…)

PHP DateTime and DateTimeZone Tutorial

Tuesday, June 3rd, 2008

With each new version PHP is getting more and more object oriented. In version 5.x we get two useful classes for date and time handling. Many programmers are still using outdated methods which are available in PHP mainly for compatibility reasons, so i want to introduce you to DateTime and DateTimeZone objects. (more…)

PHP namespaces

Tuesday, May 27th, 2008

Recently while reading some other web development blog, i have found info about PHP namespaces, for those who do not know what is a namespace here is a short explanation: Basically every language is a namespace, and it doesn’t matter whatever it is a programming language, formal language of forign language. When it comes to programming languages, some of them has got a set of namespaces and importing or including one of them allows to use a set of new classes and objects.

(more…)

Is your HTML code Tidy?

Thursday, January 3rd, 2008

When creating huge Internet applications it sometimes hard to keep your HTML code in good shape, especially if users are allowed to submit their articles or posts, there is always possibility of none closed tag or any similar small problem, with big consequences.

Basically there are two solutions for this problem, write complex scripts to check syntax of submitted text, or configure Tidy extension, write few lines of code and never think about it again. In my opinion second solution sounds more tempting, and in this article I want to show you how it is done.

But, before we start. What is Tidy extension? According to PHP manual: Tidy is a binding for the Tidy HTML clean and repair utility which allows you to clean and otherwise manipulate HTML documents.

(more…)

How to create WordPress Plugin from a scratch

Thursday, August 9th, 2007

Wordpress blogs are getting more popular then ever, there are literally hundreds of new weblogs popping up everyday. However WordPress is not a new software, so I think it is about time to learn how to create decent plugins for it, and once you learn how to write plugins you will discover that this is not only fun but can be very profitable as well.

(more…)

Optimizing PHP scripts

Friday, July 13th, 2007

This post is mainly for new programmers and web developers, but advanced programmers also can make use of it. While browsing forums i often see programmers asking questions about their scripts why doesn’t they work mainly, don’t get me wrong i have nothing against asking questions, but i noticed something else what concerned me, most of newbies do not optimize their scripts, as long as they do not have much visits on their websites it is ok, they can get away with it.

(more…)

Creating watermarks with PHP and GD Library

Wednesday, July 11th, 2007

The last post i wrote was about getting started with GD library, today i want to show you practical use of this wonderful library. I want to protect all images on my server, so i need to create watermarks for all my images, but let’s pretend i want to sell this images at the same time so there cannot be any watermarks on it. There are two solutions to this problem: create images with and without watermarks or use GD library and create watermarks on the fly. Obviously we will take advantage of the second method because it is more professional and requires less work in the end.

(more…)

Getting started with GD Library

Tuesday, July 10th, 2007

Often we need to create a chart or add watermark to image, we could do it manually and create those images by ourselves using Photoshop for example, but it would be time consuming and would cost a lot of money (to buy graphics software mainly). Fortunately PHP has got nice library for creating and editing images on the fly, it is called GD library.

This library is not installed by default with PHP, but almost always you can find it in PHP package, so if you have PHP installed then probably everything you need to install GD library is already on your computer, however you may still need to configure GD.

The best way to find out if your GD library is ready to use is to create simple script like:

If you will receive Fatal Error while running this script it means your GD library is not active and you need to install it or configure server first, it is very simple, and installation process is well covered in PHP manual so I won’t go into details here.

I assume you have your GD library up and running so we can write first script.

We will start with small image containing text only, this will be simple script, but it should give you an idea how to handle GD library.

1
 

We start with setting content type to image/png, we have to do it because using GD library we cannot throw our image into html code. If you have script ready then save it as img.php and open in browser, you should see black image with white string on it, but try to view source code, there is no html, right? This is because our img.php file is no longer text file for our server it is PNG image.

Let’s play with it further, after “?>” add to img.php “I like HTML”, save file and reload it in browser. What do you see now? A lot of signs and letters which do not make any sense? If yes then you did this exercise correctly. By adding text we corrupted our file structure, the same effect can be achieved if you open with Notepad any image on your computer add some text to it, save and close image. If you will try to open this file with some image viewer you will get error saying that there is something wrong with your file. Of course you know that, because you just edited this file by yourself.

However, what should concern you now is a fact that img.php is just image file and we can’t really do anything with it, besides displaying our image, therefore if you wish to display our image on your website with html code around it then you need to create new .html (or .php) file and add there this similar line, if your new file is in the same directory as img.php.

1
<img src="img.php" mce_src="img.php">

Now let me explain our code briefly, imagecreate(…) is a function which creates new blank image, two parameters given are image width and height of course. In the next line you can find imagecolorallocate(…) function which assigns to variable color in RGB format, BUT always first use of this function after imagecreate(…) fills background with selected color. So after first two lines we have 200 px width and 50px height black image.

In the next line we assign value which represents white color to variable $white, then by using imagestring() function we add text to our image. First parameter is a reference to image which will contain this string, second parameter is a size of build-in font (from 1 to 5), third and fourth parameters are x and y coordinates, we need to know where our string starts and this numbers define it. Fifth parameter is string which we want to put in the image and finally last parameter is color of our string, defined earlier with imagecolorallocate(…).

Imagepng(…) sends created image to output as a PNG image, analogically if we want to send our file as GIF then we must use imagegif(…), if we need JPEG then we must use imagejpeg(…). Of course you need to remember to change header if you change file format.

If we would like to save our image to file as PNG image then in our example we should redirect output stream to file, in other words instead of imagepng($img); we should write imagepng($img, “our_first.png”);.

That’s it for now. If you are new to GD library then I am confident this article will get you started and you will soon want to learn how to draw objects with GD, so for more functions visit www.php.net and find “Image Functions” category.

Zend Framework 1.0 finally relased

Sunday, July 8th, 2007

On 2nd of July stable Zend framework was released. We have been waiting for a very long for that to happen, mainly because Zend is the biggest company involved in PHP development and their every product is something that can really improve programmers work, however most of them are commercial, you need to spend some cash to get them, but Zend Framework is free for all and it is available for download at www.zend.framework.com.

(more…)