Cheap Web Hosting for Developers

PHP, MySQL, Java, Unix Cheap Web Hosting

Comparing Technologies 91 When designing an application with

Filed under: Web Applications Development With PHP4.0 — webmaster @ 19:36

Comparing Technologies 93 Of course, this isn t as powerful as we d want it to be, but it s a start. Next, we could surf the Web to look for pages that have one of the (nowadays almost obligatory) chat links.Although they differ widely in look and feel/implementation,most of them can be boiled down to the following: n Java for fancy interfaces, although some use plain HTML. n A proprietary protocol with a single server (or simply database-backed). n Few predefined rooms. n Few predefined commands. Apart from these chat setups, there are chat applications and networks such as Mirabilis ICQ or the diverse Instant Messaging Systems systems that don t always provide real-time services and generally require additional proprietary client software to be installed on every participating system. However, one system stands out from the list. IRC (Internet Relay Chat) is a widely- known and long-used chat protocol used by many networks, some of which carry hundreds of thousands of users simultaneously.The IRC protocol is text-based a drawback when operating under high load (long string commands generate much more traffic than single binary characters), but this also makes it significantly easier to process. Most current IRC servers support compressed backbone links, which greatly reduce traffic. Although IRC requires special client software on every participating system, we can tweak this requirement to our advantage:Why not provide the client software ourselves server-side, and abstract it by using an HTML interface and allowing each user access to the network through an HTML client? This would give us control over what the user can do (each user is required to use our HTML client).Additionally,we have all the advantages of an existing network system: reliable client software, proven concept,hundreds of tools,etc.We could even allow users to use their own client software an option to be avoided in most cases, however, as we want to create a closed chat network. On a closed network, you know every way that each client can access your network. By limiting the access points to specific setups, you greatly reduce the risk of being attacked. This directly leads to the question, do we need a real protocol such as IRC? Or would it be sufficient to simply use a database-driven protocol, with a remote synchronization feature to provide the requested networking abilities? Questions such as this will arise every time you plan an application, and they ll arise often. Make sure that you ve got all of them covered, and make sure that no questions will arise at a later stage during development. This is the point where you can still address these questions; later on you might be unable to resolve them (and eventually get your project kicked into the trash).A good project is a project without doubts, without uncertainties, without inconsistencies, and without unforeseen eventualities. Make sure that after your planning phase you can assure a stable, fully evaluated situation!

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

Comparing Technologies 91 When designing an application with

Filed under: Web Applications Development With PHP4.0 — webmaster @ 19:36

92 Chapter 3 Application Design: A Real-Life Example n Do similar systems exist that perform almost the same task? n If so, can we reuse anything from that design? n Can we reuse foreign techniques, maybe add up to our system with them? Questions over questions. The first is easy to answer.We want to create a chat system.How? Well,with PHP, and somehow server-side we don t know much more about it at this time. Are there already any chat systems or something similar out there? Indeed there are. It starts right at your shell the talk command allows you to chat with other people that you can reach via a valid network link (or local link), as shown in Figure 3.1. Figure 3.1 The traditional talk command.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

Comparing Technologies 91 When designing an application with

Filed under: PHP Web Hosting — webmaster @ 19:36

Comparing Technologies 91 When designing an application with a customer, this step is called creating the specifications (or just specs).At this point,the customer can still influence the layout of the application.This is very important because the application must meet the requirements listed in this step, or it won t be approved by the customer. The Customer Is Always Right, Even When He s Wrong Customers who contract you for an application often do not have enough expertise to design such an application by themselves, which is why they hire you.When discussing requirements with customers,guide them when they re suggesting bad solutions.For example,if the customer says, I want a chat that displays full-screen images of every chatter, refreshed at least every second, you might make this counter-suggestion: Wouldn t it be better to try to stick to thumbnail views next to each line? Most of your chatters won t have enough bandwidth to display full-screen pictures at all. But be careful; never insist on your point of view (except when customers want you to implement unrealistic features).After all, customers pay you to implement their vision.To avoid losing a contract,you may have to accept temporarily implementing a bad solution (when you see that you can t talk the customer into doing it the right way), and then later on change it when the customer sees that it won t work out using their strategy. For this project, you will take the role of the project manager and the authors will be your customers. Since we re nice customers, we won t keep insisting on nailing down further details of this application;we ll leave the rest of the design to you.Whenever this chapter hits a point where a choice or decision can be made, sit back and try to make your own choices. Closely evaluate all facts and then compare your results with the conclusions discussed in the book. Comparing Technologies Before even starting to think about code layout, there s a phase we don t know what else to call but getting things together. This is the intermediate step between the idea and the specs/code layout stage figuring out the inner workings and on what to base them. To make it clearer, let s go back to the very beginning: n What do we want to create? n How are we going to create it? n Are there any existing implementations of our idea already?

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

