user1755949
user1755949

Reputation: 93

Unserialize issue php

I am using the following to serialize a variable in php

$sum=30;
$a = serialize($sum);
file_put_contents('store', $a);

And in another page i am not able to get the variable by unserialize function.In my local server ,it is working fine.But when i transferred to live server,i am not able to get the unserialized variable.I am using following for unserialization,

$s = file_get_contents('store');
$a = unserialize($s);

What is the issue?

Upvotes: 1

Views: 100

Answers (1)

lisachenko
lisachenko

Reputation: 6092

General cases are:

  1. Invalid access rights for the file store, so a live server isn't able to read a data from it.
  2. Different serialization mechanisms on servers. Do you use an igbinary or suhoshin extensions? They can influence on serialization/unserialization process.
  3. Buggy version of PHP. For example, PHP versions from 5.4.6 to 5.4.11 have a lot of bugs with broken serialization.
  4. And the last one case is an invalid path to the file, check carefully that this file exists and readable by checking is_readable('store');

Upvotes: 2

Related Questions