Hi ya guys,
Have you ever nested that many if conditions that your code starts to get quite complicated? Let's give you an example
Just some simple data checks on the $_POST['name'] value. But I'm not happy with that code. For something so simply, why is the code so complex? Let's use a technique with functions to make this much simpler. Then explain how it works in regards to simplifying it.
[code language='php']function get_name() {
//make sure it's set
if (isset($_POST['name']) == false) {
return 'Error Occured'; View In Full
I will quickly run you through an example of HOW to use memcache and how it works.
Download Memcache
http://jehiah.cz/projects/memcached-win32/
And load up the .exe - you should just get a blank command box appear - the server is then running on localhost:11211
Install the Memcache extensions in to PHP
If you use something like xamp or easyphp - just enable the memcache exentions (just a case of maybe uncommenting a line or ticking a box like in easyphp).
Code Example
Put that code in a .php page (remember to have the memcache server running). Now simply run the script and it will save my name in memory for 60 seconds! To retrieve the value from memory now put this in the script (within 60 seconds else it will expire from memory).
And you will see that my name is still there!
It's quite simple really. You use add() to add new values to memory where they are View In Full
Let�s go over what a session is.
Sessions
First you call session_start() which gives you a unique ID such as: dde2ds2g67xs2zxjh89s3j8923
Everything you then save to $_SESSION is saved in a file on the server such as:
$_SESSION['message'] = 'hello';
Would be saved to:
tmp/phpsess_dde2ds2g67xs2zxjh89s3j8923
and next time you call session_start(), $_SESSION['message'] will still exist and will have 'hello' in it!
Database Problem
So, you record a members total page hits on your site, and the last time they made a page hit on your site. You keep these stats up to date like this (which is executed on EVERY page hit by the member):
$time = time();
mysql_query("UPDATE `members` SET `timestamp_last_seen` = '{$time}', `hits` = `hits` + 1 WHERE `member` = 'VBAssassin' LIMIT 1;");
Now, all you�re doing is keeping track of the last time they were seen, and the total page hits they have made while logged in.
Solution
You need to keep track of your active sessions u... View In Full
Hello,
I am going to show you how to speed up delivery of you external .js files along with examples. I will use the prototype and scriptaculous javascript libraries as a benchmark which contains 8 seperate .js files.
Unoptimized .JS
Here are the results using YSlow to benchmark the speed of the JS files downloading when there is no gzip compression, no cdn, and no minification of the js code:
Response Time (ms): 4477 (all files)
File Size (kb): 248.7
4.4 seconds to download some JS files! Thats 4.4 seconds, on broadband, to wait before the page even renders!!! So lets get that optimized.
Option 1 - Optimized .JS - Using Google
http://code.google.com/apis/ajaxlibs/documentation/index.html
This is a very quick and easy way to speed up the delivery of the library files to an acceptable level. The same files, gziped with cdn (not minimized, but gzip kind of makes up for that loss)... results in the following:
Response Time (ms): 1920 (all files)
File Size (kb)... View In Full
Recently AJAX has had a lot of hype about how it is used in the whole Web 2.0 scene. But which the great power that AJAX brings to a website, it has the capability to either destroy your site, or turn it in to something to admire!
The uses of AJAX
AJAX should be used to do one or more of the following:
Speed up delivery of content
Since only the portion of the page that is of interest needs to be loaded it means only a couple of kilobytes needs to be downloaded, instead of the whole page.
Reduce server stress
Because only a section of a page that is of interest is loaded on demand. Fewer SQL queries and fewer server side resources are required to produce just a section of a page, instead of the whole page.
Wow effect
If used with special effects (mainly when loading), it can produce a very nice looking website that has a wow effect to it!
Applications
It can be used to create application like websites! Take a look at sites such as Meebo.com for an example of a we... View In Full
Hi ya guys,
Have you ever heard of "null byte" poison? Well if not... read on...
How to create a null byte
Hold down Ctrl + Shift and press the key with the @ symbol on it. In notepad++ for example it creates a little box with the word "nul" in it. That is a null byte.
What is a null byte
It's the first character in the ascii table i.e. 0 or chr(0) for example would return a null byte (in php).
Practical Purpose
A null byte in many languages is used to detect the end of a string. As opposed to storing an integer value in the first byte or two of the string stating the total length. A null byte on the other hand would just be placed at the end of the string... in just a single byte (saving space and does not need to keep count of the total characters in a string).
PHP, C, and many other languages use null bytes to indicate the end of a string.
So whats "null byte" poison?
It's when someone enters a string and places a null byte somewhere in it. This then ch... View In Full
Here are some common versioning conventions used when developing software.
Versioning Structure
Versioning software is just a simple way of keeping track of changes made to that software. An example of a version number would be: 1.0.3.12
Or in words: Major.Minor.VMinor.Build
Major � When you do major changes that are no longer compatible with older (or newer) versions of your software then this number should be increased.
Minor � When a new feature is added this increases
Revision � When bugs are fixed this increases
Build � Increases each time the software is compiled
This will help you and your users keep track of different editions of your code and keep track of your compiled editions of code.
There are many other ways of organizing the numbers and some people even use hex numbering systems! It is just a case of working out what you want to include in the version numbers, but I hope you can see what I am trying to show by how the numbers are split up.
A... View In Full
This is purely how I use Objects in PHP and I am not saying this way will be best for you however it has proven to be the better way for myself without the disadvantages of OOP� i.e. spending more time on structure of a program than coding, and having your code jump all over the place from object to object.
My Rules (To prevent complication)
1. Each object ONLY refers to itself i.e. it will not create any new objects inside of itself.
2. Each object achieves just ONE task and does not try to do everything.
3. Objects are used to process data in an already known fashion, NOT to make decisions on what code gets executed as that would be handling the object itself and should not be done inside the object.
Functions
First of all lets decide when functions should be used instead of Object methods containing those functions. If you can do everything you need to via ONE function for example str_replace() to just replace a string it should be a function.. if however you have two... View In Full
Some of you may know that plain unparsed PHP files are sent from the server to the person browsing your website. This is down to the way in which mod_php is implemented in Apache. Facebook have suffered from their servers spitting out unparsed PHP, and many more may unknowingly be rarely spitting out PHP files as well! So, the purpose of this article is to show you how you can secure your PHP code on to your server and make sure people never get hold of your PHP files!
Includes Outside Web Root
All your include files such as database connection details and so on should all be outside your webroot. When this can not be done you may use a htaccess file in the includes folder with the following to prevent access to those files (but PHP will still be able to include them as normal).
Default File Type
This is mainly for when or if you change the file extension from php to a misspelling for example index.ph� in which case by default it would send the visitor to your site the... View In Full
Note: The term global means it can be used �anywhere in a project�. The attachment contains a word document that is easier to read and print.
Global Objects � Have methods and properties that you can access
App - Gives general information about an application
Calendar - Sets or returns the current calendar
Clipboard - Provides access the systems Clipboard
Date - Sets or returns the current system date
Date$ - Sets or returns the current system date
Forms - All loaded forms in an application
Licenses - Manipulate a collection of control licenses for use with Controls.Add
Now - Returns the current system date and time
Printer - Enables you to communicate with a system printer (initially the default printer)
Printers - Enabled you to gather information about all available printers on the system
Screen - manipulates Forms according the their placement on the screen and controls the mouse pointer
Time - Sets or returns the current system time
Time$ - S... View In Full