roshni Posted April 23, 2015 Share Posted April 23, 2015 Hi all, I have been trying to figure out by myself for hours but with no success. I created a object and then serialized it and passed in a URL. include_once("BabyName.php"); $babyName = new BabyName($name, $gender, $meaning, $origin, $likesCount); echo $babyName->getGender(); $babyNameSerialized = serialize($babyName); echo $babyNameSerialized; <a href="babyNameDetails.php?id= '<?php echo $babyNameSerialized ?>'"> <?php echo $name ?></a> I get output:O:8:"BabyName":5:{s:18:"BabyNamebabyName";s:6:"Akriti";s:16:"BabyNamegender";s:4:"Girl";s:17:"BabyNamemeaning";s:16:"Picture, Diagram";s:16:"BabyNameorigin";N;s:19:"BabyNamenoOfLikes";s:1:"1";} Then in babyNameDetails.php file, I get the seriazed babyName. But only O:8 gets printed. It gets serialized properly originally as I can see the echo output. But when I pass through URL, I do not get the serialized string. <?php include_once('BabyName.php'); $id = $_REQUEST['id']; echo "id: " . $id . "<br>"; $babyName = unserialize($id); echo "babyName: " . $babyName; I just get: id: 'O:8:babyName: Please let me know what am I doing wrong. Thank you, Roshni Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/ Share on other sites More sharing options...
Muddy_Funster Posted April 23, 2015 Share Posted April 23, 2015 try making a url variable and echo it back: $url = "babyNameDetails.php?".$babyNameSerialized; echo $url; echo "<a href=\"{$url}\">{$name}</a>"; Then on the receiving page stick in print_r($_GET) and see what's sent over Also: ONLY ONE THREAD IS REQUIRED, POSTING MULTIPLE DUPLICATES IS AGAINST FORUM T's&C's (not to mention it upsets people...like me....and discourages those people from helping you) Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509748 Share on other sites More sharing options...
roshni Posted April 23, 2015 Author Share Posted April 23, 2015 i am so sorry I posted more than once. I did not realized I had posted more than once because everytime I hit the submit post button I would get "page cannot be displayed" page. I thought I was not able to post my problem on this forum at all. Thanks for the response. Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509749 Share on other sites More sharing options...
roshni Posted April 23, 2015 Author Share Posted April 23, 2015 Thanks Muddy_Funster. I tried what you suggested. But in the receiving page it is: Array ( [id] => 'O:8: ) It is the same thing as I was getting before. If you could suggest be something else too, I would try. Thank you, Roshni Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509751 Share on other sites More sharing options...
cyberRobot Posted April 23, 2015 Share Posted April 23, 2015 i am so sorry I posted more than once. I did not realized I had posted more than once because everytime I hit the submit post button I would get "page cannot be displayed" page. I thought I was not able to post my problem on this forum at all. Thanks for the response. If it makes you feel any better, you're not the only one who's had these problems. I (along with the other gurus, moderators, and admins) do our best to remove the duplicate responses in a timely fashion. Note that your duplicates have been removed. Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509752 Share on other sites More sharing options...
ginerjm Posted April 23, 2015 Share Posted April 23, 2015 Hate to say it but this seems to have many solutions available using a google search. Did you think to try that first? The topics all agree that you do : serialize urlencode urldecode unserialize Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509755 Share on other sites More sharing options...
mac_gyver Posted April 23, 2015 Share Posted April 23, 2015 the serialized data contains several characters that have significance in a url and in html as delimiters/syntax and must be urlencoded() so that they can exist as part of the value in the url. php will url decode the $_GET values for you. Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509756 Share on other sites More sharing options...
roshni Posted April 23, 2015 Author Share Posted April 23, 2015 Thank you CyberRobot. I tried serializing then encoding ...then sending over URL then decoding and then unserializing. But still I am having problems. $name = "Akriti"; $babyNameSerialized = urlencode(serialize($babyName)); $url = "babyNameDetails.php?".$babyNameSerialized; <td style="font-weight: bold;" ><?php echo "<a href=\"{$url}\">{$name}</a>"; ?></td> and in <?php include_once('BabyName.php'); print_r ($_GET); $id = $_REQUEST['id']; echo "<br>" . "id: " . $id . "<br>"; $babyName = unserialize(urldecode($_GET['id'])); echo "babyName: " . $babyName; This is what I get: Array ( [O:8:"BabyName":5:{s:18:"] => ) id: babyName: I can see the encoded data in the URL though. So the BabyName object is sent in the URL but I am not able to receive it. But I am not able to get in the $_GET or$_REQUEST. Please suggest me. Thanks, Roshni Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509762 Share on other sites More sharing options...
roshni Posted April 23, 2015 Author Share Posted April 23, 2015 Hi All, I think I am getting it now. I let you all know it few minutes if I need more suggestions Thank you all. Roshni Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509764 Share on other sites More sharing options...
mac_gyver Posted April 23, 2015 Share Posted April 23, 2015 ONLY the data being put into the URL is urlencoded(). just value after the = would be urlencoded() Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509765 Share on other sites More sharing options...
roshni Posted April 23, 2015 Author Share Posted April 23, 2015 Thank you all for the valuable suggestions for my problem. It helped solve it. I now am having issue with the lost method of the object. I get the following output: Array ( [id] => O:8:"BabyName":5:{s:18:"BabyNamebabyName";s:6:"Akriti";s:16:"BabyNamegender";s:4:"Girl";s:17:"BabyNamemeaning";s:16:"Picture, Diagram";s:16:"BabyNameorigin";N;s:19:"BabyNamenoOfLikes";s:1:"1";} )object(BabyName)[7]private 'babyName' => string 'Akriti' (length=6)private 'gender' => string 'Girl' (length=4)private 'meaning' => string 'Picture, Diagram' (length=16)private 'origin' => nullprivate 'noOfLikes' => string '1' (length=1) ( ! ) Fatal error: Call to undefined method BabyName::getName() in C:\wamp\www\babyNames\babyNameDetails.php on line 34 Call Stack # Time Memory Function Location 1 0.0011 688280 {main}( ) ..\babyNameDetails.php:0 I have this on my php page: <?php include_once('BabyName.php'); print_r ($_GET); $babyName = unserialize(urldecode($_GET['id'])); var_dump($babyName); echo "babyName: " . $babyName->getName(); It seems we cannot serialize object methods. How do we work around getting the object methods? Or is their another way of doing it? Thank you, Roshni Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509766 Share on other sites More sharing options...
roshni Posted April 23, 2015 Author Share Posted April 23, 2015 Hi All, I had used wrong method name and was wasting my time and your too Thanks to all who helped solved my original problem. Roshni. Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509770 Share on other sites More sharing options...
CroNiX Posted April 24, 2015 Share Posted April 24, 2015 Not sure why you'd pass an object via the url where it can be manipulated by the user. Why not serialize the object and store it in a session or something, where the user can't tamper with it? Link to comment https://forums.phpfreaks.com/topic/295803-passing-serialized-object-in-url-not-working/#findComment-1509878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.