开发者

PHP and mySQL Data Errors

I currently have 2 users registered on my website; jason and jason1.

I have a mySQL database that stores the following fields: id message reciever sender

When a message is sent from jason1 to jason, the data comes up correctly. However, when a message is sent from jason to jason1 both the sender and reciever fields come up as having the value of jason1. Here is some script info:

The way the function is called: http://pastebi开发者_如何学JAVAn.com/BqVQ7vVE

The function itself: http://pastebin.com/1hTEhxAN

getmessage.php, called with XHR: http://pastebin.com/u1A4hPG3

And a screenshot of the database: http://img263.imageshack.us/img263/7804/mysqlz.png

I will take any suggestions, this is really frustrating.


to summarize the discussion, the issue is with the cookie, and according to your set cookie function here: http://pastebin.com/8fwEPALk

function validateUser($username){
        session_regenerate_id (); 
        $_SESSION['valid'] = 1;
        $_SESSION['username'] = $username;
        header("Location: ../new.php");
        setcookie('username2',$_SESSION['username'],time()+60*60*24*365,'/');
    }

you made it go header before the setcookie, you need to place the setcookie before header and also don't forget to add exit after header. the reason jason1 always in your cookie perhaps from previous working state of your website.

function validateUser($username){
        session_regenerate_id (); 
        $_SESSION['valid'] = 1;
        $_SESSION['username'] = $username;
        setcookie('username2',$_SESSION['username'],time()+60*60*24*365,'/');
        header("Location: ../new.php");
            exit;
    }

using cookie to validate user login is a security risk , you can debug and find out why session didn't work for you. it could be the session directory is getting wiped out improperly, in that case try to set different folder for the session_path

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