Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Archive for July, 2012

Meet the JavaScript object

Monday, July 30th, 2012 by Servage
Hello PHP developer, please meet the JavaScript object. It's your friend :-) Actually JavaScript has similar capabilities when it comes to object oriented programming, and mastering the JavaScript object is your first step on the way to program great code in JavaScript. In the following example you will see a simple JavaScript object with the following features: Constructor method Defining an object property Getter and setter functions for object property How to instantiate and use the object Example Object Code var MyObject = function() { this.foo = 'bar'; this.construct = function() { // Do you construction stuff here } this.setFoo(value) { this.foo = value; } ...

Secure sessions with PHP

Saturday, July 28th, 2012 by Servage
When working with sessions in PHP, you basically rely on the client sending a session ID wirth every request, so you can uniquely identify the particular user. This usually works with cookies. Session IDs have a few things about them, which make them tricky to work with. First of all, the sessione engine has to create and maintain session file (or stored in another data source), but thankfully this is usually done automatically for us, for example by the PHP session handler. Also the cookie creation and retrieval of session ID is usually done by PHPs magic. So, whats the problem here then? Well, the whole session issue starts to become complicated, ...

Foreign key constraints in MySQL Workbench

Wednesday, July 25th, 2012 by Servage
In this previous article you were introduced to MySQL Workbench, which essentially is a pretty great app to work with data modelling for MySQL databases. In MySQL you can work with different indexes, keys and contraints, which are tools that help you build and maintain logical relationships between entries and tune your database for performance. One of those is the foreign key, which is automatically added to rows when using the relations functionality in MySQL workbench. What are foreign keys If you are used to manually create your database on your hosting account, for example using phpMyAdmin or similar, you might not create foreign keys. Their purpose is to indicate how a ...

New input elements in HTML5

Tuesday, July 24th, 2012 by Servage
Have you already checked out the new input elements in HTML? For many years developers have been forced to be creative when using input elements in forms. Creating a special input element might have involved the use of multiple other elements. For example a date and time or credit card field would contain multiple input fields or dropdowns. In HTML5 some new input elements have been introduced, which standardizes and makes it easier to implement such inputs. New available input types color date datetime datetime-local email month number range search tel time url week It's very easy to use these types. It's just like the old "text" or other types. Example: <input type="color" name="favcolor" /> The advantage of this is that supporting browsers will render the proper element, while older ...

Page caching in Yii is very easy

Friday, July 20th, 2012 by Servage
Cahing is one of the best tools to improve performance and thereby create faster load times and an increased user experience for your users. There are many standardized cahing mechanisms you can implement, but Yii actually gives it'd developers a high level implemntation, so you don't even have to worry about the cahcing system itself. You can simply apply cahing to pages, or wherever you need it.  So check out the example on page cahing from The Definite Guide to Yii here: Page caching can be considered as a special case of fragment caching. Because the content of a page is often generated by applying a layout to a ...

Working with spatial functions in MySQL

Tuesday, July 17th, 2012 by Servage
Geo-based services are increasingly popular, and databases are getting better, faster and more advanced querieng functionality to deliver geo-based results fast and accurate. PostgreSQL with the PostGIS extenstion has for a long time been a great solution, and continues to deliver great database products to the open source community. However, MySQL is the by-far most implemented database software with hosting companies. It can be argued for and against, but the fact remains, and therefore it is great to see how spatial functionality continues to improve in MySQL. While the most stable and delpoyed MySQL versions are the lower version 5 distributions, the newer version 5.6 and upwards finally integrates rather ...

Move into your own Server space

Sunday, July 15th, 2012 by Servage
Do you want you own server? Do you need special software? Are you tired of performance problems? Are you just curious? Well, there are many good reasons to get an own virtual private server. The price is definitely also one of them! Consider this offer from Servage. It's pretty much the same cost as a shared webhosting account! RAM Memory: 256 MB Traffic: 100 GB Diskspace: 50 GB Full root access Power On/Off from CP Backup (snapshots) ACPI shutdown from CP Console access from CP Check out the plans. Cloud Based Server Virtualization The TotalCloud server virtualization offering is based on a modular setup where the servers are clustered in pairs. In these pairs, one server acts ...

PHP conversion of array elements to a string

Thursday, July 12th, 2012 by Servage
Working with arrays in PHP is very common for web developers and often used to hold data which is needed later on, for example lists, configurations, etc. PHP provides a great set of array functions which allow you to do a lot of things with your arrays. Often I find myself wanting to produce some kind of content based on an array, but I don't need the same action caried out on each element of the array, depending of being the first, any element or maybe the last. GET params example You wish to create a URL with some GET params, which you have in an array with key => value association. The ending GET ...

Help your visitors with chats on your site

Tuesday, July 10th, 2012 by Servage
Chat capabilities on websites can be implemented in various ways, and there are lots of different solutions available. The chat can be a powerful tool if implemented correctly and unobtrusive. HelpOnClick is trying to do that for you, so you can provide your website's visitors with a superb experience. Providing the right support at the right time is the best marketing and sales action you can get. HelpOnClick has a great feature set and is ready to be integrated on your hosting account. The developers say: Live Chat - as easy as it gets The advanced feature list doesn't change the most important thing of all - simplicity of use. After many ...

Selecting data from tables with the Yii framework

Friday, July 6th, 2012 by Servage
Yii is one of the best PHP frameworks out there, and it really does a lot of stuff pretty awesome. One of the things that is built right into the core functionality of Yii is CDbCriteria class, which helps you manage your queries whenever you want to select data from a database. The criteria object is especially useful in combination with the various find methods of active records. This way you get powerful and customizable methods to get data rightout of Yii for free. CActiveRecord::find() CActiveRecord::findAll() CActiveRecord::findByPk() CActiveRecord::findAllByPk() CActiveRecord::findByAttributes() CActiveRecord::findAllByAttributes() CActiveRecord::count() Here is an example of how to use the criteria object to specifcy your query $criteria = new CDbCriteria; $criteria->condition='post_id=:post_id AND status=:status'; $criteria->params=array(':post_id'=>8, ':status'=>'active'); $post = Post::model()->find($criteria); Check out the ...