after a user logs in, i can pull up their username and print it out on the webpage with <?php $_SESSION['MM_Username'] ?>.
however, i want to take that text value and store it in the database along side a timestamp. so that i know when someone is logged in and what they were doing.
simple as this sounds, i'm finding it not so simple.
how do you take the username of the person logged into your website and store that in the MySQL database?
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search
Last edited by BubikolRamios; 01-20-2013 at 05:21 PM..
Users who have thanked BubikolRamios for this post:
The behaviour you describe requires either using completely database controlled sessions, or to use the session_set_save_handler for simplicity. That lets you override the functionality of sessions so you can transparently use and modify the session without needing to implement any new control code to the existing scripts. If you set the save handlers, you can use a database or still use the filesystem and use partial database control for things like a timestamp.
This is only relevant if you want to aggregate the session data. So to see how many people are online for example. If you just want to know the last time there was activity for a user, you can store that in the session itself (only that user will have access to it though).
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
ok, i read everything you guys referenced and i'm still lost
using the $_SESSION variable is fine, i understand that.
but when i try to assign that "text" value to a different variable, like an object literal or something, and then "post" that info to the mysql database, it all just does not want to happen. nothing crashes, its just that the value of the username never makes it to the database.
i was reading about the session set save handler, sounds easy,... oh boy, looking at the code, totally lost.
this should be easy, so i would assume.
still stuck
You obviously have that, so showing that to user & reading that from form again is pointless, as the second you have it, means user logged in and you can do update of db, to log last visit.
Quote:
how do you take the username of the person logged into your website
Read above.
Quote:
and store that in the MySQL database
If you don't have any SQL to show us, you are not using it (so the stuff cant get to db), study my link given above again. If you do, and nothing happens in db, there must be some error.
Show us Insert or update SQL if you have it.
Mybe you inherited some project with object oriented db stuff (like hyberate,...), which I think you did not, but in case ...then only god can help you (-:
Hope this will turn some light on.
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search
Users who have thanked BubikolRamios for this post:
i was splashing out the username on the screen just to test that i can access that value as a text string accurately
i need to store the username in the db, because my user will select changes to graphics on the home page, then a different user comes along and does the same thing, then another, and so on. each time a user is logged on and changes the graphic to one of the preset options, i log who made the change. only one user can be logged on at any one time. so i'm simply tracking who the users are and when they are on the sight and what changes they made to the preset graphic options.
i may need to splash out the username on the main page later, but for now it's just going in the database for my log.
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search
Users who have thanked BubikolRamios for this post:
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search
Users who have thanked BubikolRamios for this post:
i went to the link you showed and looked it over hard
never seen that code before
not sure what they are doing, haven't a clue how to relate that to mine
sorry
doing some research elsewhere, some are saying that $_SESSION variables are on the server side, while Javascript variables are on the client side and that you cannot mix the two
one said to just declare:
var a = <?php echo $_SESSION['MM_Username']; ?>
I assume that should do what it looks like it should do. Doh I don't know PHP
Quote:
Originally Posted by Paul Williams
var a = <?php echo $_SESSION['MM_Username']; ?>
but that doesn't work either.
What do you mean it does not work ?
Try
Code:
...
<script>
alert(a);
</script>
</html>
That should pop up your name that you transfered from server to client (into javascript part of client).
And prove that it works.
I would formulate the saying prom previous post that some suggested it to you a bit different: When server spits whatever it spits to client, then it (the server) would not know what is on client even if you kill it (the server) (-:
From my previous post: Google for exception handling and you will find text like (no matter which language): try...except ... finaly
Read that.
It means, whatewer seems did nothing, it probably means that you can get what went wrong after except part of code.
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search
Users who have thanked BubikolRamios for this post:
$_SESSION['MM_Username'] is something that comes from using dreamweaver. I would not trust it nor use it. When a user logs into a site they are normally asked for their user name and their password. So you should have their user name as a variable already. I was thinking that you would set a session variable to that along with the log in time and not use $_SESSION['MM_Username']. I then thought that you could use sessions to keep track of "what they were doing" on your site and when they logged out or the session time out you would then store that information.
I do believe on a site you can use cPanel and get over all statistics about your site, but not what individuals do.
Lets see how you would "i want to take that text value and store it in the database along side a timestamp." from post one.
User goes to your site and get a login screen. He/she logs in giving you his user name and password in a form that is passed to a php program that cleans the variable and looks into the database to see if he is registered. At the point if he is registered you can make a DB entree with his name and time. Simple. Also at this time you can set the session variable for her name so you can follow her on your site.
When things are over you can get the variable
Code:
<?php
session_start();
foreach ($_SESSION as $key=>$val)
echo $key." ".$val."<br/>";
?>
Or instead of echoing them put them into an array and then put the array into the db.