Jump to content

SHow current user


CJLeah

Recommended Posts

First, this depends on how you determine when a user is online/offline. Do you have a cron job which deletes open sessions if they exceed a certain amount of time of inactivity? Otherwise, anytime someone logs in, and closes their browser without logging out, the session will stay open (If indeed you are using a sessions table in the database) thus, showing these people as "Online".

In regards to your example, nothing in your query gives specifics as to what user you are trying to retrieve from the database.

[code]<?php

$username = $_POST['username'];

$somequery = mysql_query("SELECT * FROM users WHERE username = '$username'");

$result = mysql_fetch_array($somequery);

echo"Hiya $result[username], how the f*ck are you, you ugly bastage?";

?>[/code]

As far as a "who is online" script...that is trickier without knowing what I discussed above....but yeah....

Asuming that the username column is the second one in the table...

[code]<?php

$somequery = mysql_query("SELECT * FROM users WHERE online = '1'");

while ($row = mysql_fetch_array($somequery))

{echo" $row[1] ";}

?>[/code]

I also take it you are running your login script through several checks before you determine whether someone is logged in or not...and other security concerns?

Anyway, good luck bro.
Link to comment
https://forums.phpfreaks.com/topic/7760-show-current-user/#findComment-28309
Share on other sites

[!--quoteo(post=366164:date=Apr 18 2006, 03:16 PM:name=Chris Leah)--][div class=\'quotetop\']QUOTE(Chris Leah @ Apr 18 2006, 03:16 PM) [snapback]366164[/snapback][/div][div class=\'quotemain\'][!--quotec--]
sorry, i'm veyr new to php, but basically what i'm trying to do is, show the that users username, when he look at that page, like 'Hello USERNAME how are you?' somthing like that...

that help any better?
[/quote]

Look at my above example.

And consider looking through -> [a href=\"http://www.php.net\" target=\"_blank\"]http://www.php.net[/a] ....Great source.
Link to comment
https://forums.phpfreaks.com/topic/7760-show-current-user/#findComment-28330
Share on other sites

[!--quoteo(post=366172:date=Apr 18 2006, 03:24 PM:name=Caesar)--][div class=\'quotetop\']QUOTE(Caesar @ Apr 18 2006, 03:24 PM) [snapback]366172[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Look at my above example.

And consider looking through -> [a href=\"http://www.php.net\" target=\"_blank\"]http://www.php.net[/a] ....Great source.
[/quote]


I have mate, but not working ..:( but i've jsut tried this also


[code]<?php
$result = mysql_query("SELECT COUNT(*) FROM users WHERE username = '" . $_POST['username'] . "'") or exit(mysql_error());
if (mysql_result($result, 0)) {echo $_POST['username'] . ' how are you?';}
else {echo $_POST['username'] . ' is not in the database';}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/7760-show-current-user/#findComment-28333
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.