PHP IM Login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sonic98
Forum Newbie
Posts: 16
Joined: Tue Dec 17, 2002 8:55 pm
Contact:

PHP IM Login

Post by Sonic98 »

The instant messenger I am setting up is in PHP and connects to a mysql database. It has scripts for login, messaging, and registration. It's supposed to log you out when you close the IM window. It keeps logging people out as soon as they register or login. I figure that the problem has to either be in the im window script or the logout script

window.php

Code: Select all

<?
include ("mysql.php");
mysql_select_db("swacfans_im");
$query="select * from users where username='$username' and status="yes"";

$result=mysql_query($query, $link);
if($result!=0)
&#123;
print"<center><body bgcolor="000066"><span style=background-color:8080C0><font color=lightblue>&nbsp;$username you have logged out&nbsp;</span>";
exit;
&#125;
else
&#123;
$query="delete from chatdata where message ='<br>' or buddy='to <font color=blue></font>'";
mysql_query($query,$link);
$query="select sender, buddy, message from chatdata where sender = '<font color=red>$username</font>' or sender like '%$buddy%'  and   
buddy ='<font color=blue>$buddy</font>' or buddy like '%$username%'  order by id desc";
echo mysql_error();
logout.php

Code: Select all

<?
include("mysql.php");

if($user=="$username")
&#123;
$query="delete from chatdata where username like '%$username%'";
mysql_query($query, $link);
$query="update users set status='no' where username='$username'";
$result= mysql_query($query, $link);
header("location: index.php");
&#125;
print$msg;
print$user;
?>
Anyone see something I'm missing?[/i]
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

error?

Post by AVATAr »

what's the error?
Sonic98
Forum Newbie
Posts: 16
Joined: Tue Dec 17, 2002 8:55 pm
Contact:

Post by Sonic98 »

There is no error message. I got rid of all the errors. The only problem is that it logs you out as soon as you log in.

Code: Select all

if($result!=0) 
 
print"<center><body bgcolor="000066"><span style=background-color:8080C0><font color=lightblue> $username you have logged out </span>"; 
exit;
It seems to be taking this result no matter what I do.
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

Logging out when the window closes has to do with Sessions. Find the script which controls sessions and check for errors there.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Sonic98 wrote:There is no error message. I got rid of all the errors. The only problem is that it logs you out as soon as you log in.
In other words, this could be a logic issue.

Cheers,
BDKR
Sonic98
Forum Newbie
Posts: 16
Joined: Tue Dec 17, 2002 8:55 pm
Contact:

Post by Sonic98 »

Yeah it basically was a runtime error. I fixed it by changing it to result==0 insteand of !=0, but now I have to figure out why it's not storing passwords correctly. I can register but when I try to log back in, it tells me, the password is incorrect or the username is in use.
Post Reply