unserialize():40个字节的偏移量0处出错

时间:2019-02-23 16:21:27

标签: laravel

当我尝试登录服务器站点时出现此错误。enter image description here

如何解决此错误?

3 个答案:

答案 0 :(得分:1)

Laravel从V5.6.30更改了其处理cookie的方式,以提高安全性。可能是您尝试解密未序列化的内容,反之亦然。

首先,在浏览器中删除cookie和/或在Laravel应用中清除会话文件

或者,在中间件// MainActivity public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Bundle itemsScreenData = getIntent().getExtras(); if(itemsScreenData == null){ return; } ArrayList<String> elementsMain = new ArrayList<String>(); ListAdapter myAdaptor = new MainScreenAdapter(this, elementsMain); ListView mainList = (ListView) findViewById(R.id.mainList); listaMain.setAdapter(myAdaptor); String items = itemsScreenData.getString("Type"); elementsMain.add(items); } public void onClick(View view) { Intent mutare = new Intent(this, ItemsScreen.class); startActivity(mutare); } } //Main activity adapter public class MainScreenAdapter extends ArrayAdapter<String> { public MainScreenAdapter(Context context, ArrayList<String> elementsMain) { super(context, R.layout.custom_row, elementsMain); } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater myInflater = LayoutInflater.from(getContext()); View customView= myInflater.inflate(R.layout.custom_row, parent, false); String someItems = getItem(position); TextView textItem =(TextView)customView.findViewById(R.id.textItem); textItem.setText(someItems); return customView; } } // Second activity - The list of predefined items public class ItemsScreen extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.items_screen); final String[] items = {"Coffee", "Espresso"}; ListAdapter anAdapter = new CustomAdapter(this, items); ListView myList = (ListView) findViewById(R.id.myList); myList.setAdapter(anAdapter); myList.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String element = String.valueOf(parent.getItemAtPosition(position)); Intent i = new Intent(getApplicationContext(), MainActivity.class); i.putExtra("Type", element); startActivity(i); } } ); 中,您可以将其翻转以进行测试:

添加:app\Http\Middleware\EncryptCookies.php

这是一个非常常见的问题-如果不起作用,您可以在堆栈溢出中搜索类似的答案。

答案 1 :(得分:0)

您必须设置一个新闻密钥,使用以下命令:

php artisan key:generate

在测试之后再次运行Laravel应用程序

php artisan serve

请参阅类似的问题:unserialize(): Error at offset 0 of 40 bytes Error

答案 2 :(得分:0)

在浏览器中删除cookie和/或在Laravel应用中清除会话文件。

当我将Laravel 5.5应用程序升级到5.6时,我遇到了同样的错误。该错误来自EncryptCookies-Middleware。