Page 1 of 1

PHP IM Login

Posted: Tue Dec 17, 2002 8:55 pm
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]

error?

Posted: Tue Dec 17, 2002 8:59 pm
by AVATAr
what's the error?

Posted: Tue Dec 17, 2002 9:01 pm
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.

Posted: Wed Dec 18, 2002 6:48 am
by evilcoder
Logging out when the window closes has to do with Sessions. Find the script which controls sessions and check for errors there.

Posted: Wed Dec 18, 2002 8:55 am
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

Posted: Wed Dec 18, 2002 11:32 am
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.