Today's Question:  What are you most afraid of as a programmer?        GIVE A SHOUT



  jsonSerialize() in extended class

Since PHP 5.4.0, there is a convenient interface JsonSerializable which can be used to indicate that a PHP object can be serialized to JSON object. It has only one method which should be implemented by any class which implements this interface. The method is named jsonSerialize(). It's really easy to serialize an object to JSON object. Here is one example: <?php class ArrayValue implements JsonSerializable { public function __construct(array $array) { $this->array = $array; ...


  PHP Apache MySQL Set-up Note

With the emergence of WAMP, LAMP, PHP developers are liberated from the tedious work of setting up PHP environment. Since PHP, Apache and MySQL are so tightly bundled, WAMP and LAMP provide a setp solution for setting up a PHP environment which includes the programming programming environment, server and database. But for a PHP who wants to learn more, you have to try to set the PHP environment yourself by installing PHP, Apache and MySQL manually and configuring them. Below is a simple note on ...

2,720 0 0          PHP APACHE MYSQL

  10 less known but useful PHP functions

PHP has abundant built in functions. As PHP developers, we may have used many of them. But there are still some useful functions we may not be so familiar with. In this post, we will introduce some of them. levenshtein() Have you ever wondered how to check differences between two works? This function just does what you want. It can tell you how much the difference is between two words. <?php $str1 = "carrot"; $str2 = "carrrott"; echo levenshtein($str1, $str2); //Outputs 2 ?> get_defined_va...

4,497 0 1          PHP FUNCTION

  What does session_destroy() do in PHP?

In PHP manual, the description for session_destroy() function is : session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called. I am confused about this description. If this function destroys all session data, then why the global variables associated with the session are not unset? Why can we u...


  Set PHP session timeout

There are many different discussions about PHP sessions. We may often face some weird issues while handling PHP sessions. Sometimes session is expired earlier than expected. Or sometimes the session is not expired. This introduces many confusions. Today we discuss how to set PHP session timeout correctly today. In php.ini, there are three key parameters which will affect the session timeout. session.gc_maxlifetime, session.gc_probability and session.gc_divisor. session.gc_maxlifetime defined the...

14,011 1 0          PHP SESSION TIMEOUT

  A trap in PDOStatement::bindParam

First, let's check out below codes: <?php $dbh = new PDO('mysql:host=localhost;dbname=test', "test"); $query = <<prepare($query); $bind_params = array(':username' => "laruence", ':password' => "weibo"); foreach( $bind_params as $key => $value ){ $statement->bindParam($key, $value); } $statement->execute(); What is the SQL executed finally? Is there any problem with above codes? Many people may think the query executed is : INSERT INTO `user` (`username`, `password...

6,933 1 0          PHP TRAP BINDPARAM

  Remote form submission

Remote form submission is way of submitting HTML forms from local to a particular remote server. This is used by many advertisers, spammers or even hackers to submit bad data to other websites in order to get what they want. They can write some automation scripts to help them do spamming. How can people do remote form submission and how to prevent this kind of attacks? Since a website can be accessed by almost every one, so one can save a local copy of a HTML form of a website through File->S...


  TIOBE: PHP is coming back

TIOBE released the programming language index for July 2013. The highlight of this month is that PHP is coming back. It ranks the fifth and has an increase of 1.54% compared to January. There are no changes in the ranking for the top 4 languages. The reason why PHP is back may be attributed to the new PHP Zend Framework that was released in September 2012, but this reason is not very convincing. PositionJul 2013PositionJul 2012Delta in PositionProgramming LanguageRatingsJul 2013Delta Jul...