Jump to content

[SOLVED] passing object via POST


robcrozier

Recommended Posts

Hi Guys.

 

Can anyone advise me on the best way of passing an array of objects via form post?  I've tried serialising the data, however i'm getting unserialize errors at the other end.  I've also tried storing the array as a session, however i then get an incomplete object error at the otger end?

 

I really need to get this working.

 

Any help would be great!

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/172457-solved-passing-object-via-post/
Share on other sites

Hi

 

Thanks for the reply.  Onlty thing is, when i do that, the object is unknown at the other end and thus i cant access any of it's methods to get the data out of it.

 

Unless you can help me with that error too (the unknown object one), i don't think that's gonna work.

 

Cheers mate!

The class definition needs to be within scope when you unserialize the object. eg;

 

class.foo.php

class foo {
  public $v;
}

 

a.php

include 'class.foo.php';
$f = new foo;
$f->v = 'hello';
echo '<a href="b.php?obj=' . serialize($f) . '">B</a>';

 

b.php

include 'class.foo.php';
$f = unserialize($_GET['obj']);
echo $f->v;

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.