NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [resolved] problems with serialize and unserialize

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 11-13-2007, 08:36 AM THREAD STARTER               #1 (permalink)
Munky Designs
Join Date: May 2005
Posts: 996
Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough
 



problems with serialize and unserialize


hey,

ok, I am saving 2 values in my cookie, like so:

Code:
$cookie = @serialize(array($u, $c));
setcookie("siteLogin", $cookie, time() + 36000, "/");
$u is username, $c is a cookie value (this is part of a remember script for logins).

now, when I come to extract it, I have this:

Code:
if (isset($_COOKIE['siteLogin'])){

    echo $_COOKIE['siteLogin']."<br />";
    echo unserialize($cookie)."<br />";
    list($u, $c) = @unserialize($cookie);
    echo "username: ".$u."  cookie: ".$c;

}
the echo is just for debugging, ive checked if the cookie contains a value, it does (and looks serialized). I can;t echo it unserialized or listed, am I doing something wrong?
????: NamePros.com http://www.namepros.com/programming/395341-resolved-problems-with-serialize-and-unserialize.html

here is a test url:

http://munkydesigns.co.uk/ScriptsNew/login.php

u: username
p: password

make sure you check remember me lol

thanks in advance
Albino is offline  
Old 11-13-2007, 09:32 AM   #2 (permalink)
Senior Member
Join Date: Aug 2007
Posts: 2,172
jido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond repute
 



First thing, look at unserialize error messages:

Code:
    list($u, $c) = unserialize($cookie);
__________________
______________________________________
Help with crosswords http://lettercombination.com
Pitfalls of Java http://javasyntax.com
_______________ f o r . s a l e ______________
jido is offline  
Old 11-13-2007, 11:16 AM THREAD STARTER               #3 (permalink)
Munky Designs
Join Date: May 2005
Posts: 996
Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough
 



there are no error messages
Albino is offline  
Old 11-13-2007, 11:27 AM   #4 (permalink)
Senior Member
Join Date: Aug 2007
Posts: 2,172
jido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond repute
 



Can you paste the serialized cookie here?
__________________
______________________________________
Help with crosswords http://lettercombination.com
Pitfalls of Java http://javasyntax.com
_______________ f o r . s a l e ______________
jido is offline  
Old 11-13-2007, 02:00 PM   #5 (permalink)
NamePros Regular
Join Date: Oct 2006
Posts: 963
neroux has a spectacular aura aboutneroux has a spectacular aura about
 



You are referring to a variable $cookie which doesnt seem to be set unserialize($_COOKIE['siteLogin']); should do it.
__________________
Paris loves CityPics

-- Do not let others be treated this way!
neroux is offline  
Old 11-14-2007, 10:38 AM THREAD STARTER               #6 (permalink)
Munky Designs
Join Date: May 2005
Posts: 996
Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough
 



Jido, here is the serialized cookie: a:2:{i:0;s:8:\"username\";i:1;s:32:\"29ef5859fbfe3 4e0918bdec7ec00a988\";}

Neroux, good spot haha. thats because I copied and pasted the snippet from the actual function, with $cookie as a parameter. However, even as :

PHP Code:
echo $_COOKIE['siteLogin']."<br />";
????: NamePros.com http://www.namepros.com/showthread.php?t=395341
echo 
unserialize($_COOKIE['siteLogin'])."<br />";
list(
$u$c) = @unserialize($_COOKIE['siteLogin']);
echo 
"username: ".$u."  cookie: ".$c
I get no outcome
Albino is offline  
Old 11-14-2007, 01:37 PM   #7 (permalink)
NamePros Regular
Join Date: Oct 2006
Posts: 963
neroux has a spectacular aura aboutneroux has a spectacular aura about
 



I know you said the cookie contains the value, but can you check it once again? The reason is, in your example I am not even getting the cookie but only the session cookie.
__________________
Paris loves CityPics

-- Do not let others be treated this way!
neroux is offline  
Old 11-14-2007, 02:14 PM   #8 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
Try this, it's ugly and someone will probably yell at me. But it seems to work.

PHP Code:
$u "hello";
$c "world";

$cookie urlencode(serialize(array($u$c)));

if(!
setcookie("siteLogin"$cookietime() + 20000)) die("Hmm");

if(isset(
$_COOKIE['siteLogin'])) {
        
    
$line urldecode($_COOKIE['siteLogin']);
    
    if (
get_magic_quotes_gpc()) $line stripslashes($line);
    
    list(
$a$u) = unserialize($line);
    echo 
"username: " $a "<br />pass: " $u;
????: NamePros.com http://www.namepros.com/showthread.php?t=395341

Remember: Cookie names can not contain any of the following '=,; \t\r\n\013\014
Last edited by Danltn; 11-14-2007 at 02:18 PM.
Daniel is offline  
Old 11-18-2007, 04:43 PM THREAD STARTER               #9 (permalink)
Munky Designs
Join Date: May 2005
Posts: 996
Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough
 



cheers Danltn, worked a treat
Albino is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 12:39 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger