Re: Sessions auto storing class



UKuser wrote:
Hi Folks,

I'm working on a basket at the moment, however I'm experiencing
something VERY wierd. My local scripts work fine, however my live ones
error saying I'm trying to use an object as an array. What I
discovered is that $_SESSION is outputting:

Array
(
[basket] => basket_orders Object
(
[site] => site Object
(
[db] => Zend_Db_Adapter_Mysqli Object
(
[_numericDataTypes:protected] => Array
(

So evidently, SESSION is storing my object but it should only be
storing the data I provide to it?? My Constructor for "basket_orders"
is:

public function __construct($get,$post){
session_start();
require_once("class_site.php");
$site = new site;
$this->site = $site;

switch ($get['act']){
case "add": return $this->addBasket($post); break;
case "del": return $this->deleteBasket($post); break;
case "upd": return $this->updateBasket($post); break;
case "count": return $this->countBasket(); break;
case "show":
if (isset($get['test'])){
print"<pre>";print_r($_SESSION);print"</pre>";exit;
}
return $this->showBasket($get); break; // used for the main
basket page
case "drop": return $this->dropBasket(); break;
// Again - added for testing purposes
case "clear":
session_start();
$_SESSION = array();
$_COOKIE = array();
session_destroy();
header("location:products.php?pid=1");
break;
}
}

I don't believe I'm doing anything blindingly stupid, but am happy to
be advised otherwise.

I hope that sounds familiar - I don't want to paste my whole script in
here as its a few hundred lines, but let me know if you need anything
more.

Thanks

A

This is a constructor, but what class is this in?

I don't see anywhere you are storing data in the $_SESSION array or retrieving from that array, other than clearing it with $_SESSION=array() (which, BTW, is not a good idea - it's better to unset() the appropriate values).

If you are storing the object in the $_SESSION array, then you must include the class definition before you call session_start().

One other thing - generally it's not a good idea to call session_start() within a function. Things have a tendency to go bad if you either call session_start() more than once or output anything before the call to session_start(). I find it better to just place it at the top of each page (after any required include files, of course).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Sessions auto storing class
    ... I'm working on a basket at the moment, ... My local scripts work fine, ... SESSION is storing my object but it should only be ...
    (alt.php)
  • aspnet_state.exe Internals Info Needed
    ... I noticed when storing large amounts of information in the StateServer ... Service that this does not increase in size, the worker process itself seems ... I thought the State Server actually stored the session data itself, ... seem from my example that this is not the case and that the memory space ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to use same menu html code on each page
    ... the Session may be an issue as you'll end up, in theory, with the SAME menu ... > My application has a menu which is defined and stored in a database. ... > which gets the menu from the database and then converts it into the html ... > storing the menu html in the Application or Session state object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Restrict use of Multiple Users for the Same Login
    ... storing and comparing varbinary fields is not a problem in SQL server and is ... Just storing something like an IP address may be an alternative. ... the lines of an inactivity timeout may be used to clear down the session ... > Reason: Still falls prey to the same problem of connections constantly being opened and closed by the web pages. ...
    (microsoft.public.sqlserver.programming)
  • Re: Funny session behavior
    ... the $_SESSION array. ... the session to transport a session id. ... That doesn't mean they know anything about security. ... And these usually have the cheapest tech support people (i.e. the least knowledgeable - or the least caring). ...
    (comp.lang.php)