News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Question about cookies...

Started by Dazitov, January 05, 2005, 11:22:20 AM

Previous topic - Next topic

Dazitov

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: $something=unserialize($_COOKIE['SMFCookie7'])

Where as, if I simple echo the value of $_COOKIE['SMFCookie7'] and copy that like so:
$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. hxxp:php.net [nonactive] 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..

Peter Duggan

Quote from: Aphotix on January 05, 2005, 11:22:20 AM
So, what class definitions do I need to make this work?

Don't think it uses classes.

Quote from: david55038 on January 05, 2005, 11:22:20 AM
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

Peter Duggan

Quote from: Peter Duggan on January 05, 2005, 11:42:06 AM
Quote from: Aphotix on January 05, 2005, 11:22:20 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.

Dazitov

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:

<?php
require("YOUR_PATH_TO_SSI.php");

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



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.

Dazitov

That reminds me, do you know where the array `$context` is?

Peter Duggan

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();

Dazitov

Quote from: Peter Duggan 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();


Thats what I was afraid of ;_;

Thanks though!

[Unknown]

Quote from: Aphotix on January 05, 2005, 01:14:25 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]

Advertisement: