[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 11-13-2007, 07:36 AM   #1 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

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?

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, 08:32 AM   #2 (permalink)
Senior Member
 
Join Date: Aug 2007
Posts: 2,167
457.00 NP$ (Donate)

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);
__________________
______________________________________
Time After Leisure & Events discussions
eBay auction aqnu, pzpy, vqqr.com 16 llll.com start $.95
_______________ f o r . s a l e ______________
jido is offline  
Old 11-13-2007, 10:16 AM   #3 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

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, 10:27 AM   #4 (permalink)
Senior Member
 
Join Date: Aug 2007
Posts: 2,167
457.00 NP$ (Donate)

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?
__________________
______________________________________
Time After Leisure & Events discussions
eBay auction aqnu, pzpy, vqqr.com 16 llll.com start $.95
_______________ f o r . s a l e ______________
jido is offline  
Old 11-13-2007, 01:00 PM   #5 (permalink)
NamePros Regular
 
Join Date: Oct 2006
Posts: 918
40.00 NP$ (Donate)

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

muov.com • qeww.com • sejz.com • viuo.com • vuav.com • wzeo.com • xeib.com • xueo.com

-- Do not let others be treated this way!
neroux is offline  
Old 11-14-2007, 09:38 AM   #6 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

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 />";
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, 12:37 PM   #7 (permalink)
NamePros Regular
 
Join Date: Oct 2006
Posts: 918
40.00 NP$ (Donate)

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

muov.com • qeww.com • sejz.com • viuo.com • vuav.com • wzeo.com • xeib.com • xueo.com

-- Do not let others be treated this way!
neroux is offline  
Old 11-14-2007, 01:14 PM   #8 (permalink)
Danltn.com
 
Daniel's Avatar
 
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
13.51 NP$ (Donate)

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", $cookie, time() + 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;
}
Remember: Cookie names can not contain any of the following '=,; \t\r\n\013\014

Last edited by Danltn; 11-14-2007 at 01:18 PM.
Daniel is offline  
Old 11-18-2007, 03:43 PM   #9 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:58 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85