X-Original-To: pgsql-php@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id BEC644758F1 for ; Sat, 22 Mar 2003 01:44:40 -0500 (EST) Received: from alegro.binertia.com (unknown [216.254.174.62]) by postgresql.org (Postfix) with ESMTP id D18BC474E44 for ; Sat, 22 Mar 2003 01:44:39 -0500 (EST) Received: from nofate.com (unknown [24.112.13.97]) by alegro.binertia.com (Postfix) with ESMTP id 3CB94C824A; Sat, 22 Mar 2003 01:51:54 -0500 (EST) Message-ID: <3E7C056A.1090408@nofate.com> Date: Sat, 22 Mar 2003 01:40:42 -0500 From: apz User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ludwig Lim Cc: PostgreSQL Mailing List Subject: Re: Questions Regarding Sessions References: <20030322050118.17564.qmail@web80411.mail.yahoo.com> In-Reply-To: <20030322050118.17564.qmail@web80411.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-27.4 required=5.0 tests=EMAIL_ATTRIBUTION,HTML_00_10,HTML_MESSAGE,IN_REP_TO, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50-cvs X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50-cvs (1.172-2003-02-14-exp) X-Archive-Number: 200303/30 X-Sequence-Number: 1942 Ludwig Lim wrote: > I've tried testing simple session scripts and it > works, but initializing and using sessions in a > function seems to be a problem for me. do session_start and session_register in global scope, then it seems to work. http://www.php.net/manual/en/function.session-start.php > How can I make the script above to work? I dont know if this is proper 'recommended' php way, but I have an include called myPageStart.inc.php that I load on every page that needs sessions: -------/ START: t1.php /-------------- -------/ END: t1.php /-------------- -------/ START: t2.php /-------------- -------/ END: t1.php /-------------- -------/ START: myPageStart.inc.php /-------------- -------/ END: : mySessionStart.inc.php /-------------- another few notes (by quicly reading: http://www.php.net/manual/en/ref.session.php ) using $HTTP_SESSION_VARS is deprecated, try using just $_SESSION it was ok until PHP 4.0.6, since then use $_SESSION when using $_SESSION, its always global, no need to ask for it to be from global scope in a function. It already is. using session_register is now not needed dont use session_is_registered, there is no need, just use as if any other var with isset, so your if should be just: if (isset($_SESSION[$_SESSION["test"]])) { which brings me to another point. you seem to confuse the idea of session key with session value. $_SESSION["test"]="hello"; here key = "test", value = "hello" as if: $key = "test"; $value = "hello"; $_SESSION[$key] = $value; but then, when you register/check if registered, the key is different $_SESSION["test"]="hello"; session_register($_SESSION["test"]); is same as if: $_SESSION["test"]="hello"; session_register("hello"); or if you prefer to see it through $key , $value then: $key = "test"; $value = "hello"; $_SESSION[$key] = $value; session_register($value); Now, when you do this session_register you tell it that there is another key within session, now we have two keys: $_SESSION["test"] $_SESSION["hello"] I dont think this is what you want, I am including here what I think you really wanted, with what should be up to newest php specs: -------/ START: t1.php /-------------- -------/ END: t1.php /-------------- -------/ START: t2.php /-------------- "); $x = $_SESSION["test"]; echo ("value of session = $x"); session_destroy(); } ?> -------/ END: t1.php /-------------- -------/ START: myPageStart.inc.php /-------------- -------/ END: : myPageStart.inc.php /-------------- You mgith want to question myPageStart.inc.php, I also use it, besides starting session, start various counters which later I use to in myPageEnd.inc.php to log what parts of my page took how long to generate, so that I know what to look next to optimize. hope this helps /apz, The moving cursor writes, and having written, blinks on.