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

 PHP


  Output a file with HTTP range header in PHP

When downloading a large file, we may encounter some network issues which causes download termination and only part of the file is downloaded. When the network connection resumes next time, we may need to redownload the file again from the beginning. In order to save bandwidth, http provides a Range parameter in its header which can control the file transfer flow. With the range parameter in the header, we can resume the download from where we stop.Here is a piece of PHP code snippet which uses the range header to control which part of the file to transfer: <?php $filename=$_GET['fi...

29,284 3       PHP HTTP RANGE FILE TRANSFER


  How does PHP session work?

This article is about how PHP session works internally. Below are the steps :1. Session in PHP is loaded into PHP core as an extension, we can understand it as an extension. When session extension is loaded, PHP will call core functions to get the session save_handler, i.e interface or functions for reading and writing session data. By default, PHP will handle session data by writing and reading files on the server. But PHP also supplies custom methods for handling session data, we can use session_set_save_handler() to register the save_handler. At the same time, PHP will check whether session...

10,256 0       PHP SESSION MECHANISM


  File upload in PHP

File is a special kind of form data, when being uploaded to the server through HTTP POST request, PHP will create a $_FILES global array, the relevant file information will be stored in this global array. We will illustrate file upload with some code snippets using PHP and look into the internal work mechanism. Lastly will talk about file upload security.File uploadIn order for users to upload files in client side, we have to provide a form on the user interface. Since the uploaded file is a special data, it is different from other POST data, so we have have to set a special encoding for the f...

4,482 1       PHP FILE UPLOAD


  Handle ”cannot modify header information – headers already sent by”

Man PHP developers should encounter ”Warning: Cannot modify header information – headers already sent by ….” error before when executing a PHP script.Here are some solutions to this error.1. Blank lineCheck whether there is any blank line after , especially in the files which are used in include() and require(0, some problems are caused by blank lines.2. Add exit() after head()header (“Location: xxx”);exit();3. Use output cache<?php ob_start(); ?>… HTML codes …<?php… PHP codes …header (“Location: ….&rdquo...

11,259 2       HEADER SENT PHP ERROR HANDLE


  Tips for improving PHP efficiency

0. Using single quote to replace double quote to enclose string literal, this will be a bit faster. Because PHP engine will search variables in double quoted string.1. If a method in class can be declared as static, then make it static, this will be 4 times faster.2. $row["id"] is 7 times faster than $row[id]3. echo is faster than print, and you should use multiple parameters instead of string concatenation, i.e use comma(,) instead of dot(.) to concatenate string. For example echo $str1,$str24. Calculate the numer of loops before executing for loop, don;t calculate the number of loops in each...

14,913 0       PHP EFFICIENCY TIPS


  One reason why mcrypt responds slowly

This morning one colleague came over and talked about one script which used mcrypt responded very slowly, the server configurations are fine. But the reason for the slowness is unknown.Here is one script which reproduces the issue:<?php$dmcryptText = "dummy";$key = "foobar";$size = mcrypt_get_iv_size(MCRYPT_BLOWFISH,MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($size); //Take care $m = mcrypt_ecb(MCRYPT_BLOWFISH, $key, $dmcryptText, MCRYPT_DECRYPT, $iv);var_dump($m);When 20 requests of this script are sent to the server in parallel, the response time of Apache server increases rapidly.The r...

9,121 8       PHP SOLUTION SLOW MCRYPT RESPONSE


  Kodiak PHP can run PHP codes offline on iPad

In the eyes of the vast majority of application developers, iPad is the terminal equipment for running code, rather than the tool used to write code. However, there are some applications developers finding iPad's potential to develop a wide variety of programming applications with some applications, such as Diet Coda, Koder, Gusto and so on. The family of applications for writing applications has added a new member -  Kodiak PHP. This application runs on iPad, it can be used to develop PHP applications and also can be used to run PHP codes offline.Kodiak PHP is an Integrated Development E...

4,715 0       IPAD KODIAK PHP ROGRAMMING


  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,175 0       PHP CLASS PAGING