Summary 87 Summary In this chapter, you ve learned

Filed under: Web Applications Development With PHP4.0 — webmaster @ 14:36

3 Application Design: A Real-Life Example Prevent trouble before it arises. Put things in order before they exist. The giant pine tree grows from a tiny sprout. The journey of a thousand miles starts from beneath your feet. APPLICATION DESIGN IS A TOPIC SO BROAD that a whole book couldn t fully cover it.The term application design contains merely every single part of development, from data structure layout, flow charts, and entity-relationship diagrams to code layout, documentation, and anything in between. Because it is so important, however, we decided not to exclude it from this book, but instead to tackle a discussion of application design by restricting the topics covered to a hands-on example, namely phpChat.This chapter will give you an in-depth view of this real-time chat server application implemented in PHP,similar to an extended software case study.We hope that you can extract useful information and methods to use when designing your next application.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

Summary 87 Summary In this chapter, you ve learned

Filed under: Web Applications Development With PHP4.0 — webmaster @ 14:36

90 Chapter 3 Application Design: A Real-Life Example Many of the boxed notes in this chapter contain remarks about techniques common to application design that you should memorize and try to use directly on the suggested example (or phpChat in general), and indirectly on your next project. Note: Another, more theoretical but shorter discussion about application design can be found in Chapter 7, Cutting-Edge Applications. Project Overview When designing an application, you start with the idea of what the application is supposed to do. In the case of phpChat, the application is supposed to provide a browser-based chat service. The chat should have the following features: n Real-time chat. No deferred relaying of messages and no refreshes. n No client-side programming. The browser should be confronted only with pure HTML (and eventually some JavaScript). n Networkable. It should be possible to link chat boxes. n Generic. Make as few assumptions about the target systems as possible and introduce as few requirements as possible. n No design enforcements. Separation of code and page layout. n Easy to use and administer. n Unlimited number of clients and chat rooms. Once you ve gotten this far and know what your application is supposed to do, you have to evaluate the concept and create a more detailed overview of how the application should be laid out. Take the time to write down all the requirements. It helps a lot, especially as a reminder later on.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

Summary 87 Summary In this chapter, you ve learned

Filed under: Web Applications Development With PHP4.0 — webmaster @ 14:36

Summary 87 Summary In this chapter, you ve learned a lot about PHP s advanced syntax and good coding practices.You ve seen how to create constants using define().Then the more tricky aspects of arrays were outlined, and you learned that you should use list()/each() to traverse hashes.We ve explained PHP s OOP features,and shown you how and when to use them and when to stick to procedural programming instead. Because PHP is an interpreted language, it allows many features that would be very hard to implement with traditional compiled programming languages: variable variables and functions, self-modifying code,and runtime evaluation of source code.With this knowledge, you re well prepared for advanced PHP programming, and a big step further on your way to becoming a PHP wizard.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

84 Chapter 2 Advanced Syntax Figure 2.13 Input

Filed under: Web Applications Development With PHP4.0 — webmaster @ 04:02

Polymorphism and Self-Modifying Code 85 Figure 2.14 Sample output of the function plotter. The function generated by parse_function() would be as follows for the example (m * x + b) / (x / 3) : function calculate($req_code, $x) { eval($req_code); return(($m * $x + $b) / ($x / 3)); } $req_code contains the input from the second form field, in this example $m = 10; $b = 20;. Executing that using eval() results in correct variable assignment for the next line, which already does all the calculation and that s it! Note: For important information about the eval() statement, see the earlier warning! The rest is straightforward function plotting; the for() loop iterates through a predefined range and uses calculate() to determine the curve sY value in each iteration.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

