Facebook Login Callback Error

Facebook Login Callback Error

I was implementing Facebook Login on my site, and I found this error when Facebook Callbacks to my site with AccessToken.
Error: “Cross-site request forgery validation failed. The “state” param from the URL and session do not match.”

I searched on internet found some solutions like use session_start(), correcting the sequence which nothing worked for me. I checked in Chrome Debugger Network Panel and I found that favicon tag was not assigned and it was calling the same url again so, the facebook url created by the previous request was invalidated and new value for key “FBRLH_state” in session was generated. It was easy to fix the image which I did but as a permenant solution I implemented this flow.

1- Login Page: Create a static url in my site for Facebook Login (mysite.com/facebook-login) and set to the button “Login with Facebook”.
2- Facebook Login: generate the Facebook Login Url (mentioned in Facebook SDK Documentation) and redirected the request that url.
3- Facebook Callback: The standard way mentioned in Facebook SDK Documentation.
4- Happy Flow 🙂

How to disable srcset in WordPress

How to disable srcset in WordPress

WordPress 4.4 has a new feature which let browsers to select the best image according to the device screen size from a set of images resized by WordPress for different screen sizes. It help to minimise loading time and also bandwidth because if you are using iPhone, it will only load images for iPhone screen instead of big images which are for desktop screens.

As this is the new feature and many plugins are not optimised to use this feature so, plugins may misbehave (i.e. yith-woocommerce-zoom-magnifier on thumbnail selection where it don’t change the image but show the image on mouse hover). So, the quick solution is to disable this feature until new compatible version of plugin is released. You can use following code to do it.

