Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Apache::Session problem update...

by powerhouse (Friar)
on Dec 29, 2002 at 00:03 UTC ( [id://222817]=perlquestion: print w/replies, xml ) Need Help??

powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

Ok, Here is what I have done now...

Paul DuBois helped do this part, he sent me this code:

my $session_contents = "Session contents:<br />"; foreach my $key (keys (%{$sess_ref})) { $session_contents .= "Key: " . escapeHTML ($key) . " value: (" . escapeHTML ($sess_ref->attr ($key)) . ")" . "<br />"; }

I added it to the script so that it displayed on every page. When this happened, I got these results:

Here it is when I first load it:

Session contents:
Key: #<expires># value: (ARRAY(0x82b0284))
Key: _session_id value: (fd52d8aad5076259c022aa99adf602c0)

Then when I go to the login page:
Session contents:
Key: #<expires># value: (ARRAY(0x82b032c))
Key: _session_id value: (fd52d8aad5076259c022aa99adf602c0)

It's the same. Then when I login:
Session contents:
Key: c_q value: (2)
Key: country value: (USA)
Key: loggedin value: (1)
Key: postal_code value: (my_zip)
Key: lname value: (Jones)
Key: number value: (1)
Key: fname value: (Richard)
Key: street2 value: ()
Key: street3 value: ()
Key: mname value: (L)
Key: c_q_a value: (stockholm)
Key: titl value: (Mr.)
Key: _session_id value: (fd52d8aad5076259c022aa99adf602c0)
Key: phone value: (my_phone)
Key: #<expires># value: (ARRAY(0x82b06fc))
Key: nname value: (Richie)
Key: state value: (myState)
Key: city value: (my City)
Key: last_login_ip value: (myLastIP)
Key: username value: (my_username)
Key: province value: ()
Key: updates value: (1)
Key: remember_me value: (0)
Key: email value: (my email)
Key: street value: (my address)

See it does load them in there and log me in, but then if I leave the page, here is what it now has:
Session contents:
Key: #<expires># value: (ARRAY(0x82b032c))
Key: _session_id value: (fd52d8aad5076259c022aa99adf602c0)

Right back to the same old thing. The only constant is the session_id and the expires, although the expires changes every time...

What would cause that to happen?

I really don't understand.

thx,
Richard

Replies are listed 'Best First'.
Re: Apache::Session problem update...
by Anonymous Monk on Dec 29, 2002 at 00:17 UTC
    If you turned warnings on, you would see a warning about "variable cannot remain shared". The three basic solutions are to pass the session keys explicitly into every function, change my to our, or use the vars pragma to declare variables instead of using my.

    OK, so that is the solution. What is the problem? That is a little more complex to explain.

    Here is what Apache::Registry does. The first time your run your script it takes your CGI script, sticks a function around it, and calls eval. The second time it calls that function. The problem is that the functions in your script have global names, but the my variables that they are sharing with the rest of your script are private to the invocation of the outer wrapper function. So if you call the outer wrapper function twice (ie access the page twice), on the second call all of your functions are accessing the my variables from the first time you loaded that page.

    If this confuses you, then review the code example at Re (tilly) 9: Why are closures cool? carefully and see if you an understand what it does. Replace the entire contents of outer() by your script, get rid of the anonymous functions that are meant to show you what is happening, and you have what is going wrong with your script.

    If you still have trouble seeing it, just take my word that the problem is subtle and is basically impossible to come up with a really good fix to.

    In that light, the three solutions correspondingly are to stop trying to share a private variable, make the private variable accessed actually be a global variable, and just plain make accessing a global variable OK.

      If you turned warnings on, you would see a warning about "variable cannot remain shared".

      If he is running this under mod_perl, that is. I don't see mod_perl mentioned in the original post.

Re: Apache::Session problem update...
by mt2k (Hermit) on Dec 29, 2002 at 00:21 UTC
    Hrrm... as to your problem, I don't know. I'm just here to comment on the fact that you've started a second thread on the exact same problem. You most likely should not have done that. That's what threads are for: continued discussion/problem solving. If it was possible, I'd move this post to make it a reply of the original post. As for the first post on this subject, I believe you might want to look at Writeup Formatting Tips for the hint on using CODE tags instead of PRE ones. (Err... your reply to that first one I mean) Messy messy messy...

    I wish I could have linked to the better documentation on formatting, etc, but the site documentation is quite spread out. Needs some reformatting and rewriting I do believe. And for the likes of me, I cannot recall the fellow monk who has written up a bunch of documentation for the site (the stuff that will soon become the official docs here I do hope).

    -------------------------------------
    eval reverse@{[lreP
    =>q{ tsuJ\{qq},' rehtonA'
    ,q{\}rekcaH },' tnirp']}[1+1+
    1,1-1,1+1,1*1,(1+1)*(1+1)];
    -------------------------------------
    

      Yes, If you notice this thread does use the <code> tag, instead of <pre> :o)
      Jeffa already asked me about it.

      As for the posting on the same thread, I am new to this forum, I have been visiting here for a long time, but never read posts, or posted anything, so did not know how it works, in addition to that, it seemed like everytime I posted, I could never see my post, where I posted it. I don't know if it's just not in real time, or if the server is just terribly slow, or what.

      So, with that being the case, I started a new thread, "Updating" where I was at, so it would show up, where people would see it, as I don't know if the threads are posted in order of original date, or last posted date. And I was not able to see where my thread was in the first place to just hit reply, I had to go search under my posts to find them. Not something I think anyone would do on this forum.

      That is why I did it. I would really like it if someone explained how they are sorted, so I'll know how they actually work.

      I've made several mistakes, because I was unaware of how this forum posts things and such. I did read the information they provide too, but it did not help in understanding how, when and where the posts were posted.

      Anyways, enough of this. I know how to post now, but still would like to know where they go when I hit submit, because I don't see them in the thread, only where it takes me right after I post.

      thx,
      Richard

        Regarding why you don't see your posts after submitting them: around here, we call it the 'approval' process. Basically, after you submit your post, one user (yep, it only takes one user, besides yourself) must say 'yes, this post is worthy of being viewed by everyone who might be interested and deserves to be given some attention by the rest of the readers of the site'.

        So it might take between 10 seconds and a couple of hours for your post to be approved. If you still don't see the post after several hours, it may be because your fellow monks think the post was not perl-related or that you didn't put any thought or effort into solving your own problem. We like to see code examples that show you've attempted to tackle the problem yourself. If you just need something done and you don't want to do any work, don't think that others will do your work for you. If that's what you're looking for, look for somebody who will work for money :)

        Another reason you might not be able to see your post is that it HAS been approved, but others thought your post would be better presented under another section on the site. So if you post to Seekers of Perl Wisdom, but your post is a question about the site and not about Perl, it might have been moved to Perl Monks Discussion. Check out all the sections to see if it's hanging around. :)

        Also, if you really want to see your post (as well as those posted by others) right away without waiting for them to be approved, look under User Settings, and check the checkbox that says 'Show Unmoderated Content', located under the 'Miscellaneous' section. This will place non-approved nodes at the top of the message list, so that you can browse them without scrolling to the very bottom of the page, where unmoderated/unapproved nodes hang around.

        I don't know if it's just not in real time, or if the server is just terribly slow, or what.

        Blasphemy! Nothing is wrong with Perl Monks :P Seriously though, there haven't been terrible problems regarding the cached documents. As soon as more content is discovered, the cached page is updated. The only area that used to (may still?) be a little out of sync was the front page of the site. I think so anyhow.

        And to answer the question you asked in paragraph 3, the posts are sorted according to original posting date. If a reply is written for a certain thread, the post is not replaced at the top of the list. This just keeps everything organized in a simple manner. In this way, threads don't keep jumping around. Now, if you're wondering how to keep up with which threads are well-discussed topics, there is one great way: and it has this very purpose in mind.

        It is called Newest Nodes. Newest Nodes is wonderful. Its default behaviour is to show you the threads and nodes that have been posted/created since the last time you checked the list. Once you've read all the nodes you are interested in, you simply click the "I've checked all these" button at the bottom of that page. You'll then have an empty list, and any newly created threads will be put on this list.

        This is also the feature that makes starting another thread on the exact same problem/question/topic very annoying. If anybody who read the original post is interested in that particular post, they will watch Newest Nodes for replies to that post... therefore there is no need to start another thread. Even if the original thread is not anywhere near the top of the list, replies will still be found and read by those who use the useful Newest Nodes. So even if you post a reply to a thread posted in the year 2000, a link to the reply will be added to Newest Nodes.

        Just my $30.02

        -------------------------------------
        eval reverse@{[lreP
        =>q{ tsuJ\{qq},' rehtonA'
        ,q{\}rekcaH },' tnirp']}[1+1+
        1,1-1,1+1,1*1,(1+1)*(1+1)];
        -------------------------------------
        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://222817]
Approved by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-16 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found