Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Simple PHP paging class

Frequently in our web applications, we may have many records in the database to display. In order to imrpove loading speed and efficiency, we may need to display some records at a time, so we need to paginate the records. For example, if we have 1 million book records and when users want to view the book list, it's inefficient to display all the records on the same page, we may need to have some pagination to allow displaying a portion of the records such as 20 records per page. This is a simple PHP pagination class, here is the code.paing.php<?phpclass Paging {  public static $count =...

6,171 0       PHP CLASS PAGING


  Some hidden XSS injection vulnerabilities

XSS injection refers to a Web page generates some unexpected executable js codes based on user input  and these executable codes are executed by web browser,i.e, the source code sent to web browser by the server contains some illegal js codes, and these illegal js codes are related to user's input.Common XSS injection vulnerabilities can be fixed with some functions such as htmlspecialchars(escaping HTML special characters) and strip_tags() or similar, but there are some hidden XSS injection vulnerabilities can not be fixed by the two functions above, and sometimes we are not allowed to r...

7,693 0       PHP SECURITY XSS JAVASCRIPT CODE


  Beauty of code : How to write graceful PHP code

Writing good code is an art. In order to achieve this, it is necessary to develop good programming habits at the beginning. Good programming habits not only contributes to the early project design (modular),but also allows you to the code easier to understand, so that the maintenance of the code is easier. Bad programming habits will result in more code bugs, and will make future maintenance work difficult.We introduce some good programming habits taking PHP as example. Hope this will help you.1. Planning code structureExcellent PHP code should have a clear structure. PHP object-oriented featu...

15,090 0       PHP GOOD CODE


  Why cannot compare double values directly for equality?

A question in PHP: Get some value from the database and use floatval() to convert it to floatint point value, then compare it with another value which is also converted to floating point value with floatval(). These two values are the same when using var_dump() to output, the two outputs are float(8.87), they are the same. But when comparing them for equality, the result is weird., they are not equal. Why?To analyze this question, we need to start with PHP data types. PHP uses weak types. In PHP, floating point values are stored using C's double precision type, so we need to understand how dou...

10,223 0       PHP FLOATING PRECISION COMPARE EQUALITY


  Case sensitivity in PHP

Case sensitivity in PHP is a bit messy. We recommend that you stick to the case sensitive rule in any language. Here we share some case sensitivity cases in PHP.1. Case sensitive1.1 Variable name is case sensitiveAll variables names are case sensitive, these include normal variables and superglobals such as $_GET,$_POST,$_REQUEST,$_COOKIE,$_SESSION,$_GLOBALS etc.<?php$abc = 'abcd';echo $abc; //Output 'abcd'echo $aBc; //No outputecho $ABC; //No output1.2 Constant name by default is case sensitive, usually use UPPER CASE for constant name<?phpdefine("ABC","Hello World");echo ABC; &nbs...

14,209 0       PHP SUMMARY CASE SENSITIVITY


  Output control functions in PHP

The Output Control functions in PHP allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo and data between blocks of PHP code. These output control functions include ob_start(0, ob_clean(),ob_get_contents(), etc. To be honest, I am always mess up these ob_xxx() functions, some of them have similar functions and some of them can ...

6,407 0       PHP RELATIONSHIP OUTPUT BUFFER OB


  Create cron job on CentOS

These two days, I am building a website and deploying it on a VPS server which uses CentOS 5. I don't have cPanel or Plesk for my account, so I need to install and configure everything myself including Apache, PHP, MySQL and FTP server, also today's topic cron job. Since my website has a ranking algorithm to calculate the rankings of each link and update the ranking on database and I need to calculate the rankings every 5 minutes, so I think to use cron jobs. Here are what I have done which may help you.First we need to understand the crontab commands, it can have different options with this c...

93,412 0       PHP LINUX EXAMPLE CRON JOB CRONTAB CENTOS


  PHP to get long running process progress dynamically

Frequently in web applications, we may have a request to the back end system which may trigger a long running process such as searching huge amount of data or a long running database process. Then the front end webpage may hang and wait for the process to be finished. During this process, if we can provide the user some information about the progress of the back end process, it may improve user experience. Unfortunately, in web applications, this seems not an easy task because web scripting languages don't support multithreading and HTTP is stateless.  We now can have AJAX to simulate rea...

59,268 10       PHP AJAX DEMO PROGRESS LONG PROCESS