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

 PHP


  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:<?phpclass ArrayValue implements JsonSerializable { public function __construct(array $array) { $this->array = $array; } public function jsonSerialize() { return $this->array; }}$array = [1, 2, 3];echo json_e...

10,281 0       JSON INHERITANCE JSONSERIALIZE EXTENDS


  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 how to setup the PHP environment on Mac OS X. This setup guide should also be helpful on other system...

4,519 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_vars()This is a very useful function when you wants to debug your codes when there are some issues. It will re...

6,557 0       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 use the session variables again?If we read the description carefully, we can find what this function does...

7,427 0       SESSION_DESTROY SESSION_START


  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 lifetime of a session in seconds which indicates when the session will be garbage collected. Then se...

21,270 3       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`) VALUES ("laruence", "weibo");But the query actually gets executed is :INSERT INTO `user` (`username`, `passwor...

9,209 1       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->Save as on the browser. Then they only need to modify the action attribute of the form, instead of the ...

13,768 0       PHP SECURITY REMOTE FORM SUBMISSION


  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 2012Status11C17.628%-0.70%  A22Java15.906%-0.18%  A33Objective-C10.248%+0.91% ...

47,471 7       PHP TIOBE ZEND FRAMEWORK JULY