Search Results

Search found 64 results on 3 pages for 'unserialize'.

Page 1/3 | 1 2 3  | Next Page >

  • unserialize problem in php

    - by Kurt
    hi i'm using serialize/unserialize functions in php 5.2. the text to be stored is POSTed via a form. btw, no white-space before or after. if text contains " or ' it serializes successfully. the problem is it does not unserialize back. what i'm doing wrong?

    Read the article

  • PHP unserialize fails with non-encoded characters?

    - by FFish
    $ser = 'a:2:{i:0;s:5:"héllö";i:1;s:5:"wörld";}'; // fails $ser2 = 'a:2:{i:0;s:5:"hello";i:1;s:5:"world";}'; // works $out = unserialize($ser); $out2 = unserialize($ser2); print_r($out); print_r($out2); echo "<hr>"; But why? Should I encode before serialzing than? How? I am using Javascript to write the serialized string to a hidden field, than PHP's $_POST In JS I have something like: function writeImgData() { var caption_arr = new Array(); $('.album img').each(function(index) { caption_arr.push($(this).attr('alt')); }); $("#hidden-field").attr("value", serializeArray(caption_arr)); };

    Read the article

  • Php using unserialize() and serialize() changing values in a saved file

    - by Doodle
    I have a serialized array of values saved to a file and need to change the value of one of the variables. In the example I change the value of $two and then save the whole array back into the file with the new value. Is there a more efficient way of altering just the single value with out having to read and write the entire file/array. $data = file_get_contents('./userInfo'); $data = unserialize($data); extract($data); $two="this is a altered value"; $userData = array( 'one' => $one, 'two' => $two, 'three' => $three ); $file=fopen("../userInfo",'w'); fwrite($file, $userData); fclose($file);

    Read the article

  • Why do I have to unserialize this serialized value twice?

    - by 55skidoo
    What am I doing wrong here? I'm serializing a value, storing it in a database (table bb_meta), retrieving it... OK so far... but then I have to unserialize it twice. Shouldn't I be able to just unserialize once? This seems to work, but I'm wondering what point about serialization I'm missing here. //check database to see if user has ever visited before. $querystring = $bbdb->prepare( "SELECT `meta_value` FROM `$bbdb->meta` WHERE `object_type` = %s AND `object_id` = %s AND `meta_key` = %s LIMIT 1", $bbtype, $bb_this_thread, $bbuser ); $bb_last_visits = $bbdb->get_row($querystring, OBJECT); //if $bb_last_visits is empty, add time() as the metavalue using bb_update_meta if (empty($bb_last_visits)) { $first_visit = time(); echo 'serialized first visit: ' . $bb_this_visit_time_serialized = serialize(array($bb_this_thread => $first_visit)); bb_update_meta( $bb_this_thread, $bbuser, $bb_this_visit_time_serialized, $bbtype ); //add to database, bb_meta table echo '$bb_last_visits was empty. Setting first visit time as ' . $bb_this_visit_time_serialized . '<br>'; } else { //else, test by unserializing the data for use. echo 'last visit time already set: '; echo $bb_last_visits->meta_value; echo '<br>'; //fatal error - echo 'unserialized: ' . $bb_last_visits_unserialized = unserialize($bb_last_visits[0]->meta_value); echo '<br>'; echo 'unserialize: ' . $unserialized_visits = unserialize($bb_last_visits->meta_value); echo '<br>'; echo 'hmm, need to unserialize again??: '; echo $unserialized_unserialized_visits = unserialize($unserialized_visits); echo '<br>'; echo 'hey look, it\'s an array value I can finally use now. phew: ' . $unserialized_unserialized_visits[$bb_this_thread]; }

    Read the article

  • Why do I have to unserialize this serialized value twice? (wordpress/bbpress maybe_serialize)

    - by 55skidoo
    What am I doing wrong here? I'm serializing a value, storing it in a database (table bb_meta), retrieving it... OK so far... but then I have to unserialize it twice. Shouldn't I be able to just unserialize once? This seems to work, but I'm wondering what point about serialization I'm missing here. //check database to see if user has ever visited before. $querystring = $bbdb->prepare( "SELECT `meta_value` FROM `$bbdb->meta` WHERE `object_type` = %s AND `object_id` = %s AND `meta_key` = %s LIMIT 1", $bbtype, $bb_this_thread, $bbuser ); $bb_last_visits = $bbdb->get_row($querystring, OBJECT); //if $bb_last_visits is empty, add time() as the metavalue using bb_update_meta if (empty($bb_last_visits)) { $first_visit = time(); echo 'serialized first visit: ' . $bb_this_visit_time_serialized = serialize(array($bb_this_thread => $first_visit)); bb_update_meta( $bb_this_thread, $bbuser, $bb_this_visit_time_serialized, $bbtype ); //add to database, bb_meta table echo '$bb_last_visits was empty. Setting first visit time as ' . $bb_this_visit_time_serialized . '<br>'; } else { //else, test by unserializing the data for use. echo 'last visit time already set: '; echo $bb_last_visits->meta_value; echo '<br>'; //fatal error - echo 'unserialized: ' . $bb_last_visits_unserialized = unserialize($bb_last_visits[0]->meta_value); echo '<br>'; echo 'unserialize: ' . $unserialized_visits = unserialize($bb_last_visits->meta_value); echo '<br>'; echo 'hmm, need to unserialize again??: '; echo $unserialized_unserialized_visits = unserialize($unserialized_visits); echo '<br>'; echo 'hey look, it\'s an array value I can finally use now. phew: ' . $unserialized_unserialized_visits[$bb_this_thread]; }

    Read the article

  • Unserialize data and check it against an id in MySQL

    - by kylex
    I have a row of IDs in a database that has been serialized. What I'm trying to do is check those serialized IDs against a known ID to see if it should be excluded or not. for example: "SELECT * FROM mydb WHERE id = 4 AND checkID != 'an id in the serialized column' " What's the best way to go about this?

    Read the article

  • Symfony/Doctrine: Unserialize in action vs template

    - by Tom
    Hi, Can anyone tell me why calling "unserialize" works fine in an action but gives an offset error in a template? It's basically possible to unserialize a database text result into a variable in an action and pass it to template, in which case it displays fine: $this->clean = unserialize($this->raw); <?php echo $clean ?> But not if called directly in a template: <?php echo unserialize($raw) ?> Would be interested in knowing why this is so and whether there's some workaround. Thanks.

    Read the article

  • Zend_Session: unserialize session data

    - by takeshin
    I'm using session SaveHandler to persist session data in the database. Sample session_data column from the database: Messenger|a:1:{s:13:"page_messages";a:0:{}}userSession|a:1:{s:7:"referer";s:32:"http://cms.dev/user/profile/view";}Zend_Auth|a:1:{s:7:"storage";O:19:"User_Model_Identity":3:{s:2:"id";s:1:"1";s:8:"username";s:13:"administrator";s:4:"slug";s:13:"administrator";}} I want to delete Zend_Auth object from this session data. How can I unserialize those objects and remove object I need? I suspect, that I don't have to write my custom parser, that Zend_Session already has a method to do this. I have tried different combinations of unserialize but it still returns false. I'm using autoloader from ZF 1.10.2 and Doctrine 1.2

    Read the article

  • Rails: How do I unserialize from database?

    - by Macint
    Hello, I am currently trying to save information for an invoice/bill. On the invoice I want to show what the total price is made up of. The procedures & items, their price and the qty. So in the end I hope to get it to look like this: Consult [date] [total_price] Procedure_name [price] [qty] Procedure_name [price] [qty] Consult [date] [total_price] Procedure_name [price] [qty] etc... All this information is available through the database but i want to save the information as a separate copy. That way if the user changes the price of some procedures the invoice information is still correct. I thought i'd do this by serializing and save the data to a column (consult_data) in the Invoice table. My Model: class Invoice < ActiveRecord::Base ...stuff... serialize :consult_data ... end This is what I get from the form (1 consult and 3 procedures): {"commit"=>"Save draft", "authenticity_token"=>"MZ1OiOCtj/BOu73eVVkolZBWoN8Fy1skHqKgih7Sbzw=", "id"=>"113", "consults"=>[{"consult_date"=>"2010-02-20", "consult_problem"=>"ABC", "procedures"=>[{"name"=>"asdasdasd", "price"=>"2.0", "qty"=>"1"}, {"name"=>"AAAnd another one", "price"=>"45.0", "qty"=>"4"}, {"name"=>"asdasdasd", "price"=>"2.0", "qty"=>"1"}], "consult_id"=>"1"}]} My save action: def add_to_invoice @invoice = @current_practice.invoices.find_by_id(params[:id]) @invoice.consult_data=params[:consults] if @invoice.save render :text => "I think it worked" else render :text => "I don't think it worked'" end end It does save to the database and if I look at the entry in the console I can see that it is all there: consult_data: "--- \n- !map:HashWithIndifferentAccess \n consult_da..." (---The question---) But I can't seam to get back my data. I tried defining a variable to the consult_data attribute and then doing "variable.consult_problem" or "variable[:consult_problem]" (also tried looping) but it only throws no-method-errors back at me. How do I unserialize the data from the database and turn it back into hash that i can use? Thank you very much for any help!

    Read the article

  • [Python] How can I speed up unpickling large objects if I have plenty of RAM?

    - by conradlee
    It's taking me up to an hour to read a 1-gigabyte NetworkX graph data structure using cPickle (its 1-GB when stored on disk as a binary pickle file). Note that the file quickly loads into memory. In other words, if I run: import cPickle as pickle f = open("bigNetworkXGraph.pickle","rb") binary_data = f.read() # This part doesn't take long graph = pickle.loads(binary_data) # This takes ages How can I speed this last operation up? Note that I have tried pickling the data both in using both binary protocols (1 and 2), and it doesn't seem to make much difference which protocol I use. Also note that although I am using the "loads" (meaning "load string") function above, it is loading binary data, not ascii-data. I have 128gb of RAM on the system I'm using, so I'm hoping that somebody will tell me how to increase some read buffer buried in the pickle implementation.

    Read the article

  • Serialize checkbox array, also get checkboxes with off-value

    - by guzh
    Hi, I was wondering if this is possible. The serialize-string will be inserted in a mySQL-database, so it would be fine if all checkboxes would be inserted and not only the ones that is ticked(on). it's possible to make on column in the database for each of the checkboxes, and use this if/else-statement: if(isset($_GET['checkbox'])) { // It's checked! } else { // not checked! } but its a bit unappropriate...

    Read the article

  • Does PHP *have* to serialize/unserialize session data between each HTTP request? Or is there a sett

    - by Pete Alvin
    I think I understand why sessions are evil but for snappy client user experience I don't want to have to re-query the database on each HTTP request. (As a comparision, Java servlets can effortlessly keep tons of session objects in memory.) Can PHP be set to do this or does it have to serialize because it runs from CGI/FastCGI and therefore by definition is a new process each time a request comes in? I will be running PHP using LAMP.

    Read the article

  • How to serialize and unserialize to/from a C# class?

    - by Earlz
    Hello, I have an object in Javascript that looks like this function MyObject(){ this.name=""; this.id=0; this..... } I then stringify an array of those objects and send it to an ASP.Net web service. Now what I want to do is do some processing on the JSON objects given to the webservice and return a JSON array of the same type of objects(same field names and such) How would I do this easily? I am using Netwonsoft.Json. Is there some way to turn a JSON string into a List or Array of an object?

    Read the article

  • about post data

    - by Garnono
    hi,everyone.my question like this: post.php <?php $str = "testmytest"; $str_serialize = serialize($str); http_post_fields("get_post.php", array('str' => $str_serialize)); ?> get_post.php <?php if (isset($_POST['str'])) { $echo $_POST['str']; $str = unserialize($_POST['str']); echo $str; } ?> i can not unserialize the $str, it is changed.who knows why? Thanks for everybody.

    Read the article

  • Error appearing in application after updating cakePHP library files from 1.3.0 to 1.3.1

    - by Gaurav Sharma
    Hi everyone, I have just updated my cakephp library to latest version 1.3.1. Before this I was running v1.3.0 with no errors. After running the application I am given this error message. unserialize() [function.unserialize]: Error at offset 0 of 2574 bytes [CORE\cake\libs\cache\file.php, line 176] I updated the libraries simply by replacing the existing cake files with the new ones downloaded from the net. Is it the correct way of updating applications. I did'nt made any customizations to the core library of cakePHP. What is the problem ? Please help. Thanks

    Read the article

  • PHP Serialization Will not work correctly.

    - by stevoo
    Hi, I am developing and doing all the testing on a local machine using PHP Version 5.3.3-1ubuntu9.1 version. The host machine is PHP Version 5.2.15. All the seriliaze arguments are identical. The problems is when i try to login the user on my test local machine i do the following : $user->getByUserId($results['id'],$db); $_SESSION['user'] = serialize($user); which retrieved me and serialize the user. and i just load it back when ever i detect that a session exists $user->LoadFromObject(unserialize($_SESSION['user'])); This works perfectly on my test machine. Just transfered the files on the host to see if i can get a beta version out but i keep on getting Warning: unserialize() expects parameter 1 to be string, object given in /home/gamerent/public_html/beta/includes/header.php on line 19 i have noticed that if i echo the $_SESSION['user'] in both system the test will indeed display me the serializated one but the main one will just show me the object and will not serialize the $user

    Read the article

  • Remove accents from a JSON response using the raw content.

    - by Pentium10
    This is a follow up of this question: Remove accents from a JSON response. The accepted answer there works for a single item/string of a raw JSON content. But I would like to run a full transformation over the entire raw content of the JSON without parsing each object/array/item. What I've tried is this function removeAccents($jsoncontent) { $obj=json_decode($jsoncontent); // use decode to transform the unicode chars to utf $content=serialize($obj); // serialize into string, so the whole obj structure can be used string as a whole $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿRr'; $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr'; $content=utf8_decode($content); $jsoncontent = strtr($content, $a, $b); // at this point the accents are removed, and everything is good echo $jsoncontent; $obj=unserialize($jsoncontent); // this unserialization is returning false, probably because we messed up with the serialized string return json_encode($obj); } As you see after I decoded JSON content, I serialized the object to have a string of it, than I remove the accents from that string, but this way I have problem building back the object, as the unserialize stuff returns false. How can I fix this?

    Read the article

  • (HARD)Remove accents from a JSON response using the raw content

    - by Pentium10
    This is a follow up of this question: Remove accents from a JSON response. The accepted answer there works for a single item/string of a raw JSON content. But I would like to run a full transformation over the entire raw content of the JSON without parsing each object/array/item. What I've tried is this function removeAccents($jsoncontent) { $obj=json_decode($jsoncontent); // use decode to transform the unicode chars to utf $content=serialize($obj); // serialize into string, so the whole obj structure can be used string as a whole $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿRr'; $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr'; $content=utf8_decode($content); $jsoncontent = strtr($content, $a, $b); // at this point the accents are removed, and everything is good echo $jsoncontent; $obj=unserialize($jsoncontent); // this unserialization is returning false, probably because we messed up with the serialized string return json_encode($obj); } As you see after I decoded JSON content, I serialized the object to have a string of it, than I remove the accents from that string, but this way I have problem building back the object, as the unserialize stuff returns false. How can I fix this?

    Read the article

  • Caching page by parts; how to pass variables calculated in cached parts into never-cached parts?

    - by Kirzilla
    Hello, Let's imagine that I have a code like this... if (!$data = $cache->load("part1_cache_id")) { $item_id = $model->getItemId(); ob_start(); echo 'Here is the cached item id: '.$item_id; $data = ob_get_contents(); ob_end_clean(); $cache->save($data, "part1_cache_id"); } echo $data; echo never_cache_function($item_id); if (!$data_2 = $cache->load("part2_cache_id")) { ob_start(); echo 'Here is the another cached part of the page...'; $data_2 = ob_get_contents(); ob_end_clean(); $cache->save("part2_cache_id"); } echo $data_2; As far as you can see I need to pass $item_id variable into never_cache_function, but if fist part is cached (part1_cache_id) then I have no way to get $item_id value. I see the only solution - serialize all data from fist part (including $item_id value); then cache serialized string and unserialize it everytime when script is executed... Something like this... if (!$data = $cache->load("part1_cache_id")) { $item_id = $model->getItemId(); $data['item_id'] = $item_id; ob_start(); echo 'Here is the cached item id: '.$item_id; $data['html'] = ob_get_contents(); ob_end_clean(); $cache->save( serialize($data), "part1_cache_id" ); } $data = unserialize($data); echo $data['html'] echo never_cache_function($data['item_id']); Is there any other ways for doing such trick? I'm looking for the most high performance solution. Thank you UPDATED And another question is - how to implement such caching into controller without separating page into two templates? Is it possible? PS: Please, do not suggest Smarty, I'm really interested in implementing custom caching.

    Read the article

  • How to properly implement the Strategy pattern in a web MVC framework?

    - by jboxer
    In my Django app, I have a model (lets call it Foo) with a field called "type". I'd like to use Foo.type to indicate what type the specific instance of Foo is (possible choices are "Number", "Date", "Single Line of Text", "Multiple Lines of Text", and a few others). There are two things I'd like the "type" field to end up affecting; the way a value is converted from its normal type to text (for example, in "Date", it may be str(the_date.isoformat())), and the way a value is converted from text to the specified type (in "Date", it may be datetime.date.fromtimestamp(the_text)). To me, this seems like the Strategy pattern (I may be completely wrong, and feel free to correct me if I am). My question is, what's the proper way to code this in a web MVC framework? In a client-side app, I'd create a Type class with abstract methods "serialize()" and "unserialize()", override those methods in subclasses of Type (such as NumberType and DateType), and dynamically set the "type" field of a newly-instantiated Foo to the appropriate Type subclass at runtime. In a web framework, it's not quite as straightforward for me. Right now, the way that makes the most sense is to define Foo.type as a Small Integer field and define a limited set of choices (0 = "Number", 1 = "Date", 2 = "Single Line of Text", etc.) in the code. Then, when a Foo object is instantiated, use a Factory method to look at the value of the instance's "type" field and plug in the correct Type subclass (as described in the paragraph above). Foo would also have serialize() and unserialize() methods, which would delegate directly to the plugged-in Type subclass. How does this design sound? I've never run into this issue before, so I'd really like to know if other people have, and how they've solved it.

    Read the article

  • Unserializing an API return object (PHP/Ebay API)

    - by DavidYell
    I have been working with the Ebay api for a project and have found it great. I have however found a problem now, more PHP related. When I read my items from Ebay, I store a bunch of details in the database. Currently, just for the sake of it really, I serialize the whole return object and store it in the database in a related table. The idea being, that when I display my information, I have all the details to hand should I need them. The problem arises in that the pricing information is always in a sub object. [ConvertedAdjustmentAmount] => __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => eBayAmountType [_] => 0 [currencyID] => USD ) As you can see when I unserialize my object, my cunning plan falls foul of the Incomplete class problem. I have checked the following question, without success. http://stackoverflow.com/questions/965611/forcing-access-to-php-incomplete-class-object-properties The main issue lies, as far as I can see, in that the price class is stored in the Ebay api, so how do I recreate it? I have been reading this page, http://uk3.php.net/manual/en/function.unserialize.php and trying to figure out, unserialize_callback_func which I can't figure out either, so any help would be appreciated!

    Read the article

1 2 3  | Next Page >