84 Chapter 2 Advanced Syntax Figure 2.13 Input

Filed under: PHP Web Hosting — webmaster @ 04:02

86 Chapter 2 Advanced Syntax Self-Modifying Counter To name just a simple example, hit counters can be created using self-modifying code. Usually, hit counts would be calculated from log files or retrieved from a database but a much simpler method is to use self-contained counters. Self-contained means that counter code and counter data are actually in the same file: $counter = 0; ////////////////////////////////// // Do not modify above this point ////////////////////////////////// // increase counter $counter++; // write counter back to ourselves $file = fopen(basename($PHP_SELF), r+ ); fputs($file,

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

84 Chapter 2 Advanced Syntax Figure 2.13 Input

Filed under: PHP Web Hosting — webmaster @ 04:02

84 Chapter 2 Advanced Syntax Figure 2.13 Input form of the dynamic function plotter. The first field takes the function that is to be plotted.This example makes the assumption that x is always the only variable this function depends on. In the second field, you can enter a bit of PHP code that will be executed prior to evaluating the function statement in order to allow assignments to constants (in our case, m and b). Warning The technique used here to directly execute PHP code with eval() supplied by the user should never (we repeat: never ever) be used like this in production scripts. Executing user code introduces a huge security hole into your programs, as everyone could send something like system( rm -r /* ); and delete all data your Web server has access to. It has been done this way here as we want to concentrate on dynamic code generation and execution; for an elaborate discussion about how to secure your scripts (and avoid execution of malicious code),see Chapter 4, Web Application Concepts, and Chapter 5, Basic Web Application Strategies. For now, you can simply click Parse. Figure 2.14 shows what will appear next. So how did the script get from the input form to this graphical output? Let s discuss the inner workings step by step. After you have submitted the input form, the script starts executing the else() clause of the main if() statement.The first function called is as follows: // translate input function to PHP code $parsed_function = parse_function($function_string); parse_function() creates the PHP code from the supplied user input by applying a regular expression to it.To make comfortable use of the math function,it s embedded into a small function, which just assigns the appropriate values to the constants (by referring to user input again) and then executing the math statement, returning the resulting value to the caller.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

Polymorphism and Self-Modifying Code 81 Indeed, the regular

Filed under: Web Applications Development With PHP4.0 — webmaster @ 21:39

82 Chapter 2 Advanced Syntax Listing 2.6 Continued // the diagram height is fixed as we do not check for the // function s extreme points $width = PLOT_MAX / PLOT_STEP; $height = DIAGRAM_HEIGHT; $image = imagecreate($width, $height); // allocate colors $color_backgr = imagecolorallocate($image, 255, 255, 255); $color_grid = imagecolorallocate($image, 0, 0, 0); $color_plot = imagecolorallocate($image, 255, 0, 0); // clear image imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $color_backgr); // draw axes imageline($image, 0, 0, 0, $height - 1, $color_grid); imageline($image, 0, DIAGRAM_HORIZON, $width - 1, DIAGRAM_HORIZON, .$color_grid); // print some text imagestring($image, 3, 10, DIAGRAM_HORIZON + 10, PLOT_MIN, $color_grid); imagestring($image, 3, $width - 30, DIAGRAM_HORIZON + 10, PLOT_MAX, .$color_grid); // return image return($image); } function plot($image, $x, $y) { // import the color handle global $color_plot; // set these as static to remember the last coordinates static $old_x = PLOT_MIN; static $old_y = 0; // only plot from the second time on if($old_x != PLOT_MIN) imageline($image, $old_x / PLOT_STEP, DIAGRAM_HEIGHT .($old_y + DIAGRAM_HORIZON), $x / PLOT_STEP, DIAGRAM_HEIGHT .($y + DIAGRAM_HORIZON), $color_plot); $old_x = $x; $old_y = $y; }

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

Next Page »

Powered by Cheap Web Hosting