Advertisement:

Author Topic: Question about cookies...  (Read 5696 times)

Offline Dazitov

  • Newbie
  • *
  • Posts: 5
  • Gender: Male
    • Daxitove
Question about cookies...
« on: January 05, 2005, 11:22:20 AM »
I do not really intend to be a 'noob' but since this is the support area, it is where I shall post this question.

I am trying to retrieve the data off of the cookie set by the SMF forum, but I have come across a problem. When I try to unserialize the information from the cookie, i get an empty variable.

ex:
Code: [Select]
$something=unserialize($_COOKIE['SMFCookie7'])
Where as, if I simple echo the value of $_COOKIE['SMFCookie7'] and copy that like so:
Code: [Select]
$something=unserialize("a:3:{i forget whats in here...}")I am able to use print_r to output the values of the resulting array successfully to the browser.

Now I am am not quite sure what a class is or what it even does, but I think that is why I can't do this. php.net says

" It is strongly recommended that you include the class definitions of all such registered objects on all of your pages, even if you do not actually use these classes on all of your pages. If you don't and an object is being unserialized without its class definition being present, it will lose its class association and become an object of class stdClass without any functions available at all, that is, it will become quite useless."

So, what class definitions do I need to make this work?

Oh and I am doing this so that I can check to see if a user is logged in on my webpage, because there are some member-only areas, and rather than having the member log in seperately I thought it would be conviniant if they could be logged in automatically if they are logged in on the message board..

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,664
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Question about cookies...
« Reply #1 on: January 05, 2005, 11:42:06 AM »
So, what class definitions do I need to make this work?

Don't think it uses classes.

Oh and I am doing this so that I can check to see if a user is logged in on my webpage, because there are some member-only areas, and rather than having the member log in seperately I thought it would be conviniant if they could be logged in automatically if they are logged in on the message board..

Think you might be trying to reinvent the wheel here, so suggest looking at SMF's SSI functions:

http://www.simplemachines.org/community/index.php?topic=14906.0
http://www.simplemachines.org/community/ssi_examples.php

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,664
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Question about cookies...
« Reply #2 on: January 05, 2005, 11:53:01 AM »
So, what class definitions do I need to make this work?

Don't think it uses classes.

Nope, there are only 8 classes in SMF 1.0:

class ftp_connection
class CGIFLZW
class CGIFCOLORTABLE
class CGIFFILEHEADER
class CGIFIMAGEHEADER
class CGIFIMAGE
class CGIF
class xmlArray

Most of which are in Subs.Graphics.php.

Offline Dazitov

  • Newbie
  • *
  • Posts: 5
  • Gender: Male
    • Daxitove
Re: Question about cookies...
« Reply #3 on: January 05, 2005, 11:57:36 AM »
Okay, well thanks.

You are right, I pretty much was reinventing the wheel, but thats only because I didn't know what the function for checking what a logged in user was. I think this is what I am looking for:

Code: [Select]
<?php
require("YOUR_PATH_TO_SSI.php");

if (
$context[&#39;user&#39;][&#39;is_guest&#39;])
{
   echo
   &
#39;<h5>Access Denied</h5>
   
We are sorry guestit seems you dont have premission to view these downloads.&#39;;
}
else
{
   echo
   &
#39;<h5>Welcome &#39;, $context[&#39;user&#39;][&#39;name&#39;], &#39;!</h5>
   
Here are your downloads:&#39;;
}
?>


Though that still leaves me with the question of why I can not unserialize information from a cookie. I guess I should not have thought that was a class problem, because I never have been able to unserialize data stored in a cookie, but I don't think this is the right place to ask about that.

Anyways, though I do want to learn how to unserialize from a cookie, you did help, so I can get back to work and figure it out some other time when I really need it. Thank you for your help, and quick reply, I did not want to sit here stuck all day. Again, thanks.

Offline Dazitov

  • Newbie
  • *
  • Posts: 5
  • Gender: Male
    • Daxitove
Re: Question about cookies...
« Reply #4 on: January 05, 2005, 12:07:44 PM »
That reminds me, do you know where the array `$context` is?

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,664
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Question about cookies...
« Reply #5 on: January 05, 2005, 12:14:22 PM »
Just about everywhere!

It's defined in index.php:

$context = array();

but added to all over the place like this:

$context['user']['is_mod'] = false;
$context['linktree'] = array();

Offline Dazitov

  • Newbie
  • *
  • Posts: 5
  • Gender: Male
    • Daxitove
Re: Question about cookies...
« Reply #6 on: January 05, 2005, 01:14:25 PM »
Just about everywhere!

It's defined in index.php:

$context = array();

but added to all over the place like this:

$context['user']['is_mod'] = false;
$context['linktree'] = array();


Thats what I was afraid of ;_;

Thanks though!

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Question about cookies...
« Reply #7 on: January 07, 2005, 08:13:18 PM »
Thats what I was afraid of ;_;

Thanks though!

Parts of it are in various places; its contents depend on the page view, and can differ radically from one page to the next.

-[Unknown]