dphdh395195 2012-03-31 01:30
浏览 20
已采纳

如何访问cookie数组子变量

How do I access user_id: This is the print_r of my cookie:

Array
(
     [PHPSESSID] => gv0hsh6uel9kiuprdoc0uqboq4
     [oauth_token] => 40533855-FNM77JeuJIPdKclYyaT2Fi9jZRu2NGAHh5FeveNk
     [oauth_token_secret] => C6GDTEu60rGa4aDbqjncm6yfUf9Xc9520AuX9GXag
     [SocialAuth] => a:2:{s:4:"type";s:8:"facebook";s:7:"user_id";s:2:"22";}
     [__utma] => 157144508.1187834205.1333154906.1333154906.1333154906.1
     [__utmb] => 157144508.35.10.1333154906
     [__utmc] => 157144508
     [__utmz] => 157144508.1333154906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
)

My user ID in this is at the end of the SocialAuth line... "22". But I cant seem to access it.

$user = $_COOKIE["SocialAuth"]["user_id"];

Returns "a".

Am I doing this right? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dsmupo6631 2012-03-31 01:32
    关注

    You have a serialized array in $_COOKIE['SocialAuth']. Take a look at the manual pages for serialize and unserialize.

    Use unserialize like this to access the user id:

    $user = unserialize($_COOKIE['SocialAuth'])['user_id'];
    

    Or prior to PHP 5.4:

    $arr = unserialize($_COOKIE['SocialAuth']);
    $user = $arr['user_id'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式