Re: [PHP] serialize() casts numeric string keys to integers
On Mon, Nov 12, 2012 at 2:18 AM, eyal.t wrote: > Hi all, > > Was wondering whether the fact that serialize() casts numeric string keys > to integers, is a bug, intended behaviour, or just something that is minor > enough not to have bothered anyone yet? > This behavior is consistent with the standard key casts for arrays: http://php.net/manual/en/language.types.array.php Try dumping the array before the serialize operations. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
[PHP] serialize() casts numeric string keys to integers
Hi all, Was wondering whether the fact that serialize() casts numeric string keys to integers, is a bug, intended behaviour, or just something that is minor enough not to have bothered anyone yet? 'string key'); // '1' will be casted to 1 $arr2 = array(1=>'integer key'); $arr1_uns = unserialize(serialize($arr1)) ; $arr2_uns = unserialize(serialize($arr2)) ; var_dump($arr1_uns, $arr2_uns); == array(1) { [1]=> string(10) "string key" } array(1) { [1]=> string(11) "integer key" } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize an object
On 4/19/07, Stut <[EMAIL PROTECTED]> wrote: Tobias Wurst wrote: > i use serialize() to save my object in $_SESSION. Why? There's no point in serialising something into $_SESSION. Anything you put in there gets serialised by the session handler. That isn't necessarily 100% true. http://www.stubbles.org/archives/12-Lazy-loading-of-classes-stored-in-a-session-without-__autoload.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize an object
I'm wondering if the OP is failing to re-define the baseclass when loading in the saved object... But, yes, get rid of the by-hand serializing first, as PHP will serialize it for you. On Thu, April 19, 2007 7:40 am, Zoltán Németh wrote: > as far as I know serialize() saves all the properties of the object... > > and I think you can store objects in session without serializing it > since PHP serializes-unserializes it for you automatically - or not? > > greets > Zoltán Németh > > 2007. 04. 19, csütörtök keltezéssel 13.17-kor Tobias Wurst ezt > Ãrta: >> hi, >> i use serialize() to save my object in $_SESSION. >> But i have one Problem: >> the member-variables from the baseclass are not saved.. :( >> How can i fix this? >> >> thanks in advance >> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] serialize an object
Sorry for that ctrl+enter sends, when I wanted ctrl+V to paste :( All registered variables are serialized after the request finishes. Registered variables which are undefined are marked as being not defined. On subsequent accesses, these are not defined by the session module unless the user defines them later. Warning Some types of data can not be serialized thus stored in sessions. It includes resource variables or objects with circular references (i.e. objects which passes a reference to itself to another object). Note: Session handling was added in PHP 4.0.0. Note: Please note when working with sessions that a record of a session is not created until a variable has been registered using the session_register() function or by adding a new key to the $_SESSION superglobal array. This holds true regardless of if a session has been started using the session_start() function. So I'd assume his class has a circular reference if it cannot be serialized, and how to fix that I'm going to pass on. -Original Message- From: Zoltán Németh [mailto:[EMAIL PROTECTED] Sent: Thursday, April 19, 2007 8:40 AM To: Tobias Wurst Cc: php-general@lists.php.net Subject: Re: [PHP] serialize an object as far as I know serialize() saves all the properties of the object... and I think you can store objects in session without serializing it since PHP serializes-unserializes it for you automatically - or not? greets Zoltán Németh 2007. 04. 19, csütörtök keltezéssel 13.17-kor Tobias Wurst ezt írta: > hi, > i use serialize() to save my object in $_SESSION. > But i have one Problem: > the member-variables from the baseclass are not saved.. :( > How can i fix this? > > thanks in advance > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] serialize an object
>From the PHP manual: -Original Message- From: Zoltán Németh [mailto:[EMAIL PROTECTED] Sent: Thursday, April 19, 2007 8:40 AM To: Tobias Wurst Cc: php-general@lists.php.net Subject: Re: [PHP] serialize an object as far as I know serialize() saves all the properties of the object... and I think you can store objects in session without serializing it since PHP serializes-unserializes it for you automatically - or not? greets Zoltán Németh 2007. 04. 19, csütörtök keltezéssel 13.17-kor Tobias Wurst ezt írta: > hi, > i use serialize() to save my object in $_SESSION. > But i have one Problem: > the member-variables from the baseclass are not saved.. :( > How can i fix this? > > thanks in advance > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize an object
as far as I know serialize() saves all the properties of the object... and I think you can store objects in session without serializing it since PHP serializes-unserializes it for you automatically - or not? greets Zoltán Németh 2007. 04. 19, csütörtök keltezéssel 13.17-kor Tobias Wurst ezt írta: > hi, > i use serialize() to save my object in $_SESSION. > But i have one Problem: > the member-variables from the baseclass are not saved.. :( > How can i fix this? > > thanks in advance > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize an object
Tobias Wurst wrote: i use serialize() to save my object in $_SESSION. Why? There's no point in serialising something into $_SESSION. Anything you put in there gets serialised by the session handler. But i have one Problem: the member-variables from the baseclass are not saved.. :( How can i fix this? Pass. I know you can specify member variables to be saved in __sleep(), so I guess that would be one possible workaround. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize an object
hi, i use serialize() to save my object in $_SESSION. But i have one Problem: the member-variables from the baseclass are not saved.. :( How can i fix this? thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() and special ANSI characters
Just a guess: You could perhaps run all your data through base64 encoding or somesuch to be certain the characters to be serialized are all "nice" On Mon, February 19, 2007 8:56 am, Youri LACAN-BARTLEY wrote: > Hi all, > > I'm just curious to find out if I'm the only person to have bumped > into > this kind of issue with serialize/unserialize. > > When I try and serialize an array containing a string value with the > "±" > character (alt+241 ASCII) such as : > "120GB 2X512MB 15.4IN DVD±RW VHP FR" > > The resulting serialized array is truncated. > ie. I would obtain : > > "a:17:{i:0;s:1:"A";i:1;s:7:"TOSHIBA";i:2;s:4:"3740";i:3;s:7:"404D862";i:4;s:31:"SATELLITE > A100-044 CD/T2060-1.6";i:5;s:35:"120GB 2X512MB 15.4IN DVD" > > As you can see serialization seems to stall as soon as the "±" > character > shows up. > > Do any of you have the same issue? And what could be a work around for > this sort of problem. > > This has occurred on a Windows XP box running PHP 5.2.0. The string is > obtained from a CSV file using ANSI encoding. > > Thanks, > > Youri > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() and special ANSI characters
# [EMAIL PROTECTED] / 2007-02-19 17:29:53 +0100: > Roman Neuhauser wrote: > > > >class serializeASCII241 extends Tence_TestCase > >{ > >function testTruncates() > >{ > >return $this->assertEquals( > >"120GB 2X512MB 15.4IN DVD", > >serialize("120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR") > >); > >} > >} > > > >?> > > I'd just like to point out that your test will fail systematically > unless you use something like this : > > function testTruncates() > { > $string = "120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR"; > return $this->assertEquals( > "s:" . strlen($string) . ":\"120GB 2X512MB 15.4IN DVD", > serialize("120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR") > ); > } You're right, of course, I wrote that in a hurry, after I checked the output of serialize() contained the whole input. This is a better test, and it does work with the beforementioned configuration (5.2.1 on FreeBSD). raw = "120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR"; $this->serialized = sprintf( 's:%d:"%s";', strlen($this->raw), $this->raw ); } function testWorksAsExpected() { return $this->assertEquals( $this->serialized, serialize($this->raw) ); } } ?> -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() and special ANSI characters
Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-02-19 15:56:15 +0100: I'm just curious to find out if I'm the only person to have bumped into this kind of issue with serialize/unserialize. When I try and serialize an array containing a string value with the "?" character (alt+241 ASCII) such as : "120GB 2X512MB 15.4IN DVD?RW VHP FR" The resulting serialized array is truncated. ie. I would obtain : "a:17:{i:0;s:1:"A";i:1;s:7:"TOSHIBA";i:2;s:4:"3740";i:3;s:7:"404D862";i:4;s:31:"SATELLITE A100-044 CD/T2060-1.6";i:5;s:35:"120GB 2X512MB 15.4IN DVD" As you can see serialization seems to stall as soon as the "?" character shows up. I don't see the effect you're mentioning, but this is on FreeBSD, so perhaps there's a problem on Windows. I don't really believe it, though, and would hazard a guess you're running into display problems with your browser. Another thing to mention is that ASCII only goes up to 127. You may desire for ASCII 241 to mean +/-, but n-tilde is also a popular interpretation... Use a character set which actually includes +/- as a single character, and an encoding that can handle that charset. I'm probably just running into so encoding issues with the CSV files I'm using on which I have no control whatsoever. The following test fails in 5.2.1: assertEquals( "120GB 2X512MB 15.4IN DVD", serialize("120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR") ); } } ?> I'd just like to point out that your test will fail systematically unless you use something like this : function testTruncates() { $string = "120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR"; return $this->assertEquals( "s:" . strlen($string) . ":\"120GB 2X512MB 15.4IN DVD", serialize("120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR") ); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() and special ANSI characters
# [EMAIL PROTECTED] / 2007-02-19 15:56:15 +0100: > I'm just curious to find out if I'm the only person to have bumped into > this kind of issue with serialize/unserialize. > > When I try and serialize an array containing a string value with the "?" > character (alt+241 ASCII) such as : > "120GB 2X512MB 15.4IN DVD?RW VHP FR" > > The resulting serialized array is truncated. > ie. I would obtain : > > "a:17:{i:0;s:1:"A";i:1;s:7:"TOSHIBA";i:2;s:4:"3740";i:3;s:7:"404D862";i:4;s:31:"SATELLITE > > A100-044 CD/T2060-1.6";i:5;s:35:"120GB 2X512MB 15.4IN DVD" > > As you can see serialization seems to stall as soon as the "?" character > shows up. I don't see the effect you're mentioning, but this is on FreeBSD, so perhaps there's a problem on Windows. I don't really believe it, though, and would hazard a guess you're running into display problems with your browser. Another thing to mention is that ASCII only goes up to 127. You may desire for ASCII 241 to mean +/-, but n-tilde is also a popular interpretation... Use a character set which actually includes +/- as a single character, and an encoding that can handle that charset. The following test fails in 5.2.1: assertEquals( "120GB 2X512MB 15.4IN DVD", serialize("120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR") ); } } ?> -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize() and special ANSI characters
Hi all, I'm just curious to find out if I'm the only person to have bumped into this kind of issue with serialize/unserialize. When I try and serialize an array containing a string value with the "±" character (alt+241 ASCII) such as : "120GB 2X512MB 15.4IN DVD±RW VHP FR" The resulting serialized array is truncated. ie. I would obtain : "a:17:{i:0;s:1:"A";i:1;s:7:"TOSHIBA";i:2;s:4:"3740";i:3;s:7:"404D862";i:4;s:31:"SATELLITE A100-044 CD/T2060-1.6";i:5;s:35:"120GB 2X512MB 15.4IN DVD" As you can see serialization seems to stall as soon as the "±" character shows up. Do any of you have the same issue? And what could be a work around for this sort of problem. This has occurred on a Windows XP box running PHP 5.2.0. The string is obtained from a CSV file using ANSI encoding. Thanks, Youri -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Serialize
On Wed, May 24, 2006 4:50 am, [EMAIL PROTECTED] wrote: > Is a serialized array a "safe" string to insert into a mysql text > field? Or is a > function such as mysql_real_escape_string always needed? Assume that a Bad Guy is smart enough to get SOMETHING in there to mess you up, even if you serialize it. Thus, you need to escape it. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Serialize
At 10:50 AM +0100 5/24/06, [EMAIL PROTECTED] wrote: Hi, Is a serialized array a "safe" string to insert into a mysql text field? Or is a function such as mysql_real_escape_string always needed? regards Simon. Simon: If you want to store a serialized array in mysql, then you must use mysql_real_escape_string to cover the possibility that your array values may have quotes and other such stuff that a mysql query would stumble on. Also, the following is what I discovered from my own investigation. Please note that normally when you place data into mysql using mysql_real_escape_string -- you also use htmlentities to pull it out -- if -- your going to show it to a browser. But, if you do that, then you can't subsequently also unserialized the string into an array. You must unserialized the array directly from mysql and not after htmlentities. It's interesting that an inspection of a "serialized array string" before and after htmlentities may "look" the same, but they aren't. hth's tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Serialize
On 24/05/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Hi, Is a serialized array a "safe" string to insert into a mysql text field? Or is a function such as mysql_real_escape_string always needed? No, it's not at all a safe string to insert into a mysql text field. mysql_real_escap_string() is needed. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Serialize
It's not safe... if the array contains strings which contain ' or " might screw your query... it's safe to escape the string result from serialize... Andy [EMAIL PROTECTED] wrote: Hi, Is a serialized array a "safe" string to insert into a mysql text field? Or is a function such as mysql_real_escape_string always needed? regards Simon. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Serialize
On 5/24/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Hi, Is a serialized array a "safe" string to insert into a mysql text field? Or is a function such as mysql_real_escape_string always needed? *Always* escape your data. What if your array contains a quote? -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Serialize
Hi, Is a serialized array a "safe" string to insert into a mysql text field? Or is a function such as mysql_real_escape_string always needed? regards Simon. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
tedd wrote: Jochem: $_SESSION has another advantage - everything you stick in it is automagically serialized and unserialized at end/start of the request. I didn't know that. Thanks, now I have to figure out a way to store a $_SESSION in a cookie and read it back without inferring with what the user is currently doing in both post and get selections. I have myself overly confused at the moment with too much user activity. no shit! (regarding the confusion). $_SESSION is populated when you call session_start(), it's contents are stored on the server. calling session_start() implicitly make php emit a cookie which contains not much other than the session id - it's this id (that the browser sends back in the form of a cookie again) that tell's php which chunk of serialized data that it saved onto disk (usually onto disk) at the end a previous request it should load up when you call session_start(). by default the session cookie is 'dropped' by the browser once you close it [the browser] try this, it might to help you see what's happening a bit (oh and don't forget the manual ;-): "; $_SESSION['myObj'] = new stdObject; $_SESSION['myObj']->counter = 1; } echo $_SESSION['myObj']->counter++; tedd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
Jochem: $_SESSION has another advantage - everything you stick in it is automagically serialized and unserialized at end/start of the request. I didn't know that. Thanks, now I have to figure out a way to store a $_SESSION in a cookie and read it back without inferring with what the user is currently doing in both post and get selections. I have myself overly confused at the moment with too much user activity. tedd -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
There's nothing special about the data returned by serialize() except that it can be safely written saved, transmitted, etc. To do anything useful with it you have to unserialize() it. The cool part about it is that you can serialize any data structure, like an entire array or object. The Yahoo Developer center (ever friendly to PHP developers) talks about how their APIs can return serialized data for PHP: http://developer.yahoo.com/common/phpserial.html For example, use can use the Yahoo Search API to search for "Seinfeld", unserialize the results, and have a beautiful array to use: print_r(unserialize(file_get_contents("http://api.search.yahoo.com/ WebSearchService/V1/webSearch? appid=YahooDemo&query=Seinfeld&results=3&output=php"))); (It's almost like making SOAP out of a REST call.) Richard On Apr 13, 2006, at 3:53 PM, Nicholas Couloute wrote: Are there any tutorials and uses for serialize() ? I went to php.net and it isn't well documented as I would hope! ~Nick Couloute co-owner/Web Designer Sidekick2Music.Com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
On Thu, April 13, 2006 7:03 pm, Jochem Maas wrote: >> One example, each domain has a limit of cookies (20) and you can use > > I wasn't aware that there was a hard limit on cookies - I always > thought > this was a browser dependent setting ... not that I ever get above > 2 cookies max (and mostly just 1 for the session cookie). Not only are browsers free to ignore more than X cookies they are also allowed to purge anything more than Y bytes in the cookies from any given domain. [nb] You really should read the original Netscape Cookie spec -- it's short and clear and concise, and possibly one of the best-written specs out there, in some ways. [/nb] So I would never recommend serializing a bunch of data to get it all into one cookie. imho. Better to give the browser ONE cookie and use that to track everything else on the server in a session. This also matters for bandwidth -- It would do Google no good at all to trim down their homepage to the Nth degree like they do, if they sent an extra 100K of coookie data back and forth all the time. Remember: Whatever you SEND in the Cookie, the browser has to send BACK on every page hit, every image hit, the CSS, the javascript requests, all of them, to the same domain. Serialized data is seldom "small" so even a handful of datastructures being sent back by the browser on every request could add up quickly. The user has to wait for that data to get to your server, after all, before they can even BEGIN to get your content back. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
Robert Cummings wrote: On Thu, 2006-04-13 at 18:58, tedd wrote: Not that you don't know -- because I'm sure you do -- but for the benefit of others. One example, each domain has a limit of cookies (20) and you can use them up pretty quickly. However, if you place your data in an array, you could then serialize the array and save it as one long string (i.e., the cookie). Then you can read it back from the cookie and un-serialize it back to the array. Except for extremely rare cases you should never need more than 2 cookies for a domain. Rather than saving every data field into a cookie, save a single unique ID into the user's cookie, and use that to look into your database. Now you can store zillions of fields and any size you want. So that's one, what's the other? Well you can do a persistent cookie also so that you can remember them when they return :) If you're going to store data on the the clients computer, you're going to have to security check every piece of data you saved there before every use. At least when the data is only linked by a unique key, you only ever have to validate the unique key. amen. Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
On Thu, 2006-04-13 at 18:58, tedd wrote: > Not that you don't know -- because I'm sure you do -- but for the > benefit of others. > > One example, each domain has a limit of cookies (20) and you can use > them up pretty quickly. However, if you place your data in an array, > you could then serialize the array and save it as one long string > (i.e., the cookie). Then you can read it back from the cookie and > un-serialize it back to the array. Except for extremely rare cases you should never need more than 2 cookies for a domain. Rather than saving every data field into a cookie, save a single unique ID into the user's cookie, and use that to look into your database. Now you can store zillions of fields and any size you want. So that's one, what's the other? Well you can do a persistent cookie also so that you can remember them when they return :) If you're going to store data on the the clients computer, you're going to have to security check every piece of data you saved there before every use. At least when the data is only linked by a unique key, you only ever have to validate the unique key. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
tedd wrote: At 12:04 AM +0200 4/14/06, Jochem Maas wrote: Nicholas Couloute wrote: Are there any tutorials and uses for serialize() ? I went to php.net and it isn't well documented as I would hope! $o,"B"=>$a,"C"=>$i,"D"=>$b)),"\n", ?> ... and yes there are uses for it. what do you want to do? Jochem: Not that you don't know -- because I'm sure you do -- but for the benefit of others. I don't know jack - just ask Jasper ;-) One example, each domain has a limit of cookies (20) and you can use I wasn't aware that there was a hard limit on cookies - I always thought this was a browser dependent setting ... not that I ever get above 2 cookies max (and mostly just 1 for the session cookie). them up pretty quickly. However, if you place your data in an array, you could then serialize the array and save it as one long string (i.e., the cookie). Then you can read it back from the cookie and un-serialize it back to the array. I'd don't tend to do anything with cookies other than the session cookie and keep any data in $_SESSION - saves having to cleanse whatever incoming stuff is in the cookie (storing data on the clientside that is serialized is can of worms waiting to happen - not that you can't code it safely per se, it's just that much more to think about) $_SESSION has another advantage - everything you stick in it is automagically serialized and unserialized at end/start of the request. tedd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
At 12:04 AM +0200 4/14/06, Jochem Maas wrote: Nicholas Couloute wrote: Are there any tutorials and uses for serialize() ? I went to php.net and it isn't well documented as I would hope! $o,"B"=>$a,"C"=>$i,"D"=>$b)),"\n", ?> ... and yes there are uses for it. what do you want to do? Jochem: Not that you don't know -- because I'm sure you do -- but for the benefit of others. One example, each domain has a limit of cookies (20) and you can use them up pretty quickly. However, if you place your data in an array, you could then serialize the array and save it as one long string (i.e., the cookie). Then you can read it back from the cookie and un-serialize it back to the array. tedd -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
Nicholas Couloute wrote: I was thinking of a news system with comments. fine. but what's that got to do with serialize() per se? or put another don't look at a function decide it might be useful and then force yourself to build an application with it cart before the horse and all that. On Thu, 13 Apr 2006 6:04 pm, Jochem Maas wrote: Nicholas Couloute wrote: Are there any tutorials and uses for serialize() ? I went to php.net and it isn't well documented as I would hope! $o,"B"=>$a,"C"=>$i,"D"=>$b)),"\n", ?> ... and yes there are uses for it. what do you want to do? ~Nick Couloute co-owner/Web Designer Sidekick2Music.Com ~Nick Couloute co-owner/Web Designer Sidekick2Music.Com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize() function
Nicholas Couloute wrote: Are there any tutorials and uses for serialize() ? I went to php.net and it isn't well documented as I would hope! $o,"B"=>$a,"C"=>$i,"D"=>$b)),"\n", ?> ... and yes there are uses for it. what do you want to do? ~Nick Couloute co-owner/Web Designer Sidekick2Music.Com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize() function
Are there any tutorials and uses for serialize() ? I went to php.net and it isn't well documented as I would hope! ~Nick Couloute co-owner/Web Designer Sidekick2Music.Com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] serialize
> Sent this to [EMAIL PROTECTED] but forgot to copy php-general... > heh. Here it is again. > > I would use a table such as > Table > |_UserData > > Then use objects per user to store the data. > class User { > var TestScore; > var ScoreType; > ... > var Vars; > function __construct($TestScore, $ScoreType) { > $this->TestScore = $TestScore; > $this->ScoreType = $ScoreType; > } > function __sleep() { > $this->Vars = get_object_variables($this); > } > ... > function ListVars() { > $MyString = ""; > ForEach($this->Vars as $key => $value) { > $MyString .= "${key}: ${value}\n"; > } > Return $MyString; > } > } > $Joe = new User("WhateverScore", "WhateverType"); > $sJoe = Serialize($Joe); > ...Store it... > > > ...Recall it... > (Variable result = recieved serialized version of $Joe) > $Joe = unserialize($Result); > $Results = $Joe->ListVars(); Hi Jake, I guess this comes down to preference, but I personally simply couldn't bring myself to store serialized objects in a table in the way you're describing. A well-designed database should not only be normalized, but should also be agnostic of the technology being used to access it. I don't know enough about whether or not serialize() is a widely implemented language construct, but I have worked on enough projects where someone in management has said, "Hey, I know you've done all this work in PHP (or insert language here), but we've decided we want to rework it in (insert other language which someone read a glowing article about on some website)" to shudder at the thought of storing data in a database that perhaps only one language can access. It also implies more coding to perform relatively simple recordset operations such as "give me the average of 'score12' across all things being scored", etc. Lastly, it locks your DBA (assuming you have one) out of being able to perform granular updates should the need arise. It's for pretty much the same reason that I hide under my desk, whimpering, when someone inevitably suggests storing XML recordsets as XML documents in database fields. So, full marks for fully exploiting the potential of objects, but you'll have to excuse me while I go make a coffee and maybe go for a brisk walk to get over the case of heebie-jeebies this suggestion gave me. ;-) Much warmth, Murray --- "Lost in thought..." http://www.planetthoughtful.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize
Sent this to [EMAIL PROTECTED] but forgot to copy php-general... heh. Here it is again. I would use a table such as Table |_UserData Then use objects per user to store the data. class User { var TestScore; var ScoreType; ... var Vars; function __construct($TestScore, $ScoreType) { $this->TestScore = $TestScore; $this->ScoreType = $ScoreType; } function __sleep() { $this->Vars = get_object_variables($this); } ... function ListVars() { $MyString = ""; ForEach($this->Vars as $key => $value) { $MyString .= "${key}: ${value}\n"; } Return $MyString; } } $Joe = new User("WhateverScore", "WhateverType"); $sJoe = Serialize($Joe); ...Store it... ...Recall it... (Variable result = recieved serialized version of $Joe) $Joe = unserialize($Result); $Results = $Joe->ListVars(); etc. On 9/26/05, Jake Gardner <[EMAIL PROTECTED]> wrote: > I would use a table such as > Table > |_UserData > > Then use objects per user to store the data. > class User { > var TestScore; > var ScoreType; > ... > var Vars; > function __construct($TestScore, $ScoreType) { > $this->TestScore = $TestScore; > $this->ScoreType = $ScoreType; > } > function __sleep() { > $this->Vars = get_object_variables($this); > } > ... > function ListVars() { > $MyString = ""; > ForEach($this->Vars as $key => $value) { > $MyString .= "${key}: ${value}\n"; > } > Return $MyString; > } > } > $Joe = new User("WhateverScore", "WhateverType"); > $sJoe = Serialize($Joe); > ...Store it... > > > ...Recall it... > (Variable result = recieved serialized version of $Joe) > $Joe = unserialize($Result); > $Results = $Joe->ListVars(); > > etc. > > On 9/26/05, bruce <[EMAIL PROTECTED]> wrote: > > murray... > > > > it may have been helpful to the guy to also give him an idea of your tbl > > structure. i think you're talking about something like: > > tbl schema > > > > EvalTBL > > -id > > -UserID > > -ScoreTypeID > > > > ScoreTBL > > -id > > -ScoreType > > > > table ScoreType could/would have as many different categorites as required. > > table EvalType would have a scoreTypeID (from the ScoreTBL) for each userID. > > each user could have multiple scoreTypes in the EvalTBL... > > > > -bruce > > > > > > -Original Message- > > From: Murray @ PlanetThoughtful [mailto:[EMAIL PROTECTED] > > Sent: Saturday, September 24, 2005 11:49 PM > > To: 'blackwater dev'; php-general@lists.php.net > > Subject: RE: [PHP] serialize > > > > > > > I have an app that stores evaluation scores so I have 30+ values all > > > within a certain range, currently in the db, each of these values has > > > it's own column: > > > > > > Table test > > >id > > >user_id > > >motivation > > >caring > > >personal_characteristics > > >creativity, > > >...etc. > > > > > > If the client decides they want to trap more characteristics, it > > > requires changes to the table structure and the table quickly gets > > > large with 30+ columns. I was thinking of just compacting all of > > > these down to one column and then using serialize/unserialize and > > > storing an array of the test scoresis this the best way?? > > > > Hi, > > > > This has less to do with PHP (though it will impact on your code) and more > > to do with database design principles. > > > > From what you describe, you have a denormalized table. Ie, every score value > > has its own field for each thing being scored: > > > > Id, score1, score2, score3, score4..., score30 > > > > , 23, 18, 12, 36, 38 > > 1112, 45, 12, 62, 25, 73 > > > > A more normalized representation of that table would be: > > > > Id, scoretype, score > > > > , 'score1', 23 > > , 'score2', 18 > > , 'score3', 12 > > , 'score4', 36 > > > > , 'score30', 38 > > 1112, 'score1', 45 > > 1112, 'score2', 12 > > 1112, 'score3', 62 > > 1112, 'score4'
RE: [PHP] serialize
> murray... > > it may have been helpful to the guy to also give him an idea of your tbl > structure. i think you're talking about something like: > tbl schema > > EvalTBL >-id >-UserID >-ScoreTypeID > > ScoreTBL >-id >-ScoreType > > table ScoreType could/would have as many different categorites as > required. > table EvalType would have a scoreTypeID (from the ScoreTBL) for each > userID. > each user could have multiple scoreTypes in the EvalTBL... Hi bruce, That would have been an even more normalized representation of the table(s), yes. For the purposes of demonstrating a state of normalization that still allowed the OP to maintain a single table, my structure in that post was: Scores -ScoredThingID -scoretype -score I would personally have implemented a structure similar to the one you outlined, but posted with the idea of "first things first". That's why I included a link to a tutorial on normalization and suggested Googling on the topic as well, for further reading. Still and all, it's helpful of you to clarify. Much warmth, Murray --- "Lost in thought..." http://www.planetthoughtful.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] serialize
murray... it may have been helpful to the guy to also give him an idea of your tbl structure. i think you're talking about something like: tbl schema EvalTBL -id -UserID -ScoreTypeID ScoreTBL -id -ScoreType table ScoreType could/would have as many different categorites as required. table EvalType would have a scoreTypeID (from the ScoreTBL) for each userID. each user could have multiple scoreTypes in the EvalTBL... -bruce -Original Message- From: Murray @ PlanetThoughtful [mailto:[EMAIL PROTECTED] Sent: Saturday, September 24, 2005 11:49 PM To: 'blackwater dev'; php-general@lists.php.net Subject: RE: [PHP] serialize > I have an app that stores evaluation scores so I have 30+ values all > within a certain range, currently in the db, each of these values has > it's own column: > > Table test >id >user_id >motivation >caring >personal_characteristics >creativity, >...etc. > > If the client decides they want to trap more characteristics, it > requires changes to the table structure and the table quickly gets > large with 30+ columns. I was thinking of just compacting all of > these down to one column and then using serialize/unserialize and > storing an array of the test scoresis this the best way?? Hi, This has less to do with PHP (though it will impact on your code) and more to do with database design principles. >From what you describe, you have a denormalized table. Ie, every score value has its own field for each thing being scored: Id, score1, score2, score3, score4..., score30 , 23, 18, 12, 36, 38 1112, 45, 12, 62, 25, 73 A more normalized representation of that table would be: Id, scoretype, score , 'score1', 23 , 'score2', 18 , 'score3', 12 , 'score4', 36 , 'score30', 38 1112, 'score1', 45 1112, 'score2', 12 1112, 'score3', 62 1112, 'score4', 25 1112, 'score30', 73 Adding a new score type for each id is then as simple as inserting rows for the ids with a new 'scoretype' value, meaning that no change of the actual table structure is required. To retrieve the scores for any given id in your PHP code, you'd do something like: $sql = "SELECT scoretype, score FROM scores WHERE id="; $rs = mysql_query($sql); while ($row = mysql_fetch_object($rs)){ $scores[$row->scoretype] = $row->score; } mysql_free_result($rs); print_r($scores); It might be helpful to you to Google on the topic of database normalization. Here's a link from the MySQL site that gives a brief introduction to the topic. http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html Hope this helps. Much warmth, Murray --- "Lost in thought..." http://www.planetthoughtful.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] serialize
> I have an app that stores evaluation scores so I have 30+ values all > within a certain range, currently in the db, each of these values has > it's own column: > > Table test >id >user_id >motivation >caring >personal_characteristics >creativity, >...etc. > > If the client decides they want to trap more characteristics, it > requires changes to the table structure and the table quickly gets > large with 30+ columns. I was thinking of just compacting all of > these down to one column and then using serialize/unserialize and > storing an array of the test scoresis this the best way?? Hi, This has less to do with PHP (though it will impact on your code) and more to do with database design principles. >From what you describe, you have a denormalized table. Ie, every score value has its own field for each thing being scored: Id, score1, score2, score3, score4..., score30 , 23, 18, 12, 36, 38 1112, 45, 12, 62, 25, 73 A more normalized representation of that table would be: Id, scoretype, score , 'score1', 23 , 'score2', 18 , 'score3', 12 , 'score4', 36 , 'score30', 38 1112, 'score1', 45 1112, 'score2', 12 1112, 'score3', 62 1112, 'score4', 25 1112, 'score30', 73 Adding a new score type for each id is then as simple as inserting rows for the ids with a new 'scoretype' value, meaning that no change of the actual table structure is required. To retrieve the scores for any given id in your PHP code, you'd do something like: $sql = "SELECT scoretype, score FROM scores WHERE id="; $rs = mysql_query($sql); while ($row = mysql_fetch_object($rs)){ $scores[$row->scoretype] = $row->score; } mysql_free_result($rs); print_r($scores); It might be helpful to you to Google on the topic of database normalization. Here's a link from the MySQL site that gives a brief introduction to the topic. http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html Hope this helps. Much warmth, Murray --- "Lost in thought..." http://www.planetthoughtful.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize
- Original Message - From: "blackwater dev" <[EMAIL PROTECTED]> To: Sent: Sunday, September 25, 2005 4:17 AM Subject: [PHP] serialize I have an app that stores evaluation scores so I have 30+ values all within a certain range, currently in the db, each of these values has it's own column: Table test id user_id motivation caring personal_characteristics creativity, ...etc. If the client decides they want to trap more characteristics, it requires changes to the table structure and the table quickly gets large with 30+ columns. I was thinking of just compacting all of these down to one column and then using serialize/unserialize and storing an array of the test scoresis this the best way?? Thanks! Hi! It doesn't seem like "good" db-practise to set all the values in one field. You shouldn't be forced to change database-structure just because the user inputs more information. You may reconsider using several tables and do relations between the tables.. /G http://www.varupiraten.se/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize
I have an app that stores evaluation scores so I have 30+ values all within a certain range, currently in the db, each of these values has it's own column: Table test id user_id motivation caring personal_characteristics creativity, ...etc. If the client decides they want to trap more characteristics, it requires changes to the table structure and the table quickly gets large with 30+ columns. I was thinking of just compacting all of these down to one column and then using serialize/unserialize and storing an array of the test scoresis this the best way?? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize and unserialize
You should use stripslashes to get rid of escaped characters in $_COOKIE['data']. Then remember to use addslashes when you want to use $data or $chksum in sql queries. [EMAIL PROTECTED] wrote: Hello all i need a little help with serialize and unserialize here is my code 'cart', 'y' => $password); session_register("y"); $var = serialize($data); //$chksum = md5($data . md5('secret salt here')); //$var = serialize(array($data,$chksum)); setcookie('data', $var, time() + 3600); } else { $var = unserialize($_COOKIE['data']); list($data, $chksum) = $var; if (md5($data . md5('secret salt here')) == $chksum) { // Data is valid $data = unserialize($_COOKIE['data']); list($y, $chksum) = $data; $x = $data['x']; $y = $data['y']; session_register("y"); } //session_register("y"); } ?> the problem is when i try to pull it back out to use the number that is generated by $password it gives me this error Notice: unserialize(): Error at offset 9 of 118 bytes in c:\program files\apache group\apache\htdocs\header.php on line 24 any ideas towards fixin this would be appreciated -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize and unserialize
Hello all i need a little help with serialize and unserialize here is my code 'cart', 'y' => $password); session_register("y"); $var = serialize($data); //$chksum = md5($data . md5('secret salt here')); //$var = serialize(array($data,$chksum)); setcookie('data', $var, time() + 3600); } else { $var = unserialize($_COOKIE['data']); list($data, $chksum) = $var; if (md5($data . md5('secret salt here')) == $chksum) { // Data is valid $data = unserialize($_COOKIE['data']); list($y, $chksum) = $data; $x = $data['x']; $y = $data['y']; session_register("y"); } //session_register("y"); } ?> the problem is when i try to pull it back out to use the number that is generated by $password it gives me this error Notice: unserialize(): Error at offset 9 of 118 bytes in c:\program files\apache group\apache\htdocs\header.php on line 24 any ideas towards fixin this would be appreciated
Re: [PHP] serialize?
Because it is desirable to create many small tables over one very large table I usually allow PHP to create dynamic tables. For instance, you could have a table called polls, and use the row id to create a unique table: -Dan On Tue, 2003-07-08 at 07:28, Sævar Öfjörð wrote: > Hi. Im coding a poll system which stores information in MySQL. > > When a new poll is created a new row is inserted in the table polls. > There I keep basic information such as the question, id etc. But should > I keep the poll options in one field also? Then I would create an array > from the poll options the user specifies, serialize it and then > base64_encode it. > > Is this a good way of storing an array or should I make a database table > named for example: polls_options? > > Any opinions and thougts on this appreciated. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize?
No, use another table, poll_options: poll_option_id, poll_id, option_text, vote_count hope the structure is self explanatory. Sævar Öfjörð wrote: Hi. I’m coding a poll system which stores information in MySQL. When a new poll is created a new row is inserted in the table ‘polls’. There I keep basic information such as the question, id etc. But should I keep the poll options in one field also? Then I would create an array from the poll options the user specifies, serialize it and then base64_encode it. Is this a good way of storing an array or should I make a database table named for example: ‘polls_options’? Any opinions and thougts on this appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize?
Hi. Im coding a poll system which stores information in MySQL. When a new poll is created a new row is inserted in the table polls. There I keep basic information such as the question, id etc. But should I keep the poll options in one field also? Then I would create an array from the poll options the user specifies, serialize it and then base64_encode it. Is this a good way of storing an array or should I make a database table named for example: polls_options? Any opinions and thougts on this appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize/unserialize problem
I figured out a little bit later. It's something like: rawurlencdoe(serialize($attachments)); unserialize(urldecode(stripslashes($attachments))); I overlook that rawurlencode/urldecode, another annoying thing :) I just came from perl, for half time I found PHP cute, another half time, you know it already, annoying :) Simple stuff sometimes not simple which as you know also is in contract to perl. But I still like PHP, for half and half is still very good percentage, if Steve Francis can shoot at this percentage (like Yao Ming does), Rockets will be much better off, right? Thanks anyway! Guangzu - Original Message - From: "Guangzu Wang" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, December 17, 2002 4:48 PM Subject: [PHP] serialize/unserialize problem > Hi, > I am working on mime message and try to pass an array with serialize and > unserialize and got some problems. > Here's some code snippet: > > in my function, I have this: > > $message['attachments'] = serialize($attachments); > > And calling code like this: > > $attachments = $message['attachments']; > echo "ATTACHMENT:$attachments"; > $attachments = unserialize($attachments); > echo "After unserialize:$attachments"; > > Here's the output: > > > ATTACHMENT:a:1:{i:0;a:6:{s:3:"pid";i:2;s:4:"type";s:10:"image/jpeg";s:8:"enc > oding";s:6:"base64";s:4:"size";s:5:"13540";s:11:"disposition";s:10:"attachme > nt";s:4:"name";s:10:"Sample.jpg";}} > After unserialize: > > It supposed to be an array after unserialize, but I got a empty result. I > used is_array() and got a false. I looked the online manual and tried those > annoying addslashes/stripslashes, nothing changed. What am I missed? > > Thanks a lot for your help! > > Guangzu > http://tjmu.com > http://GuangzuWang.incredibuys.com/ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize/unserialize problem
Hi, I am working on mime message and try to pass an array with serialize and unserialize and got some problems. Here's some code snippet: in my function, I have this: $message['attachments'] = serialize($attachments); And calling code like this: $attachments = $message['attachments']; echo "ATTACHMENT:$attachments"; $attachments = unserialize($attachments); echo "After unserialize:$attachments"; Here's the output: ATTACHMENT:a:1:{i:0;a:6:{s:3:"pid";i:2;s:4:"type";s:10:"image/jpeg";s:8:"enc oding";s:6:"base64";s:4:"size";s:5:"13540";s:11:"disposition";s:10:"attachme nt";s:4:"name";s:10:"Sample.jpg";}} After unserialize: It supposed to be an array after unserialize, but I got a empty result. I used is_array() and got a false. I looked the online manual and tried those annoying addslashes/stripslashes, nothing changed. What am I missed? Thanks a lot for your help! Guangzu http://tjmu.com http://GuangzuWang.incredibuys.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Serialize/URLencode query...
At 12:11 AM 5/12/2002 -0700, John Holmes posted the following... >You should use sessions. All you have to do is call session_start() at >the beginning of your code. Then, any variable you want to save to the >session, you simply use: That did the trick! Thanks for the explanation, John! Now I have a nifty script that reads the variables from my MSSQL query script, and creates a MS Excel file using the data without having to have a separate Excel-creating script for every page... :) This rocks! Thanks again, John! Glenn (I could post the code from that script, as well, if people would like to see it..?) --- The original portions of this message are the copyright of the author (c)1998-2002 Glenn E. Sieb.ICQ UIN: 300395IRC Nick: Rainbear "All acts of Love and Pleasure are Her rituals"-Charge of the Goddess -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Serialize/URLencode query...
You should use sessions. All you have to do is call session_start() at the beginning of your code. Then, any variable you want to save to the session, you simply use: $_SESSION["name"] = $name; Then, on the next page, call session_start() again, and you'll have the value of $name from the previous page in the variable $_SESSION["name"] It's a little different if you're not using PHP 4.2, so read the manuals on sessions... ---John Holmes... > -Original Message- > From: Glenn Sieb [mailto:[EMAIL PROTECTED]] > Sent: Saturday, May 11, 2002 7:57 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Serialize/URLencode query... > > I'd like to pass a bunch of variables to another PHP page for processing > there... I think serialize() and urlencode() will do what I'm looking > for.. > can I pass multiple strings through this? I'm also not clear on how I can > decode the separate strings out... > > Can someone point me in the right direction? > > Thanks, everyone! > Glenn > > --- > The original portions of this message are the copyright of the author > (c)1998-2002 Glenn E. Sieb.ICQ UIN: 300395IRC Nick: Rainbear > "All acts of Love and Pleasure are Her rituals"-Charge of the Goddess > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Serialize/URLencode query...
I'd like to pass a bunch of variables to another PHP page for processing there... I think serialize() and urlencode() will do what I'm looking for.. can I pass multiple strings through this? I'm also not clear on how I can decode the separate strings out... Can someone point me in the right direction? Thanks, everyone! Glenn --- The original portions of this message are the copyright of the author (c)1998-2002 Glenn E. Sieb.ICQ UIN: 300395IRC Nick: Rainbear "All acts of Love and Pleasure are Her rituals"-Charge of the Goddess -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize()
Hi list, I've already look at the php manual but couldn't figure out a way to use serialize to solve my problem. I have a form, with many fields like (name, age, adress, state), that I put a save button. This button allows my user to save the fields already filled in order to finish the form later. I thought in get the values submited by the save button and store it as cookie, them read it back later, but how can I store the fields in cookie with serialize and use it later to complety my fields again??? Thanks Rodrigo -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize
Instead of serialize(), you could also fix your existing code like this: "; } ?> Or "; } ?> bvr. > for ($i=0; $i<$HTTP_GET_VARS['num']; $i++) > { > echo "felnummer "; > } > ?> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize
On Tuesday, March 5, 2002, at 09:58 AM, Axel Nilsson wrote: > I use this code to create a number of fields in a form depending on > what input number I use. My problem occurs when i am going to save it. > Right now only the value of the last field gets stored. I want to > serialize all values from all fields so that they can be saved as a > stringvalue > > is there any friendly soul out there who knows how to do it? > > /Axel > > for ($i=0; $i<$HTTP_GET_VARS['num']; $i++) > { > echo "felnummer "; > } > ?> I did the exact same code just last week. Try this: for ($i = 0; $i < $_GET['num']; $i++) { echo "felnummer "; } It is very important that you use the doublequotes in the 'fellnummer["$i"]' and not use single quotes, or your variable will not expand to the value of $i (it will think that you want a literal 'buck i'). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serialize
hHi $data = serialize($felnummer); That should do it.. Tom At 12:58 AM 6/03/2002, Axel Nilsson wrote: >Hi All! >I use this code to create a number of fields in a form depending on what >input number I use. My problem occurs when i am going to save it. Right >now only the value of the last field gets stored. I want to serialize all >values from all fields so that they can be saved as a stringvalue > >is there any friendly soul out there who knows how to do it? > >/Axel > >for ($i=0; $i<$HTTP_GET_VARS['num']; $i++) >{ >echo "felnummer "; >} >?> > > > >_ >MSN Photos är det enklaste sättet att dela ut och skriva ut foton: >http://photos.msn.se/Support/WorldWide.aspx > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize
Hi All! I use this code to create a number of fields in a form depending on what input number I use. My problem occurs when i am going to save it. Right now only the value of the last field gets stored. I want to serialize all values from all fields so that they can be saved as a stringvalue is there any friendly soul out there who knows how to do it? /Axel "; } ?> _ MSN Photos är det enklaste sättet att dela ut och skriva ut foton: http://photos.msn.se/Support/WorldWide.aspx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] serialize object & session_auto_start
Hi, I'm trying to save an object in the session, with the serialize and uunserialize fonction. But i got an error message wich say me that i must define the class before the session start. But my session start automaticly. So I can't include my class before the session start. I'm looking for a workaround. Thanks -- -- Matthieu Brunet - [EMAIL PROTECTED] Réseau-Photo S.A. - http://www.reseau-photo.com 15, rue du Général Campredon - 34000 Montpellier Tél. : 04 67 58 07 08 - Fax : 04 67 58 03 04 Icq : 119683958 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] php serialize
wow... that looks like it might just do the job :) although it'd still be fun to hack up a simple serialize/deserialize in perl, i didnt know that WDDX modules existed for perl... i'll go and get it all and start playing around with it now :) > -Original Message- > From: Alexander Wagner [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 03, 2001 1:46 PM > To: scott [gts]; php > Subject: Re: [PHP] php serialize > > > scott [gts] wrote: > > i want to write serialize() and unserialize() in perl > > so that arrays (no objects or references yet) can be > > read/written by both PHP and Perl to help with my > > cross-language session implementation. > > Why don't you use WDDX? > > regards > Wagner > > -- > Madness takes its toll. Please have exact change. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] php serialize
scott [gts] wrote: > i want to write serialize() and unserialize() in perl > so that arrays (no objects or references yet) can be > read/written by both PHP and Perl to help with my > cross-language session implementation. Why don't you use WDDX? regards Wagner -- Madness takes its toll. Please have exact change. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] php serialize
does anyone know any good places to look for detailed information about PHP's serialize(), unserialize() (besides the PHP sources, becuase i'm already going thru them) i want to write serialize() and unserialize() in perl so that arrays (no objects or references yet) can be read/written by both PHP and Perl to help with my cross-language session implementation. i really would like to have some more integration between PHP and Perl... especially the sharing of data structures. since PHP's serialize()/unserialize() produces a simple text string, i thought i'd use that model -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] serialize/unzerialize help
Hello all members, i am confuse to pass my class object over page (read my quote below). can u give a little example to demonstrate this using serialize and unserialize function. thaks for your attention.. andrie Tuesday, March 13, 2001, 9:03:08 PM, Loe nulis gini: PK> do you have register_globals enabled in your php.ini? you also have to have PK> the class definition available when unserializing it to properly reconstruct PK> the class with all the methods. if you're using PHP4 it's quite handy to use PK> the built-in session functionality to implement persistent classes. PK> Pavel PK> - Original Message - PK> From: "andrie" <[EMAIL PROTECTED]> PK> To: <[EMAIL PROTECTED]> >> Hello php-db, >> >> if i have a class >> class myDog { >> VAR $name; >> Function bark(); >> } >> >> $dog = new myDog; >> >> and i want to pass this class over page. someone in this forum said >> to me to use serialize and pass it using cookies. >> setcookie("dog", serialize($dog)); >> the question is, when i used unserialize to get this class from >> other page , >> unserialize($dog); >> >> i have found out that i can find my class structure or any >> properties and it values there. >> anybody can help me ? >> >> -- >> Best regards, >> andrie mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] serialize/deserialize data
what serialize does is that it allows you to store or pass data types such as arrays, objects etc without losing their structure. for ex, let's say you have an array $foo=array("abc","def") now you need to pass this array to the next page without losing the structure. that is on the next page, you shoudl be able to do $foo[0] and till be able to get $foo[0] as "abc" just do the folloowing $passFoo=serialzie($foo); and pass the value in $passFoo to the next page on the next page, you should do $foo=unserialzie($passFoo) and doing $foo[0] should give you "abc" try it out yourself writing some dummy code and you will understand it better. serialize is extremely helpful in case of storing session variables, arrrays etc. hope that helps Ankur Verma HCL Technologies A1CD, Sec -16 Noida, UP India - Original Message - From: "Brian V Bonini" <[EMAIL PROTECTED]> To: "PHP Lists" <[EMAIL PROTECTED]> Sent: Tuesday, February 13, 2001 5:36 AM Subject: [PHP] serialize/deserialize data > What exactly does > serialize/deserialize data > mean? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] serialize/deserialize data
"Brian V Bonini" <[EMAIL PROTECTED]> wrote: > What exactly does > serialize/deserialize data > mean? See the manual at http://www.php.net/manual/en/function.serialize.php. Serializing is a way of storing values so that they retain their type and structure. Session variables are stored in this way. Here's a serialized set of session variables from an intranet application I wrote: employee_id|s:4:"7204";logged_in|i:1;name_l|s:7:"Edmonds";name_f|s:5:"Larry" ;component_id|a:5:{i:0;s:4:"1001";i:1;s:4:"1002";i:2;s:4:"1003";i:3;s:4:"100 4";i:4;s:7:"1002101";} unserialize( $var_name ) will pull transform the values back into their normal state. If you want to pass form data from page to page (arrays in particular), store an array in a single field of a database or store values and retain the fact that they're an integers, strings, etc. serialize is a good way to accomplish this. I hope that helped clarify serialize a little. If not, just play with it a little to understand it. -- Steve Werby COO 24-7 Computer Services, LLC Tel: 804.817.2470 http://www.247computing.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] serialize/deserialize data
What exactly does serialize/deserialize data mean? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]