开发者

weird php error - cannot explain just in title

开发者 https://www.devze.com 2023-02-19 20:54 出处:网络
discovered this forum a few days ago and still not into it enough to contribute - will happen soon i hope :)

discovered this forum a few days ago and still not into it enough to contribute - will happen soon i hope :)

right now i am experiencing something weird i hope someone can help me with.

In the following php code:

when i run it and enter a valid username and password, it wil开发者_C百科l always send me to failed.php although it should have returned a result.

When i add a random "echo" before the if clause, it goes into the correct branch, but of course can't do the header("Location..) any more.

Does anyone have an idea what i am missing here or why this is happening? Could it be some PHP setting i am not aware of?

thanks in advance Seb

(NOTE i know php4 is not up to date, sql injections etc. - i just want to know and maybe understand why this is happening ;) )

<?php

     include("config.php");

    $query = 'select * from users where username = "' . 
            $_POST['username'] . '" and password = "' . 
            md5($_POST['password']) . '"';
    $select_user = mysql_query($query);
    //echo "something";
    if ($select_user && ($row = mysql_fetch_row($select_user)))
    {
            $user_id = $row[0];
        session_start();
        session_register('authorized');
        $_SESSION['authorized'] = true;
        $_SESSION['uid'] = $user_id;
        //echo "anothersomething";
        header("Location: portal.php");
        exit;
    } 
    else 
    {
    $_SESSION['authorized'] = false;
        $_SESSION['uid'] = 0;
        header("Location: failed.php");
        exit;   
    }
    @MYSQL_CLOSE($db); 
?>
0

精彩评论

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