Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Ok, I have a Module I wrote with the help of Paul DuBois' "Perl and MySQL for the web". Which has taught me a lot.

I have modified a few parts of it to fit what I'm doing.

I've created an "admin" interface, whereby, the individual I've created it for, and myself can manage this site, including Registered users.

In the Admin interface there is a link that is for "managing users", if you click that, it will show their status, if they are verified(email), if they are admin(yes or no). If they are NOT an administrator, their is an option to add them, if they are, their is an option to remove them.

In both, I want it to Open EVERY session_id, Check the "session's username" as in the session, if exists.

For Adding "admin" powers, I want it to check if it is their session, and they are logged in, then if both of those are true, then it ADDS the variable the system checks to see if they are an admin user.

If it's to remove them, then it checks to find All THEIR sessions that are not deleted, and if they contain the variable that says they are admin users, then it deletes those variables. This way, if they are currently logged in, and I remove them, it's real time, not only after they log out and back in. and the other way around too. Where it will add them, real time, not only after they logout and back in.

So to do this, I added this to the code, in the appropriate place. Do you see a problem with this?
$cust_username = $dbh->selectrow_array(qq{SELECT username FROM + users WHERE id = "$in{id}"}); $sth1 = $dbh->prepare (qq{ SELECT * FROM session_db }); $sth1->execute(); while($row1 = $sth1->fetchrow_hashref()) { next if !$row1->{id}; $sess_ref1 = CWT::Site_DB->open_with_expiration(undef, $ro +w1->{id}); if($sess_ref1->attr("username") eq "$cust_username") { if ($sess_ref1->attr("logged_in") == 1) { $sess_ref1->attr("is_admin",1); } else { next; } } else { next; } } $sth1->finish();
I did it this way in the Remove them code:
$cust_username = $dbh->selectrow_array(qq{SELECT username FROM + users WHERE id = "$in{id}"}); $sth1 = $dbh->prepare (qq{ SELECT * FROM session_db }); $sth1->execute(); while($row1 = $sth1->fetchrow_hashref()) { next if !$row1->{id}; $sess_ref1 = CWT::Site_DB->open_with_expiration(undef, $ro +w1->{id}); if($sess_ref1->attr("username") eq "$cust_username") { if ($sess_ref1->attr("is_admin") == 1) { $sess_ref1->clear_attr("is_admin"); # Delete that +variable from sess. } else { next; } } else { next; } } $sth1->finish();


It seems like that would work. I use $sess_ref for the regular sessions, so I added 1 behind it to open each session.
This is not working. When I load the page, either adding or removing the admin "powers", it times out, then the dang site won't load for me for at least an hour. If I don't do that, then it just adds them or removes them depending on the action, but it don't work until they Next login.

Do you see a reason why this would not work?

Do you need to see more? If so, what part, module or the actual code surrounding the above extracts?

Thanks,
Richard

In reply to Sessions, Perl and MySQL by powerhouse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found