function shiota_disable_srcset( $sources ) {
return false;
add_filter( 'wp_calculate_image_srcset', 'shiota_disable_srcset' );

Ideas are nothing without execution!

Ideas are nothing without execution!

Every person working in some area or even stay at rest has some idea in his mind, some people focus on them and some ignore. The person who focuses on his idea sometime becomes too sensitive about their idea and don’t even discuss with others because it may be stolen and implemented by other. And after all, the idea kept secret without any outcome.

Its important to keep in mind that the idea is nothing without execution. Its not about the idea but the way it is executed which makes a person successful. You may have listened about the Facebook story and also about Windows. From all these, we learned that the strategy of execution is the most worthy thing than the idea itself.

So don’t be sensitive, discuss your idea with others openly and learn the pros and cons before it getting too late for you. May be you will be the next Bill Gates or Mark Zuckerberg.

Stop thinking too much, start from today and discuss with those people who can work with you to make it happen.

You can also discuss with me for a free consultation. I am a top rated developer on UpWork and have 9+ years of software development experience. You can visit my profile at https://www.shozab.com/upwork

PHP Serialization vs JSON Encoding for an array

PHP Serialization vs JSON Encoding for an array

When I was working for saving huge array in database, an idea came to mind to look into serialization against JSON. So I searched on internet and found that serialization technique is fast and I also read somewhere that unserialization for huge data is slow as compared to json_decode.

So, I made a program and do an experiment to find out the complexity for space and time of both methods with respect to the data size. Now, I am sharing my results with you. Let see.

My program generates the statistics for serialize/unserialize and JSON encode/decode and also size of serialized and JSON encoded data.

Let see the graphs.

You can see that the json_encode() is very fast as compared to serialize(). But as we know that, encoding will be useless if decoding is slow for a method. So let see the decoding/unserialization graph.

If you look for less data size, you will find that the process is fast for unserialization and for data size larger than 25000, JSON decoding is going to be faster as compared to unserialize. So, it means that if you are working for huge data than use json_decode().

Ooopsss. . . space complexity for serialization method is too high.

If you have small sized data then you can prefer serialization But for large data, serialization will be a worst choice if data is simple and just like an array.

I did this experiment for only arrays. May be results will be different for objects.

Program that I made for this experiment

	ini_set('max_execution_time', 0);
	function start_timer()
		global $time_start;
		return $time_start = microtime(true);
	function end_timer()
		global $time_start;
		$totaltime = microtime(true) - $time_start;
		echo 'Process completed in ' . $totaltime*1000 . ' ms</br>';
		return $totaltime;
	function get_random_string($valid_chars, $length)
		$random_string = "";
		$num_valid_chars = strlen($valid_chars);
		for ($i = 0; $i < $length; $i++){
			$random_pick = mt_rand(1, $num_valid_chars);
			$random_char = $valid_chars[$random_pick-1];
			$random_string .= $random_char;
		return $random_string;
	function save_csv($data)
		$csvstring = implode(array_keys($data[0]),',')."\n";;
		foreach($data as $v)
			$csvstring .= implode($v,',')."\n";
	function runtest($datasize)
		$stats_row = array();
		echo "<u>Making Test Data of size $datasize</u></br>";
		$array = array();
		for($i=0; $i<$datasize; $i++)
			$array[] = array('id'=>$i, 
		$stats_row['datasize'] = $datasize;
		echo '<u>Encoding in Json</u></br>';
		$jsonencodeddata = json_encode($array);
		$stats_row['encode_json'] = end_timer();
		$f = 'tmp/'.$datasize.'_json.dat';
		$stats_row['json_size(MB)'] = filesize($f)/1048576;
		echo '<u>Decoding from Json</u></br>';
		$jsondecodeddata = json_decode($jsonencodeddata);
		$stats_row['decode_json'] = end_timer();
		echo '<u>Serialization of data</u></br>';
		$serializeddata = serialize($array);
		$stats_row['serialize'] = end_timer();
		$f = 'tmp/'.$datasize.'_serialize.dat';
		$stats_row['serialize_size(MB)'] = filesize($f)/1048576;
		echo '<u>Unserialization of data</u></br>';
		$unserializeddata = unserialize($serializeddata);
		$stats_row['unserialize'] = end_timer();
		return $stats_row;
	$stats = array();
	$files = glob('tmp/*'); // get all file names	
	foreach($files as $file){ // iterate files
		unlink($file); // delete file
	for($i=1000; $i<50000; $i+=1000)
		$stats[] = runtest($i);
		echo '<hr>';

If I am wrong at any place then guide me by placing a comment.


How does helicopter tilt?

How does helicopter tilt?

Our helicopter has been up in the air since last post “How does helicopter go up in the air?” But how it can be moved forward or backward or tilt right or left? Its mechanism is little complex but really interesting.

Note: If you don’t know what is tilt then please goto google.com and search “tilt” and see the result. 🙂
As my nature, I always try to find the answer with thinking without making any search on internet.
Let me share my thoughts. I thought, helicopter can make down one side of its rotor that tilts the helicopter in other side but it is useless thing because if we try to make down one side of rotor then rotor will balance again itself in air and helicopter will be tilted but will not be moved one side as effectively as it must be because rotor’s center is a mounted point.
After that I thought that maybe there is a moveable weight that changes the center of gravity of helicopter that tilts the helicopter in one direction. It seems good point but not much effective. So, then I think about angle of blades because I know the angle of blades is the main thing that makes the helicopter up in the air. But how? I found the really amazing thing on Wikipedia. Let me describe this thing in my own words.

There are two swash plates. One is fixed but tiltable using controlling rods and the other one is rotatable. The Fixed one is tiltable in all four directions that changes the angle of blades individually. Rotatable plate is just rotating parallel to fixed plate. Let understand the working in four tilting directions.

Forward Tilt: Angle of blades will be zero at back and will be max downward at front.
Backward Tilt: Opposite of Forward Tilt.
Left Tilt: Angle of blades will be zero at right and will be max at left.
Right Tilt: Opposite of Left Tilt.

It is because of rods connected from swash plate to blades. Tilting of swash plate pull the rods located on one side and push the rods up on other side.

See these pictures for better understand the process.

You can see in second picture that when a blade goes in left top side (picture ref.), its angle decreases towards zero and increase when this blade comes to right bottom. This is how the swash plate works and makes helicopter to be tilted in one direction. When this tilt occurs, blades pushes air downward from one side at fast speed and on other side with low speed and in response helicopter tilts. See this picture

The combination of all four tilting points that make helicopter be tilted in any direction (North to East to South to West).

Now, we can go to meet our beloved friends using our helicopter. Hope you have enjoyed it. 🙂

Source: wikipedia.com

How does helicopter go up in the air

How does helicopter go up in the air

Helicopter is an aircraft that flies with the help of a rotor like fan that push the air downwards and in response helicopter goes up. Rotor is big enough to lift the weight of Helicopter. The mechanism of rotor is very simple and I think everyone can understand in a single preview of working. I am just describing some aspects of rotor that enable the helicopter to be flying.

There are two rotors in basic type of helicopter. One is mounted on top (Main Rotor) that enable the helicopter to be up in the air and other one is on the tail (Tail Rotor) that balances the torque produced by Main Rotor as a side effect.
Each rotor has two blades at 180(deg) and can also be rotatable at its own axis that makes lift. See this picture.

If blades are at 0 (deg) then there will be no lift in helicopter and if blades are at max angle then Helicopter goes up fast. You can easily understand by imagining this scenario.

Now, about Tail Rotor, Tail Rotor’s main purpose is to balance the torque produced in the response of Main Rotor’s motion. It is also used to rotate the helicopter along the axis perpendicular to the Earth by decreasing and increasing the angles of its blades. See this picture.

In this picture, you can see that Main Rotor is rotating about its mounted point. Main Rotor’s rotates by the force applied by helicopter in anti-clockwise, because of this force, an opposite force will be generated by Main Rotor to helicopter because of resistance produced due to inertia and air and some other factors. This opposite force tries to rotate the helicopter in opposite direction that’s called torque. This process is so fast that’s why this force produces much torque as soon as the rotor speed increases. So balancing of this force is necessary to make the helicopter stable in a direction otherwise helicopter will also rotates and I think, no one will want to enjoy this adventure. So, Tail Rotor is assembled vertically in tail of helicopter that rotates and cancels out the torque to make the helicopter stable. Imagine this whole process. It is really easy to understand.

Now, our helicopter is up in the air. 🙂

Source: wikipedia.com